diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 6856983aa59..1786194b437 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -81,6 +81,7 @@ from . import ( label_registry, location as loc_helper, ) +from .deprecation import deprecated_function from .singleton import singleton from .translation import async_translate_state from .typing import TemplateVarsType @@ -207,15 +208,24 @@ def async_setup(hass: HomeAssistant) -> bool: @bind_hass +@deprecated_function( + "automatic setting of Template.hass introduced by HA Core PR #89242", + breaks_in_ha_version="2025.10", +) def attach(hass: HomeAssistant, obj: Any) -> None: + """Recursively attach hass to all template instances in list and dict.""" + return _attach(hass, obj) + + +def _attach(hass: HomeAssistant, obj: Any) -> None: """Recursively attach hass to all template instances in list and dict.""" if isinstance(obj, list): for child in obj: - attach(hass, child) + _attach(hass, child) elif isinstance(obj, collections.abc.Mapping): for child_key, child_value in obj.items(): - attach(hass, child_key) - attach(hass, child_value) + _attach(hass, child_key) + _attach(hass, child_value) elif isinstance(obj, Template): obj.hass = hass diff --git a/tests/components/script/test_blueprint.py b/tests/components/script/test_blueprint.py index aef22b93bcf..160b330c109 100644 --- a/tests/components/script/test_blueprint.py +++ b/tests/components/script/test_blueprint.py @@ -109,7 +109,6 @@ async def test_confirmable_notification( assert len(mock_call_action.mock_calls) == 1 _hass, config, variables, _context = mock_call_action.mock_calls[0][1] - template.attach(hass, config) rendered_config = template.render_complex(config, variables) assert rendered_config == { diff --git a/tests/helpers/test_service.py b/tests/helpers/test_service.py index 81cc189e1af..efe24fe4b8e 100644 --- a/tests/helpers/test_service.py +++ b/tests/helpers/test_service.py @@ -39,7 +39,6 @@ from homeassistant.helpers import ( device_registry as dr, entity_registry as er, service, - template, ) import homeassistant.helpers.config_validation as cv from homeassistant.loader import async_get_integration @@ -565,9 +564,6 @@ async def test_not_mutate_input(hass: HomeAssistant) -> None: config = cv.SERVICE_SCHEMA(config) orig = cv.SERVICE_SCHEMA(orig) - # Only change after call is each template getting hass attached - template.attach(hass, orig) - await service.async_call_from_config(hass, config, validate_config=False) assert orig == config