Improve async_track_template_result
callback typing (#97135)
This commit is contained in:
parent
c0da6b822e
commit
582499a260
7 changed files with 228 additions and 72 deletions
|
@ -27,7 +27,7 @@ from homeassistant.const import (
|
|||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConditionError, TemplateError
|
||||
from homeassistant.helpers import condition
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -259,14 +259,13 @@ class BayesianBinarySensor(BinarySensorEntity):
|
|||
|
||||
@callback
|
||||
def _async_template_result_changed(
|
||||
event: Event | None, updates: list[TrackTemplateResult]
|
||||
event: EventType[EventStateChangedData] | None,
|
||||
updates: list[TrackTemplateResult],
|
||||
) -> None:
|
||||
track_template_result = updates.pop()
|
||||
template = track_template_result.template
|
||||
result = track_template_result.result
|
||||
entity: str | None = (
|
||||
None if event is None else event.data.get(CONF_ENTITY_ID)
|
||||
)
|
||||
entity_id = None if event is None else event.data["entity_id"]
|
||||
if isinstance(result, TemplateError):
|
||||
_LOGGER.error(
|
||||
"TemplateError('%s') while processing template '%s' in entity '%s'",
|
||||
|
@ -283,8 +282,8 @@ class BayesianBinarySensor(BinarySensorEntity):
|
|||
observation.observed = observed
|
||||
|
||||
# in some cases a template may update because of the absence of an entity
|
||||
if entity is not None:
|
||||
observation.entity_id = entity
|
||||
if entity_id is not None:
|
||||
observation.entity_id = entity_id
|
||||
|
||||
self.current_observations[observation.id] = observation
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue