Allow templates in data & service parameters (making data_template & service_template obsolete) (#39210)

This commit is contained in:
Franck Nijhof 2020-08-24 16:21:48 +02:00 committed by GitHub
parent a47f73244c
commit 181709f3d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 99 additions and 25 deletions

View file

@ -439,17 +439,18 @@ class _ScriptRun:
CONF_ALIAS, self._action[CONF_EVENT]
)
self._log("Executing step %s", self._script.last_action)
event_data = dict(self._action.get(CONF_EVENT_DATA, {}))
if CONF_EVENT_DATA_TEMPLATE in self._action:
event_data = {}
for conf in [CONF_EVENT_DATA, CONF_EVENT_DATA_TEMPLATE]:
if conf not in self._action:
continue
try:
event_data.update(
template.render_complex(
self._action[CONF_EVENT_DATA_TEMPLATE], self._variables
)
template.render_complex(self._action[conf], self._variables)
)
except exceptions.TemplateError as ex:
self._log(
"Error rendering event data template: %s", ex, level=logging.ERROR
"Error rendering event data template: %s", ex, level=logging.ERROR,
)
self._hass.bus.async_fire(