Allow targeting non-primary entities in triggers#168857
Conversation
|
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
Adds an opt-out for the “primary entities only” filtering during indirect target expansion so purpose-specific triggers (notably battery triggers) can target diagnostic/config entities when expanding via floor/area/device/label.
Changes:
- Introduces a
primary_entities_onlyflag to target expansion/tracking and threads it through entity trigger helpers. - Updates battery triggers to include non-primary entities (diagnostic/config) and updates trigger selector metadata accordingly.
- Adjusts/extends tests and shared test helpers to model diagnostic entities and validate the new behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
homeassistant/helpers/target.py |
Adds primary_entities_only flag to indirect expansion and to target state tracking setup. |
homeassistant/helpers/trigger.py |
Allows trigger classes/factories to control whether indirect expansion includes non-primary entities. |
homeassistant/helpers/selector.py |
Extends the target selector config schema to accept primary_entities_only. |
homeassistant/components/battery/trigger.py |
Configures battery triggers to include non-primary entities during indirect expansion. |
homeassistant/components/battery/triggers.yaml |
Updates battery trigger target selector config to set primary_entities_only: false. |
tests/components/common.py |
Enhances shared target entity factory to create registry entities with a given EntityCategory. |
tests/components/battery/test_trigger.py |
Makes battery-target entities diagnostic to validate that battery triggers work for non-primary entities. |
tests/helpers/test_target.py |
Adds coverage verifying primary_entities_only controls inclusion of config/diagnostic entities in indirect expansion. |
05d73e2 to
874fb28
Compare
e05e7a6 to
c65c502
Compare
MartinHjelmare
left a comment
There was a problem hiding this comment.
I think we should add a test for the selector changes.
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
There was a problem hiding this comment.
A general question: The "primary entities only" is added as a configuration option for the target selector in this PR.
It doesn't seem entirely far fetched to also make it part of the selection, that is, allow the user to control the flag in the selector.
Would the changes in this PR be compatible with such a future extension?
Yes, I expect so. This can serve as the default for the trigger, and the trigger user options could override it when calling |
Proposed change
Add support for extracting non-primary entities to target helpers and allow triggers to work for non-primary entities.
#168860 should be merged first, so that when this is added to triggers the entity extraction on the frontend also works.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: