Restore unnecessary assignment of Template.hass in event helper (#125143)
This commit is contained in:
parent
54cf52069e
commit
4e1a77326e
2 changed files with 56 additions and 0 deletions
|
@ -981,6 +981,22 @@ class TrackTemplateResultInfo:
|
|||
|
||||
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._info: dict[Template, RenderInfo] = {}
|
||||
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()
|
||||
assert len(tracker_called) == 2
|
||||
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…
Add table
Reference in a new issue