diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index b4caccf5311..2044dbd7856 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -988,7 +988,7 @@ def async_track_template_result( action: TrackTemplateResultListener, raise_on_template_error: bool = False, ) -> _TrackTemplateResultInfo: - """Add a listener that fires when a the result of a template changes. + """Add a listener that fires when the result of a template changes. The action will fire with the initial result from the template, and then whenever the output from the template changes. The template will diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 9ffc6593955..de131d8dc5c 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -146,10 +146,14 @@ def gen_result_wrapper(kls): class TupleWrapper(tuple, ResultWrapper): """Wrap a tuple.""" + # This is all magic to be allowed to subclass a tuple. + def __new__(cls, value: tuple, render_result: str) -> "TupleWrapper": """Create a new tuple class.""" return super().__new__(cls, tuple(value)) + # pylint: disable=super-init-not-called + def __init__(self, value: tuple, render_result: str): """Initialize a new tuple class.""" self.render_result = render_result @@ -398,7 +402,7 @@ class Template: return self._parse_result(render_result) - def _parse_result(self, render_result: str) -> Any: + def _parse_result(self, render_result: str) -> Any: # pylint: disable=no-self-use """Parse the result.""" try: result = literal_eval(render_result) diff --git a/tests/helpers/test_event.py b/tests/helpers/test_event.py index 9f6e66048ff..8add5cc1cf3 100644 --- a/tests/helpers/test_event.py +++ b/tests/helpers/test_event.py @@ -1771,7 +1771,7 @@ async def test_specifically_referenced_entity_is_not_rate_limited(hass): async def test_track_two_templates_with_different_rate_limits(hass): """Test two templates with different rate limits.""" - template_one = Template("{{ states | count }} ", hass) + template_one = Template("{{ (states | count) + 0 }}", hass) template_five = Template("{{ states | count }}", hass) refresh_runs = {