mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Restore unnecessary assignment of Template.hass in event helper (#125143)
This commit is contained in:
parent
fd01e22ca4
commit
cf10549df4
@ -981,6 +981,22 @@ class TrackTemplateResultInfo:
|
|||||||
|
|
||||||
self._last_result: dict[Template, bool | str | TemplateError] = {}
|
self._last_result: dict[Template, bool | str | TemplateError] = {}
|
||||||
|
|
||||||
|
for track_template_ in track_templates:
|
||||||
|
if track_template_.template.hass:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# pylint: disable-next=import-outside-toplevel
|
||||||
|
from .frame import report
|
||||||
|
|
||||||
|
report(
|
||||||
|
(
|
||||||
|
"calls async_track_template_result with template without hass, "
|
||||||
|
"which will stop working in HA Core 2025.10"
|
||||||
|
),
|
||||||
|
error_if_core=False,
|
||||||
|
)
|
||||||
|
track_template_.template.hass = hass
|
||||||
|
|
||||||
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
|
||||||
|
@ -4938,3 +4938,43 @@ async def test_async_track_state_report_event(hass: HomeAssistant) -> None:
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(tracker_called) == 2
|
assert len(tracker_called) == 2
|
||||||
unsub()
|
unsub()
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_track_template_no_hass_deprecated(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
|
"""Test async_track_template with a template without hass is deprecated."""
|
||||||
|
message = (
|
||||||
|
"Detected code that calls async_track_template_result with template without "
|
||||||
|
"hass, which will stop working in HA Core 2025.10. Please report this issue."
|
||||||
|
)
|
||||||
|
|
||||||
|
async_track_template(hass, Template("blah"), lambda x, y, z: None)
|
||||||
|
assert message in caplog.text
|
||||||
|
caplog.clear()
|
||||||
|
|
||||||
|
async_track_template(hass, Template("blah", hass), lambda x, y, z: None)
|
||||||
|
assert message not in caplog.text
|
||||||
|
caplog.clear()
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_track_template_result_no_hass_deprecated(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
|
"""Test async_track_template_result with a template without hass is deprecated."""
|
||||||
|
message = (
|
||||||
|
"Detected code that calls async_track_template_result with template without "
|
||||||
|
"hass, which will stop working in HA Core 2025.10. Please report this issue."
|
||||||
|
)
|
||||||
|
|
||||||
|
async_track_template_result(
|
||||||
|
hass, [TrackTemplate(Template("blah"), None)], lambda x, y, z: None
|
||||||
|
)
|
||||||
|
assert message in caplog.text
|
||||||
|
caplog.clear()
|
||||||
|
|
||||||
|
async_track_template_result(
|
||||||
|
hass, [TrackTemplate(Template("blah", hass), None)], lambda x, y, z: None
|
||||||
|
)
|
||||||
|
assert message not in caplog.text
|
||||||
|
caplog.clear()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user