mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Avoid linear search of entity registry in async_extract_referenced_entity_ids (#109667)
* Index area_ids in the entity registry I missed that these are used in _resolve_area in search. Eventually we can make async_extract_referenced_entity_ids a bit faster with this as well * Avoid linear search of entity registry in async_extract_referenced_entity_ids needs https://github.com/home-assistant/core/pull/109660
This commit is contained in:
parent
206aaac700
commit
9689cb448d
@ -496,26 +496,37 @@ def async_extract_referenced_entity_ids(
|
|||||||
if not selector.area_ids and not selected.referenced_devices:
|
if not selector.area_ids and not selected.referenced_devices:
|
||||||
return selected
|
return selected
|
||||||
|
|
||||||
for ent_entry in ent_reg.entities.values():
|
entities = ent_reg.entities
|
||||||
|
# Add indirectly referenced by area
|
||||||
|
selected.indirectly_referenced.update(
|
||||||
|
entry.entity_id
|
||||||
|
for area_id in selector.area_ids
|
||||||
|
# The entity's area matches a targeted area
|
||||||
|
for entry in entities.get_entries_for_area_id(area_id)
|
||||||
|
# Do not add entities which are hidden or which are config
|
||||||
|
# or diagnostic entities.
|
||||||
|
if entry.entity_category is None and entry.hidden_by is None
|
||||||
|
)
|
||||||
|
# Add indirectly referenced by device
|
||||||
|
selected.indirectly_referenced.update(
|
||||||
|
entry.entity_id
|
||||||
|
for device_id in selected.referenced_devices
|
||||||
|
for entry in entities.get_entries_for_device_id(device_id)
|
||||||
# Do not add entities which are hidden or which are config
|
# Do not add entities which are hidden or which are config
|
||||||
# or diagnostic entities.
|
# or diagnostic entities.
|
||||||
if ent_entry.entity_category is not None or ent_entry.hidden_by is not None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
# The entity's area matches a targeted area
|
entry.entity_category is None
|
||||||
ent_entry.area_id in selector.area_ids
|
and entry.hidden_by is None
|
||||||
# The entity's device matches a device referenced by an area and the entity
|
and (
|
||||||
# has no explicitly set area
|
# The entity's device matches a device referenced
|
||||||
or (
|
# by an area and the entity
|
||||||
not ent_entry.area_id
|
# has no explicitly set area
|
||||||
and ent_entry.device_id in selected.referenced_devices
|
not entry.area_id
|
||||||
|
# The entity's device matches a targeted device
|
||||||
|
or device_id in selector.device_ids
|
||||||
)
|
)
|
||||||
# The entity's device matches a targeted device
|
)
|
||||||
or ent_entry.device_id in selector.device_ids
|
)
|
||||||
):
|
|
||||||
selected.indirectly_referenced.add(ent_entry.entity_id)
|
|
||||||
|
|
||||||
return selected
|
return selected
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user