1
mirror of https://github.com/home-assistant/core synced 2024-09-25 00:41:32 +02:00

Populate trigger variable when manually triggering automation (#48202)

* Populate trigger variable when manually triggering automation

* Update tests/components/automation/test_init.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
Paulus Schoutsen 2021-03-22 00:22:32 -07:00 committed by GitHub
parent 6b93c4073d
commit f67e8b4369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -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,
)

View File

@ -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 automation trigger 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