Include referenced labels when searching automations and scripts#175459
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
This PR fixes an asymmetry in the search integration. Searching a label already returns the automations and scripts that target it (via automations_with_label / scripts_with_label), but searching an automation or script did not return the labels it targets, even though the labels_in_automation and labels_in_script helpers already existed. This change adds the missing reverse lookups, following the same pattern used for floors.
Changes:
- Add
ItemType.LABELresults fromlabels_in_automationto_async_search_automation. - Add
ItemType.LABELresults fromlabels_in_scriptto_async_search_script(which also propagates to scripts embedded in automations and nested scripts). - Add test assertions for searching
automation.labelandscript.label, reusing existing fixtures.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| homeassistant/components/search/init.py | Adds the missing targeted-label lookups to the automation and script search paths, mirroring the floor lookup pattern. |
| tests/components/search/test_init.py | Adds assertions verifying that searching an automation/script returns its targeted labels. |
I verified that:
- The
automation.labels_in_automationandscript.labels_in_scripthelpers exist and returnlist[str], which_addhandles correctly. - The placement is consistent with the adjacent floor lookups (
floors_in_automation/floors_in_script), including that referenced labels are added unconditionally (not gated onentry_point), so nested/embedded scripts contribute their labels — matching the floor behavior and the PR's stated intent. - The edge is now symmetrical with
_async_search_label, which already returns automations/scripts referencing the label. - The test fixtures (
automation.labeltargetinglabel_christmas,script.labeltargetinglabel_other) match the asserted results, and neither fixture targets additional entities that would change the expected result set.
No issues found.
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
1 similar comment
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Proposed change
Searching a label in the search integration returns the automations and scripts that target it, through
automations_with_labelandscripts_with_label. The reverse direction is missing: searching an automation or script returns the floors, areas, devices, and entities it targets, but not the labels it targets, even though thelabels_in_automationandlabels_in_scripthelpers exist. The label edge only worked one way.This change adds the missing lookups to
_async_search_automationand_async_search_script, following the exact same pattern the floor lookups already use. Since_async_search_scriptis also invoked for scripts embedded in automations and for nested scripts, those cases inherit the targeted labels as well.Tests: new assertions for searching
automation.labelandscript.label, fixtures that already existed in the test but were never searched from this direction. Both fail without the fix.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: