1 """Helper for groups."""
3 from __future__
import annotations
5 from collections.abc
import Iterable
11 ENTITY_PREFIX =
"group."
15 """Return entity_ids with group entity ids replaced by their members.
19 found_ids: list[str] = []
20 for entity_id
in entity_ids:
21 if not isinstance(entity_id, str)
or entity_id
in (
27 entity_id = entity_id.lower()
29 if entity_id.startswith(ENTITY_PREFIX):
31 if entity_id
in child_entities:
32 child_entities =
list(child_entities)
33 child_entities.remove(entity_id)
37 if ent_id
not in found_ids
39 elif entity_id
not in found_ids:
40 found_ids.append(entity_id)
46 hass: HomeAssistant, entity_id: str, domain_filter: str |
None =
None
48 """Get members of this group.
52 group = hass.states.get(entity_id)
53 if not group
or ATTR_ENTITY_ID
not in group.attributes:
55 entity_ids: list[str] = group.attributes[ATTR_ENTITY_ID]
58 domain_filter = f
"{domain_filter.lower()}."
59 return [ent_id
for ent_id
in entity_ids
if ent_id.startswith(domain_filter)]
list[str] get_entity_ids(HomeAssistant hass, str entity_id, str|None domain_filter=None)
list[str] expand_entity_ids(HomeAssistant hass, Iterable[Any] entity_ids)