mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Fix targeting all or none entities in service calls (#68513)
* Fix targeting all or none entities in service calls * Add test
This commit is contained in:
parent
43772b3fa9
commit
eb068bc850
@ -218,9 +218,12 @@ def async_prepare_call_from_config(
|
|||||||
|
|
||||||
if CONF_ENTITY_ID in target:
|
if CONF_ENTITY_ID in target:
|
||||||
registry = entity_registry.async_get(hass)
|
registry = entity_registry.async_get(hass)
|
||||||
target[CONF_ENTITY_ID] = entity_registry.async_validate_entity_ids(
|
entity_ids = cv.comp_entity_ids_or_uuids(target[CONF_ENTITY_ID])
|
||||||
registry, cv.comp_entity_ids_or_uuids(target[CONF_ENTITY_ID])
|
if entity_ids not in (ENTITY_MATCH_ALL, ENTITY_MATCH_NONE):
|
||||||
)
|
entity_ids = entity_registry.async_validate_entity_ids(
|
||||||
|
registry, entity_ids
|
||||||
|
)
|
||||||
|
target[CONF_ENTITY_ID] = entity_ids
|
||||||
except TemplateError as ex:
|
except TemplateError as ex:
|
||||||
raise HomeAssistantError(
|
raise HomeAssistantError(
|
||||||
f"Error rendering service target template: {ex}"
|
f"Error rendering service target template: {ex}"
|
||||||
|
@ -421,6 +421,22 @@ async def test_service_call_entry_id(hass):
|
|||||||
assert dict(calls[0].data) == {"entity_id": ["hello.world"]}
|
assert dict(calls[0].data) == {"entity_id": ["hello.world"]}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("target", ("all", "none"))
|
||||||
|
async def test_service_call_all_none(hass, target):
|
||||||
|
"""Test service call targeting all."""
|
||||||
|
calls = async_mock_service(hass, "test_domain", "test_service")
|
||||||
|
|
||||||
|
config = {
|
||||||
|
"service": "test_domain.test_service",
|
||||||
|
"target": {"entity_id": target},
|
||||||
|
}
|
||||||
|
|
||||||
|
await service.async_call_from_config(hass, config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert dict(calls[0].data) == {"entity_id": target}
|
||||||
|
|
||||||
|
|
||||||
async def test_extract_entity_ids(hass):
|
async def test_extract_entity_ids(hass):
|
||||||
"""Test extract_entity_ids method."""
|
"""Test extract_entity_ids method."""
|
||||||
hass.states.async_set("light.Bowl", STATE_ON)
|
hass.states.async_set("light.Bowl", STATE_ON)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user