Fix script wait templates with now/utcnow (#44717)

This commit is contained in:
J. Nick Koston
2021-01-01 02:03:34 -10:00
committed by GitHub
parent 7415dacec9
commit 2ef25e7414
4 changed files with 67 additions and 7 deletions

View File

@@ -62,7 +62,11 @@ from homeassistant.core import (
callback,
)
from homeassistant.helpers import condition, config_validation as cv, service, template
from homeassistant.helpers.event import async_call_later, async_track_template
from homeassistant.helpers.event import (
TrackTemplate,
async_call_later,
async_track_template_result,
)
from homeassistant.helpers.script_variables import ScriptVariables
from homeassistant.helpers.trigger import (
async_initialize_triggers,
@@ -355,7 +359,7 @@ class _ScriptRun:
return
@callback
def async_script_wait(entity_id, from_s, to_s):
def _async_script_wait(event, updates):
"""Handle script after template condition is true."""
self._variables["wait"] = {
"remaining": to_context.remaining if to_context else delay,
@@ -364,9 +368,12 @@ class _ScriptRun:
done.set()
to_context = None
unsub = async_track_template(
self._hass, wait_template, async_script_wait, self._variables
info = async_track_template_result(
self._hass,
[TrackTemplate(wait_template, self._variables)],
_async_script_wait,
)
unsub = info.async_remove
self._changed()
done = asyncio.Event()