Skip to content

Commit 142daf5

Browse files
Call async_track_template_result with template without hass now fails (home-assistant#153473)
Co-authored-by: Joost Lekkerkerker <[email protected]>
1 parent 8bd0ff7 commit 142daf5

File tree

2 files changed

+16
-37
lines changed

2 files changed

+16
-37
lines changed

homeassistant/helpers/event.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
callback,
3737
split_entity_id,
3838
)
39-
from homeassistant.exceptions import TemplateError
39+
from homeassistant.exceptions import HomeAssistantError, TemplateError
4040
from homeassistant.loader import bind_hass
4141
from homeassistant.util import dt as dt_util
4242
from homeassistant.util.async_ import run_callback_threadsafe
@@ -1004,12 +1004,9 @@ def __init__(
10041004
if track_template_.template.hass:
10051005
continue
10061006

1007-
frame.report_usage(
1008-
"calls async_track_template_result with template without hass",
1009-
core_behavior=frame.ReportBehavior.LOG,
1010-
breaks_in_ha_version="2025.10",
1007+
raise HomeAssistantError(
1008+
"Calls async_track_template_result with template without hass"
10111009
)
1012-
track_template_.template.hass = hass
10131010

10141011
self._rate_limit = KeyedRateLimit(hass)
10151012
self._info: dict[Template, RenderInfo] = {}

tests/helpers/test_event.py

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
HomeAssistant,
2323
callback,
2424
)
25-
from homeassistant.exceptions import TemplateError
25+
from homeassistant.exceptions import HomeAssistantError, TemplateError
2626
from homeassistant.helpers.device_registry import EVENT_DEVICE_REGISTRY_UPDATED
2727
from homeassistant.helpers.entity_registry import EVENT_ENTITY_REGISTRY_UPDATED
2828
from homeassistant.helpers.event import (
@@ -4975,43 +4975,25 @@ def on_state_report(event: Event[EventStateReportedData]) -> None:
49754975
}
49764976

49774977

4978-
async def test_async_track_template_no_hass_deprecated(
4979-
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
4980-
) -> None:
4981-
"""Test async_track_template with a template without hass is deprecated."""
4982-
message = (
4983-
"Detected code that calls async_track_template_result with template without "
4984-
"hass. This will stop working in Home Assistant 2025.10, please "
4985-
"report this issue"
4986-
)
4978+
async def test_async_track_template_no_hass_fails(hass: HomeAssistant) -> None:
4979+
"""Test async_track_template with a template without hass now fails."""
4980+
message = "Calls async_track_template_result with template without hass"
49874981

4988-
async_track_template(hass, Template("blah"), lambda x, y, z: None)
4989-
assert message in caplog.text
4990-
caplog.clear()
4982+
with pytest.raises(HomeAssistantError, match=message):
4983+
async_track_template(hass, Template("blah"), lambda x, y, z: None)
49914984

49924985
async_track_template(hass, Template("blah", hass), lambda x, y, z: None)
4993-
assert message not in caplog.text
4994-
caplog.clear()
49954986

49964987

4997-
async def test_async_track_template_result_no_hass_deprecated(
4998-
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
4999-
) -> None:
5000-
"""Test async_track_template_result with a template without hass is deprecated."""
5001-
message = (
5002-
"Detected code that calls async_track_template_result with template without "
5003-
"hass. This will stop working in Home Assistant 2025.10, please "
5004-
"report this issue"
5005-
)
4988+
async def test_async_track_template_result_no_hass_fails(hass: HomeAssistant) -> None:
4989+
"""Test async_track_template_result with a template without hass now fails."""
4990+
message = "Calls async_track_template_result with template without hass"
50064991

5007-
async_track_template_result(
5008-
hass, [TrackTemplate(Template("blah"), None)], lambda x, y, z: None
5009-
)
5010-
assert message in caplog.text
5011-
caplog.clear()
4992+
with pytest.raises(HomeAssistantError, match=message):
4993+
async_track_template_result(
4994+
hass, [TrackTemplate(Template("blah"), None)], lambda x, y, z: None
4995+
)
50124996

50134997
async_track_template_result(
50144998
hass, [TrackTemplate(Template("blah", hass), None)], lambda x, y, z: None
50154999
)
5016-
assert message not in caplog.text
5017-
caplog.clear()

0 commit comments

Comments
 (0)