mirror of
https://github.com/home-assistant/core.git
synced 2025-11-06 09:29:27 +00:00
Make async_track_template_result track multiple templates (#39371)
* Make async_track_template_result track multiple templates Combine template entity updates to only write ha state once per template group update * Make async_track_template_result use dataclasses for input/output * black versions * naming
This commit is contained in:
@@ -21,6 +21,7 @@ from homeassistant.exceptions import TemplateError
|
||||
from homeassistant.helpers import condition
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.event import (
|
||||
TrackTemplate,
|
||||
async_track_state_change_event,
|
||||
async_track_template_result,
|
||||
)
|
||||
@@ -187,7 +188,10 @@ class BayesianBinarySensor(BinarySensorEntity):
|
||||
)
|
||||
|
||||
@callback
|
||||
def _async_template_result_changed(event, template, last_result, result):
|
||||
def _async_template_result_changed(event, updates):
|
||||
track_template_result = updates.pop()
|
||||
template = track_template_result.template
|
||||
result = track_template_result.result
|
||||
entity = event and event.data.get("entity_id")
|
||||
|
||||
if isinstance(result, TemplateError):
|
||||
@@ -215,7 +219,9 @@ class BayesianBinarySensor(BinarySensorEntity):
|
||||
|
||||
for template in self.observations_by_template:
|
||||
info = async_track_template_result(
|
||||
self.hass, template, _async_template_result_changed
|
||||
self.hass,
|
||||
[TrackTemplate(template, None)],
|
||||
_async_template_result_changed,
|
||||
)
|
||||
|
||||
self._callbacks.append(info)
|
||||
|
||||
Reference in New Issue
Block a user