Log deprecation warning when template.Template is created without hass (#125142)

* Log deprecation warning when template.Template is created without hass

* Improve docstring
This commit is contained in:
Bram Kragten
2024-09-03 21:09:12 +02:00
parent 70b811096c
commit 54cf52069e
2 changed files with 34 additions and 1 deletions
+17
View File
@@ -6281,3 +6281,20 @@ def test_unzip(hass: HomeAssistant, col, expected) -> None:
).async_render({"col": col})
== expected
)
def test_warn_no_hass(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -> None:
"""Test deprecation warning when instantiating Template without hass."""
message = "Detected code that creates a template object without passing hass"
template.Template("blah")
assert message in caplog.text
caplog.clear()
template.Template("blah", None)
assert message in caplog.text
caplog.clear()
template.Template("blah", hass)
assert message not in caplog.text
caplog.clear()