Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nested schema validation in event automation trigger #126771

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Hypfer
Copy link
Contributor

@Hypfer Hypfer commented Sep 25, 2024

Proposed change

While trying to build an automation for motion controlled lights that disables itself if some other source changes a light entity, I stumbled upon something unexpected.

platform: event
event_type: call_service
id: light_turn_on_call_two
event_data:
  domain: light
  service: turn_on
  service_data:
    entity_id:
      - light.decke_bad

^ This trigger triggered on the following event (taken from the trace):

trigger:
  id: light_turn_on_call_two
  idx: '6'
  alias: null
  platform: event
  event:
    event_type: call_service
    data:
      domain: light
      service: turn_on
      service_data:
        transition: 0.1
        profile: lmao
        device_id:
          - 0115a5bba8da927df1c1a164cf059429
    origin: LOCAL
    time_fired: '2024-09-25T16:00:09.232550+00:00'

It did so, because the schema built by the trigger does not care about nested dicts.

Not being a nested schema might be intentional so this might introduce a performance penalty and might not be desired.
If that is the case, maybe it would make sense to limit the nesting depth, though if not, I think I'd keep it without a depth limit.

An alternative solution could be to update the docs, warn about this caveat and instead further validate with a template condition. Though then you get an automation that triggers all the time so might also not be desirable.

I would argue that you'd want the event trigger to work with at least the call_service events for core services

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: N/A
  • This PR is related to issue: N/A
  • Link to documentation pull request: N/A

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (homeassistant) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of homeassistant can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign homeassistant Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@Hypfer
Copy link
Contributor Author

Hypfer commented Sep 25, 2024

Looks like this change might've found a bug in an existing integration?

Prior to this PR, this schema matched this event data, which doesn't make sense I think

Event data schema:
<Schema({'device_id': '72484a2a88f9f91ea97a25c8a225bbe1', 'values': {'Status': 'Panic'}}, extra=ALLOW_EXTRA, required=False) object at 0x1a3230553a0>

Event data:
{'data': '08200300a109000670',
 'device_id': '72484a2a88f9f91ea97a25c8a225bbe1',
 'id_string': 'a10900:32',
 'packet_type': 32,
 'sub_type': 3,
 'type_string': 'KD101 Smoke Detector',
 'values': {'Battery numeric': None,
            'Rssi numeric': 7,
            'Sensor Status': 'Panic'}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant