From faa24026b93dd7129503164b025b021f12958300 Mon Sep 17 00:00:00 2001 From: Artur Pragacz Date: Mon, 4 Aug 2025 01:17:22 +0200 Subject: [PATCH 1/3] Accept more templates in service fields --- homeassistant/helpers/config_validation.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 6a922835dcbeb2..9b406f41c83bc8 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -1359,16 +1359,24 @@ def platform_only_config_schema(domain: str) -> Callable[[dict], dict]: vol.All(list, template_complex), ), vol.Optional(ATTR_DEVICE_ID): vol.Any( - ENTITY_MATCH_NONE, vol.All(ensure_list, [vol.Any(dynamic_template, str)]) + ENTITY_MATCH_NONE, + dynamic_template, + vol.All(ensure_list, [vol.Any(dynamic_template, str)]), ), vol.Optional(ATTR_AREA_ID): vol.Any( - ENTITY_MATCH_NONE, vol.All(ensure_list, [vol.Any(dynamic_template, str)]) + ENTITY_MATCH_NONE, + dynamic_template, + vol.All(ensure_list, [vol.Any(dynamic_template, str)]), ), vol.Optional(ATTR_FLOOR_ID): vol.Any( - ENTITY_MATCH_NONE, vol.All(ensure_list, [vol.Any(dynamic_template, str)]) + ENTITY_MATCH_NONE, + dynamic_template, + vol.All(ensure_list, [vol.Any(dynamic_template, str)]), ), vol.Optional(ATTR_LABEL_ID): vol.Any( - ENTITY_MATCH_NONE, vol.All(ensure_list, [vol.Any(dynamic_template, str)]) + ENTITY_MATCH_NONE, + dynamic_template, + vol.All(ensure_list, [vol.Any(dynamic_template, str)]), ), } From 52eea79b1fe896125154ebb98836feeb29e22772 Mon Sep 17 00:00:00 2001 From: Artur Pragacz Date: Thu, 30 Oct 2025 19:00:59 +0100 Subject: [PATCH 2/3] test --- tests/helpers/test_service.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/helpers/test_service.py b/tests/helpers/test_service.py index 29ececca43a067..d4862fde971a3b 100644 --- a/tests/helpers/test_service.py +++ b/tests/helpers/test_service.py @@ -511,6 +511,26 @@ async def test_service_call(hass: HomeAssistant) -> None: "entity_id": ["light.static"], } + 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.""" From 696d91cdf1d4f62be7b5a6398f38089e16a1862c Mon Sep 17 00:00:00 2001 From: Artur Pragacz Date: Mon, 3 Nov 2025 12:35:15 +0100 Subject: [PATCH 3/3] Add comments in test --- tests/helpers/test_service.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/helpers/test_service.py b/tests/helpers/test_service.py index d4862fde971a3b..52cecd8420f194 100644 --- a/tests/helpers/test_service.py +++ b/tests/helpers/test_service.py @@ -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,7 @@ async def test_service_call(hass: HomeAssistant) -> None: "entity_id": ["light.static"], } + # Templated lists as target fields config = { "action": "{{ 'test_domain.test_service' }}", "target": {