Expand group lights/covers etc (#68875)

Co-authored-by: Franck Nijhof <git@frenck.dev>
pull/68814/head^2
Paulus Schoutsen 2022-03-30 01:11:09 -07:00 committed by GitHub
parent 7613784367
commit 206ea9d237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -887,6 +887,9 @@ def result_as_boolean(template_result: Any | None) -> bool:
def expand(hass: HomeAssistant, *args: Any) -> Iterable[State]:
"""Expand out any groups into entity states."""
# circular import.
from . import entity as entity_helper # pylint: disable=import-outside-toplevel
search = list(args)
found = {}
while search:
@ -904,7 +907,10 @@ def expand(hass: HomeAssistant, *args: Any) -> Iterable[State]:
# ignore other types
continue
if entity_id.startswith(_GROUP_DOMAIN_PREFIX):
if entity_id.startswith(_GROUP_DOMAIN_PREFIX) or (
(source := entity_helper.entity_sources(hass).get(entity_id))
and source["domain"] == "group"
):
# Collect state will be called in here since it's wrapped
group_entities = entity.attributes.get(ATTR_ENTITY_ID)
if group_entities:

View File

@ -2079,6 +2079,32 @@ async def test_expand(hass):
)
assert info.rate_limit is None
# With group entities
hass.states.async_set("light.first", "on")
hass.states.async_set("light.second", "off")
assert await async_setup_component(
hass,
"light",
{
"light": {
"platform": "group",
"name": "Grouped",
"entities": ["light.first", "light.second"],
}
},
)
await hass.async_block_till_done()
info = render_to_info(
hass, "{{ expand('light.grouped') | map(attribute='entity_id') | join(', ') }}"
)
assert_result_info(
info,
"light.first, light.second",
["light.grouped", "light.first", "light.second"],
)
async def test_device_entities(hass):
"""Test device_entities function."""