This commit is contained in:
Paulus Schoutsen 2020-10-26 13:36:03 +01:00 committed by GitHub
parent e552c9ba96
commit bba770b411
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions

View File

@ -988,7 +988,7 @@ def async_track_template_result(
action: TrackTemplateResultListener, action: TrackTemplateResultListener,
raise_on_template_error: bool = False, raise_on_template_error: bool = False,
) -> _TrackTemplateResultInfo: ) -> _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 The action will fire with the initial result from the template, and
then whenever the output from the template changes. The template will then whenever the output from the template changes. The template will

View File

@ -146,10 +146,14 @@ def gen_result_wrapper(kls):
class TupleWrapper(tuple, ResultWrapper): class TupleWrapper(tuple, ResultWrapper):
"""Wrap a tuple.""" """Wrap a tuple."""
# This is all magic to be allowed to subclass a tuple.
def __new__(cls, value: tuple, render_result: str) -> "TupleWrapper": def __new__(cls, value: tuple, render_result: str) -> "TupleWrapper":
"""Create a new tuple class.""" """Create a new tuple class."""
return super().__new__(cls, tuple(value)) return super().__new__(cls, tuple(value))
# pylint: disable=super-init-not-called
def __init__(self, value: tuple, render_result: str): def __init__(self, value: tuple, render_result: str):
"""Initialize a new tuple class.""" """Initialize a new tuple class."""
self.render_result = render_result self.render_result = render_result
@ -398,7 +402,7 @@ class Template:
return self._parse_result(render_result) 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.""" """Parse the result."""
try: try:
result = literal_eval(render_result) result = literal_eval(render_result)

View File

@ -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): async def test_track_two_templates_with_different_rate_limits(hass):
"""Test two templates with different rate limits.""" """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) template_five = Template("{{ states | count }}", hass)
refresh_runs = { refresh_runs = {