Extract triggers/conditions/services for non-primary entities#169441
Extract triggers/conditions/services for non-primary entities#169441
Conversation
…components_diag_entities
…components_diag_entities2
|
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
This PR updates the websocket automation target lookups so triggers/conditions/services can be surfaced for indirectly-targeted non-primary (config/diagnostic) entities when the automation component explicitly opts in via primary_entities_only: false.
Changes:
- Extend automation component lookup metadata to include
primary_entities_onlyfrom the target description. - Expand target entity extraction to include non-primary entities, then selectively filter matches based on whether entities were indirectly referenced.
- Add websocket API tests covering non-primary entity targeting and component descriptions using
primary_entities_only: false.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
homeassistant/components/websocket_api/automation.py |
Implements primary_entities_only handling in automation component lookup and adjusts target extraction/matching logic. |
tests/components/websocket_api/test_commands.py |
Adds non-primary entities to target fixtures and extends expected trigger/service results to validate the new behavior. |
Comments suppressed due to low confidence (1)
homeassistant/components/websocket_api/automation.py:254
- Apply entity-category filtering only to entities that were indirectly expanded (area/device/floor/label) so direct
entity_idtargets still matchprimary_entities_only=Truecomponents even when the same request also includes indirect targets.
check_entity_category = len(extracted.indirectly_referenced) > 0
entity_infos = entity_sources(hass)
matched_components: set[str] = set()
for entity_id in extracted.referenced | extracted.indirectly_referenced:
if lookup_table.component_count == len(matched_components):
This reverts commit 9b29b07.
There was a problem hiding this comment.
Pull request overview
This PR updates the websocket automation target lookup so that triggers/conditions/services can be surfaced for indirectly targeted non-primary (config/diagnostic) entities when the automation component explicitly opts in via primary_entities_only: false, while preserving the “return everything” behavior for purely direct entity targets.
Changes:
- Extend websocket automation component lookup to read
primary_entities_onlyfrom target descriptions and apply entity-category filtering only when indirect targets are involved. - Extract target entities with
primary_entities_only=Falseso indirectly referenced non-primary entities are available for matching. - Expand websocket API tests to cover non-primary entities in indirect targets for triggers/conditions and services.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
homeassistant/components/websocket_api/automation.py |
Adds primary_entities_only support to component matching and changes target extraction to include non-primary entities for indirect matching. |
tests/components/websocket_api/test_commands.py |
Adds fixtures and assertions to validate trigger/condition/service lookup behavior with non-primary entities. |
There was a problem hiding this comment.
Pull request overview
Adjusts the websocket automation component lookup so triggers/conditions/services can be surfaced for indirect targets (device/area/label) even when the only matching entities are non-primary (config/diagnostic), if the component description explicitly opts in.
Changes:
- Extend websocket automation component matching to respect a
primary_entities_onlyflag from the component’s target description for indirectly referenced entities. - Always extract indirect targets with
primary_entities_only=False, then apply per-component filtering during matching. - Expand websocket API command tests to cover indirect targets containing only non-primary entities and mixed direct+indirect targeting.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
homeassistant/components/websocket_api/automation.py |
Adds per-component primary_entities_only handling and applies entity-category filtering only for indirect targets. |
tests/components/websocket_api/test_commands.py |
Adds fixtures/entities and assertions to validate component exposure for non-primary indirect targets and direct+indirect combinations. |
Proposed change
Make get_triggers_for_target/get_conditions_for_target/get_services_for_target expose triggers/conditions/services with
primary_entities_only=Falsewhen there are matching non-primary entities.This keeps the existing behavior for when there are no indirect targets: all triggers/conditions/services are returned, regardless of the flag.
Implements #168101.
Depends on #169291.
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: