diff --git a/homeassistant/components/search/__init__.py b/homeassistant/components/search/__init__.py index bfde6f38a73..e7df1de860e 100644 --- a/homeassistant/components/search/__init__.py +++ b/homeassistant/components/search/__init__.py @@ -30,13 +30,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: ( "area", "automation", + "blueprint", "config_entry", "device", "entity", "group", + "person", "scene", "script", - "person", ) ), vol.Required("item_id"): str, @@ -66,9 +67,16 @@ class Searcher: """ # These types won't be further explored. Config entries + Output types. - DONT_RESOLVE = {"scene", "automation", "script", "group", "config_entry", "area"} + DONT_RESOLVE = { + "area", + "automation", + "config_entry", + "group", + "scene", + "script", + } # These types exist as an entity and so need cleanup in results - EXIST_AS_ENTITY = {"script", "scene", "automation", "group", "person"} + EXIST_AS_ENTITY = {"automation", "group", "person", "scene", "script"} def __init__( self, @@ -130,6 +138,7 @@ class Searcher: """Resolve an area.""" for device in device_registry.async_entries_for_area(self._device_reg, area_id): self._add_or_resolve("device", device.id) + for entity_entry in entity_registry.async_entries_for_area( self._entity_reg, area_id ): @@ -141,6 +150,39 @@ class Searcher: for entity_id in automation.automations_with_area(self.hass, area_id): self._add_or_resolve("entity", entity_id) + @callback + def _resolve_automation(self, automation_entity_id) -> None: + """Resolve an automation. + + Will only be called if automation is an entry point. + """ + for entity in automation.entities_in_automation( + self.hass, automation_entity_id + ): + self._add_or_resolve("entity", entity) + + for device in automation.devices_in_automation(self.hass, automation_entity_id): + self._add_or_resolve("device", device) + + for area in automation.areas_in_automation(self.hass, automation_entity_id): + self._add_or_resolve("area", area) + + @callback + def _resolve_config_entry(self, config_entry_id) -> None: + """Resolve a config entry. + + Will only be called if config entry is an entry point. + """ + for device_entry in device_registry.async_entries_for_config_entry( + self._device_reg, config_entry_id + ): + self._add_or_resolve("device", device_entry.id) + + for entity_entry in entity_registry.async_entries_for_config_entry( + self._entity_reg, config_entry_id + ): + self._add_or_resolve("entity", entity_entry.entity_id) + @callback def _resolve_device(self, device_id) -> None: """Resolve a device.""" @@ -206,21 +248,31 @@ class Searcher: self._add_or_resolve(domain, entity_id) @callback - def _resolve_automation(self, automation_entity_id) -> None: - """Resolve an automation. + def _resolve_group(self, group_entity_id) -> None: + """Resolve a group. - Will only be called if automation is an entry point. + Will only be called if group is an entry point. """ - for entity in automation.entities_in_automation( - self.hass, automation_entity_id - ): + for entity_id in group.get_entity_ids(self.hass, group_entity_id): + self._add_or_resolve("entity", entity_id) + + @callback + def _resolve_person(self, person_entity_id) -> None: + """Resolve a person. + + Will only be called if person is an entry point. + """ + for entity in person.entities_in_person(self.hass, person_entity_id): self._add_or_resolve("entity", entity) - for device in automation.devices_in_automation(self.hass, automation_entity_id): - self._add_or_resolve("device", device) + @callback + def _resolve_scene(self, scene_entity_id) -> None: + """Resolve a scene. - for area in automation.areas_in_automation(self.hass, automation_entity_id): - self._add_or_resolve("area", area) + Will only be called if scene is an entry point. + """ + for entity in scene.entities_in_scene(self.hass, scene_entity_id): + self._add_or_resolve("entity", entity) @callback def _resolve_script(self, script_entity_id) -> None: @@ -236,46 +288,3 @@ class Searcher: for area in script.areas_in_script(self.hass, script_entity_id): self._add_or_resolve("area", area) - - @callback - def _resolve_group(self, group_entity_id) -> None: - """Resolve a group. - - Will only be called if group is an entry point. - """ - for entity_id in group.get_entity_ids(self.hass, group_entity_id): - self._add_or_resolve("entity", entity_id) - - @callback - def _resolve_scene(self, scene_entity_id) -> None: - """Resolve a scene. - - Will only be called if scene is an entry point. - """ - for entity in scene.entities_in_scene(self.hass, scene_entity_id): - self._add_or_resolve("entity", entity) - - @callback - def _resolve_person(self, person_entity_id) -> None: - """Resolve a person. - - Will only be called if person is an entry point. - """ - for entity in person.entities_in_person(self.hass, person_entity_id): - self._add_or_resolve("entity", entity) - - @callback - def _resolve_config_entry(self, config_entry_id) -> None: - """Resolve a config entry. - - Will only be called if config entry is an entry point. - """ - for device_entry in device_registry.async_entries_for_config_entry( - self._device_reg, config_entry_id - ): - self._add_or_resolve("device", device_entry.id) - - for entity_entry in entity_registry.async_entries_for_config_entry( - self._entity_reg, config_entry_id - ): - self._add_or_resolve("entity", entity_entry.entity_id)