mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Sort some code in the search integration (#78519)
This commit is contained in:
parent
aa0fd8c935
commit
c0b04e9f91
@ -30,13 +30,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
(
|
(
|
||||||
"area",
|
"area",
|
||||||
"automation",
|
"automation",
|
||||||
|
"blueprint",
|
||||||
"config_entry",
|
"config_entry",
|
||||||
"device",
|
"device",
|
||||||
"entity",
|
"entity",
|
||||||
"group",
|
"group",
|
||||||
|
"person",
|
||||||
"scene",
|
"scene",
|
||||||
"script",
|
"script",
|
||||||
"person",
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
vol.Required("item_id"): str,
|
vol.Required("item_id"): str,
|
||||||
@ -66,9 +67,16 @@ class Searcher:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# These types won't be further explored. Config entries + Output types.
|
# 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
|
# 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__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -130,6 +138,7 @@ class Searcher:
|
|||||||
"""Resolve an area."""
|
"""Resolve an area."""
|
||||||
for device in device_registry.async_entries_for_area(self._device_reg, area_id):
|
for device in device_registry.async_entries_for_area(self._device_reg, area_id):
|
||||||
self._add_or_resolve("device", device.id)
|
self._add_or_resolve("device", device.id)
|
||||||
|
|
||||||
for entity_entry in entity_registry.async_entries_for_area(
|
for entity_entry in entity_registry.async_entries_for_area(
|
||||||
self._entity_reg, area_id
|
self._entity_reg, area_id
|
||||||
):
|
):
|
||||||
@ -141,6 +150,39 @@ class Searcher:
|
|||||||
for entity_id in automation.automations_with_area(self.hass, area_id):
|
for entity_id in automation.automations_with_area(self.hass, area_id):
|
||||||
self._add_or_resolve("entity", entity_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
|
@callback
|
||||||
def _resolve_device(self, device_id) -> None:
|
def _resolve_device(self, device_id) -> None:
|
||||||
"""Resolve a device."""
|
"""Resolve a device."""
|
||||||
@ -206,21 +248,31 @@ class Searcher:
|
|||||||
self._add_or_resolve(domain, entity_id)
|
self._add_or_resolve(domain, entity_id)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _resolve_automation(self, automation_entity_id) -> None:
|
def _resolve_group(self, group_entity_id) -> None:
|
||||||
"""Resolve an automation.
|
"""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(
|
for entity_id in group.get_entity_ids(self.hass, group_entity_id):
|
||||||
self.hass, automation_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)
|
self._add_or_resolve("entity", entity)
|
||||||
|
|
||||||
for device in automation.devices_in_automation(self.hass, automation_entity_id):
|
@callback
|
||||||
self._add_or_resolve("device", device)
|
def _resolve_scene(self, scene_entity_id) -> None:
|
||||||
|
"""Resolve a scene.
|
||||||
|
|
||||||
for area in automation.areas_in_automation(self.hass, automation_entity_id):
|
Will only be called if scene is an entry point.
|
||||||
self._add_or_resolve("area", area)
|
"""
|
||||||
|
for entity in scene.entities_in_scene(self.hass, scene_entity_id):
|
||||||
|
self._add_or_resolve("entity", entity)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _resolve_script(self, script_entity_id) -> None:
|
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):
|
for area in script.areas_in_script(self.hass, script_entity_id):
|
||||||
self._add_or_resolve("area", area)
|
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)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user