1
0
mirror of https://github.com/elisspace/core.git synced 2026-08-29 15:43:55 +00:00

Fix templates not updating when an entity is added or removed from a group

Because the expand function did not collect the group
entity it would never trigger an update when the group
changed via the group.set service
This commit is contained in:
J. Nick Koston
2023-04-07 12:11:56 -10:00
parent 7eccef87c2
commit 83eff1a44d
2 changed files with 8 additions and 5 deletions

View File

@@ -1155,11 +1155,13 @@ def expand(hass: HomeAssistant, *args: Any) -> Iterable[State]:
search = list(args)
found = {}
entity_sources = entity_helper.entity_sources(hass)
while search:
entity = search.pop()
if isinstance(entity, str):
entity_id = entity
if (entity := _get_state(hass, entity)) is None:
if (entity := hass.states.get(entity_id)) is None:
_collect_state(hass, entity_id)
continue
elif isinstance(entity, State):
entity_id = entity.entity_id
@@ -1170,9 +1172,9 @@ def expand(hass: HomeAssistant, *args: Any) -> Iterable[State]:
# ignore other types
continue
_collect_state(hass, entity_id)
if entity_id.startswith(_GROUP_DOMAIN_PREFIX) or (
(source := entity_helper.entity_sources(hass).get(entity_id))
and source["domain"] == "group"
(source := entity_sources.get(entity_id)) and source["domain"] == "group"
):
# Collect state will be called in here since it's wrapped
if group_entities := entity.attributes.get(ATTR_ENTITY_ID):
@@ -1181,7 +1183,6 @@ def expand(hass: HomeAssistant, *args: Any) -> Iterable[State]:
if zone_entities := entity.attributes.get(ATTR_PERSONS):
search += zone_entities
else:
_collect_state(hass, entity_id)
found[entity_id] = entity
return list(found.values())

View File

@@ -2546,7 +2546,9 @@ async def test_expand(hass: HomeAssistant) -> None:
hass,
"{{ expand(states.group) | sort(attribute='entity_id') | map(attribute='entity_id') | join(', ') }}",
)
assert_result_info(info, "test.object", {"test.object"}, ["group"])
assert_result_info(
info, "test.object", {"group.new_group", "test.object"}, ["group"]
)
assert info.rate_limit == template.DOMAIN_STATES_RATE_LIMIT
info = render_to_info(