mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Expand group lights/covers etc (#68875)
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
7613784367
commit
206ea9d237
@ -887,6 +887,9 @@ def result_as_boolean(template_result: Any | None) -> bool:
|
|||||||
|
|
||||||
def expand(hass: HomeAssistant, *args: Any) -> Iterable[State]:
|
def expand(hass: HomeAssistant, *args: Any) -> Iterable[State]:
|
||||||
"""Expand out any groups into entity states."""
|
"""Expand out any groups into entity states."""
|
||||||
|
# circular import.
|
||||||
|
from . import entity as entity_helper # pylint: disable=import-outside-toplevel
|
||||||
|
|
||||||
search = list(args)
|
search = list(args)
|
||||||
found = {}
|
found = {}
|
||||||
while search:
|
while search:
|
||||||
@ -904,7 +907,10 @@ def expand(hass: HomeAssistant, *args: Any) -> Iterable[State]:
|
|||||||
# ignore other types
|
# ignore other types
|
||||||
continue
|
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
|
# Collect state will be called in here since it's wrapped
|
||||||
group_entities = entity.attributes.get(ATTR_ENTITY_ID)
|
group_entities = entity.attributes.get(ATTR_ENTITY_ID)
|
||||||
if group_entities:
|
if group_entities:
|
||||||
|
@ -2079,6 +2079,32 @@ async def test_expand(hass):
|
|||||||
)
|
)
|
||||||
assert info.rate_limit is None
|
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):
|
async def test_device_entities(hass):
|
||||||
"""Test device_entities function."""
|
"""Test device_entities function."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user