1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Accept more templates in service fields (#150239)

This commit is contained in:
Artur Pragacz
2025-11-03 16:40:42 +01:00
committed by GitHub
parent 983af1af7b
commit fad217837f
2 changed files with 35 additions and 4 deletions

View File

@@ -469,6 +469,7 @@ async def test_service_call(hass: HomeAssistant) -> None:
"floor_id": ["test-floor-id"],
}
# Templated strings in target fields
config = {
"action": "{{ 'test_domain.test_service' }}",
"target": {
@@ -489,6 +490,7 @@ async def test_service_call(hass: HomeAssistant) -> None:
"floor_id": ["floor-first", "floor-second"],
}
# Templated dict as target
config = {
"action": "{{ 'test_domain.test_service' }}",
"target": "{{ var_target }}",
@@ -511,6 +513,27 @@ async def test_service_call(hass: HomeAssistant) -> None:
"entity_id": ["light.static"],
}
# Templated lists as target fields
config = {
"action": "{{ 'test_domain.test_service' }}",
"target": {
"area_id": "{{ ['area-42', 'area-51'] }}",
"device_id": "{{ ['abcdef', 'fedcba'] }}",
"entity_id": "{{ ['light.static', 'light.dynamic'] }}",
"floor_id": "{{ ['floor-first', 'floor-second'] }}",
},
}
await service.async_call_from_config(hass, config)
await hass.async_block_till_done()
assert dict(calls[3].data) == {
"area_id": ["area-42", "area-51"],
"device_id": ["abcdef", "fedcba"],
"entity_id": ["light.static", "light.dynamic"],
"floor_id": ["floor-first", "floor-second"],
}
async def test_service_template_service_call(hass: HomeAssistant) -> None:
"""Test legacy service_template call with templating."""