Add missing trigger.for variable to template trigger (#24893)

This commit is contained in:
Phil Bruckner 2019-07-02 10:46:26 -05:00 committed by Pascal Vizeli
parent 3f4ce70414
commit 8dca73d08e
2 changed files with 137 additions and 14 deletions

View file

@ -35,6 +35,23 @@ async def async_trigger(hass, config, action, automation_info):
"""Listen for state changes and calls action."""
nonlocal unsub_track_same
@callback
def call_action():
"""Call action with right context."""
hass.async_run_job(action({
'trigger': {
'platform': 'template',
'entity_id': entity_id,
'from_state': from_s,
'to_state': to_s,
'for': time_delta if not time_delta else period
},
}, context=(to_s.context if to_s else None)))
if not time_delta:
call_action()
return
variables = {
'trigger': {
'platform': 'template',
@ -44,16 +61,6 @@ async def async_trigger(hass, config, action, automation_info):
},
}
@callback
def call_action():
"""Call action with right context."""
hass.async_run_job(action(
variables, context=(to_s.context if to_s else None)))
if not time_delta:
call_action()
return
try:
if isinstance(time_delta, template.Template):
period = vol.All(