mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Small performance improvement to template expand (#114086)
* Small performance improvement to template expand - Avoid fetching entity sources each loop - Skip already found entities - Avoid startswith in favor of equality check * unneeded changes
This commit is contained in:
parent
f079c1c236
commit
de831b6e87
@ -1252,6 +1252,7 @@ def expand(hass: HomeAssistant, *args: Any) -> Iterable[State]:
|
|||||||
|
|
||||||
search = list(args)
|
search = list(args)
|
||||||
found = {}
|
found = {}
|
||||||
|
sources = entity_helper.entity_sources(hass)
|
||||||
while search:
|
while search:
|
||||||
entity = search.pop()
|
entity = search.pop()
|
||||||
if isinstance(entity, str):
|
if isinstance(entity, str):
|
||||||
@ -1267,14 +1268,17 @@ def expand(hass: HomeAssistant, *args: Any) -> Iterable[State]:
|
|||||||
# ignore other types
|
# ignore other types
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if entity_id.startswith(_GROUP_DOMAIN_PREFIX) or (
|
if entity_id in found:
|
||||||
(source := entity_helper.entity_sources(hass).get(entity_id))
|
continue
|
||||||
and source["domain"] == "group"
|
|
||||||
|
domain = entity.domain
|
||||||
|
if domain == "group" or (
|
||||||
|
(source := sources.get(entity_id)) and source["domain"] == "group"
|
||||||
):
|
):
|
||||||
# Collect state will be called in here since it's wrapped
|
# Collect state will be called in here since it's wrapped
|
||||||
if group_entities := entity.attributes.get(ATTR_ENTITY_ID):
|
if group_entities := entity.attributes.get(ATTR_ENTITY_ID):
|
||||||
search += group_entities
|
search += group_entities
|
||||||
elif entity_id.startswith(_ZONE_DOMAIN_PREFIX):
|
elif domain == "zone":
|
||||||
if zone_entities := entity.attributes.get(ATTR_PERSONS):
|
if zone_entities := entity.attributes.get(ATTR_PERSONS):
|
||||||
search += zone_entities
|
search += zone_entities
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user