Return the listeners with the template result for the websocket api (#39925)

This commit is contained in:
J. Nick Koston authored and Paulus Schoutsen committed 2020-09-12 12:28:44 +00:00
1 parent 3240be0bb6
commit f81606cbf5
4 files changed
+118 -11

No files matched your search

@@ -253,9 +253,11 @@ def handle_render_template(hass, connection, msg):
template.hass = hass
variables = msg.get("variables")
info = None
@callback
def _template_listener(event, updates):
nonlocal info
track_template_result = updates.pop()
result = track_template_result.result
if isinstance(result, TemplateError):
@@ -267,7 +269,11 @@ def handle_render_template(hass, connection, msg):
result = None
connection.send_message(messages.event_message(msg["id"], {"result": result}))
connection.send_message(
messages.event_message(
msg["id"], {"result": result, "listeners": info.listeners} # type: ignore
)
)
info = async_track_template_result(
hass, [TrackTemplate(template, variables)], _template_listener