Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand group lights/covers etc #68875

Merged
merged 2 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion homeassistant/helpers/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions tests/helpers/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down