Fix typing TrackTemplateResultListener
[helpers.event] (#63541)
This commit is contained in:
parent
f8a78a49bb
commit
198ade5e2b
2 changed files with 10 additions and 8 deletions
|
@ -354,7 +354,9 @@ async def handle_render_template(
|
||||||
return
|
return
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _template_listener(event: Event, updates: list[TrackTemplateResult]) -> None:
|
def _template_listener(
|
||||||
|
event: Event | None, updates: list[TrackTemplateResult]
|
||||||
|
) -> None:
|
||||||
nonlocal info
|
nonlocal info
|
||||||
track_template_result = updates.pop()
|
track_template_result = updates.pop()
|
||||||
result = track_template_result.result
|
result = track_template_result.result
|
||||||
|
|
|
@ -9,7 +9,7 @@ from datetime import datetime, timedelta
|
||||||
import functools as ft
|
import functools as ft
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from typing import Any, Callable, List, cast
|
from typing import Any, Callable, List, Union, cast
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
|
|
||||||
|
@ -533,7 +533,7 @@ class _TrackStateChangeFiltered:
|
||||||
"""Handle removal / refresh of tracker init."""
|
"""Handle removal / refresh of tracker init."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self._action = action
|
self._action = action
|
||||||
self._listeners: dict[str, Callable] = {}
|
self._listeners: dict[str, Callable[[], None]] = {}
|
||||||
self._last_track_states: TrackStates = track_states
|
self._last_track_states: TrackStates = track_states
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -721,7 +721,7 @@ def async_track_template(
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _template_changed_listener(
|
def _template_changed_listener(
|
||||||
event: Event, updates: list[TrackTemplateResult]
|
event: Event | None, updates: list[TrackTemplateResult]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Check if condition is correct and run action."""
|
"""Check if condition is correct and run action."""
|
||||||
track_result = updates.pop()
|
track_result = updates.pop()
|
||||||
|
@ -769,7 +769,7 @@ class _TrackTemplateResultInfo:
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
track_templates: Sequence[TrackTemplate],
|
track_templates: Sequence[TrackTemplate],
|
||||||
action: Callable,
|
action: Callable[[Event | None, list[TrackTemplateResult]], None],
|
||||||
has_super_template: bool = False,
|
has_super_template: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle removal / refresh of tracker init."""
|
"""Handle removal / refresh of tracker init."""
|
||||||
|
@ -786,7 +786,7 @@ class _TrackTemplateResultInfo:
|
||||||
self._rate_limit = KeyedRateLimit(hass)
|
self._rate_limit = KeyedRateLimit(hass)
|
||||||
self._info: dict[Template, RenderInfo] = {}
|
self._info: dict[Template, RenderInfo] = {}
|
||||||
self._track_state_changes: _TrackStateChangeFiltered | None = None
|
self._track_state_changes: _TrackStateChangeFiltered | None = None
|
||||||
self._time_listeners: dict[Template, Callable] = {}
|
self._time_listeners: dict[Template, Callable[[], None]] = {}
|
||||||
|
|
||||||
def async_setup(self, raise_on_template_error: bool, strict: bool = False) -> None:
|
def async_setup(self, raise_on_template_error: bool, strict: bool = False) -> None:
|
||||||
"""Activation of template tracking."""
|
"""Activation of template tracking."""
|
||||||
|
@ -986,7 +986,7 @@ class _TrackTemplateResultInfo:
|
||||||
replayed is True if the event is being replayed because the
|
replayed is True if the event is being replayed because the
|
||||||
rate limit was hit.
|
rate limit was hit.
|
||||||
"""
|
"""
|
||||||
updates = []
|
updates: list[TrackTemplateResult] = []
|
||||||
info_changed = False
|
info_changed = False
|
||||||
now = event.time_fired if not replayed and event else dt_util.utcnow()
|
now = event.time_fired if not replayed and event else dt_util.utcnow()
|
||||||
|
|
||||||
|
@ -1075,7 +1075,7 @@ class _TrackTemplateResultInfo:
|
||||||
|
|
||||||
TrackTemplateResultListener = Callable[
|
TrackTemplateResultListener = Callable[
|
||||||
[
|
[
|
||||||
Event,
|
Union[Event, None],
|
||||||
List[TrackTemplateResult],
|
List[TrackTemplateResult],
|
||||||
],
|
],
|
||||||
None,
|
None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue