From e6c4cf2967be027605aeaa1df86006e38e896d91 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 22 Mar 2021 04:30:10 +0000 Subject: [PATCH 1/2] Populate trigger variable when manually triggering automation --- .../components/automation/__init__.py | 2 +- tests/components/automation/test_init.py | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 4c278cbf5f0cc..79c6dcc2312d2 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -189,7 +189,7 @@ async def async_setup(hass, config): async def trigger_service_handler(entity, service_call): """Handle forced automation trigger, e.g. from frontend.""" await entity.async_trigger( - service_call.data[ATTR_VARIABLES], + {**service_call.data[ATTR_VARIABLES], "trigger": {"platform": None}}, skip_condition=service_call.data[CONF_SKIP_CONDITION], context=service_call.context, ) diff --git a/tests/components/automation/test_init.py b/tests/components/automation/test_init.py index 91531481a993c..cab21f7899b67 100644 --- a/tests/components/automation/test_init.py +++ b/tests/components/automation/test_init.py @@ -1355,3 +1355,33 @@ async def test_blueprint_automation(hass, calls): assert automation.entities_in_automation(hass, "automation.automation_0") == [ "light.kitchen" ] + + +async def test_trigger_service(hass, calls): + """Test the reload config service.""" + assert await async_setup_component( + hass, + automation.DOMAIN, + { + automation.DOMAIN: { + "alias": "hello", + "trigger": {"platform": "event", "event_type": "test_event"}, + "action": { + "service": "test.automation", + "data_template": {"trigger": "{{ trigger }}"}, + }, + } + }, + ) + context = Context() + await hass.services.async_call( + "automation", + "trigger", + {"entity_id": "automation.hello"}, + blocking=True, + context=context, + ) + + assert len(calls) == 1 + assert calls[0].data.get("trigger") == {"platform": None} + assert calls[0].context.parent_id is context.id From 2571ad0a0e287d4f29b8e94d804ad3b4722f6add Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 22 Mar 2021 08:22:24 +0100 Subject: [PATCH 2/2] Update tests/components/automation/test_init.py --- tests/components/automation/test_init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/components/automation/test_init.py b/tests/components/automation/test_init.py index cab21f7899b67..71727258fcc45 100644 --- a/tests/components/automation/test_init.py +++ b/tests/components/automation/test_init.py @@ -1358,7 +1358,7 @@ async def test_blueprint_automation(hass, calls): async def test_trigger_service(hass, calls): - """Test the reload config service.""" + """Test the automation trigger service.""" assert await async_setup_component( hass, automation.DOMAIN,