From 3635dae0f59c039764e054d9b0e801b3b409c129 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 3 Sep 2024 15:07:42 +0200 Subject: [PATCH] Add blog post about deprecated template.attach (#2302) * Add blog post about deprecated template.attach * Improve * Improve language --- blog/2024-09-02-template-hass-required.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 blog/2024-09-02-template-hass-required.md diff --git a/blog/2024-09-02-template-hass-required.md b/blog/2024-09-02-template-hass-required.md new file mode 100644 index 00000000..7c5a556f --- /dev/null +++ b/blog/2024-09-02-template-hass-required.md @@ -0,0 +1,12 @@ +--- +author: Erik Montnemery +authorURL: https://github.com/emontnemery +title: "Template.hass is no longer automatically set when rendering templates" +--- + +With the merge of [core PR #89242](https://github.com/home-assistant/core/pull/124656), which landed in Home Assistant Core 2023.4, `Template.hass` will be set on `Template` objects created during schema validation. + +Before this change, it was necessary to check and set `Template.hass` before rendering templates, and this happened in numerous places throughout the codebase. +Such code has been removed from Home Assistant Core, which impacts custom integration authors: +- Custom integrations which create `Template` objects manually must pass a valid `hass` object to the constructor. This is in particular the case when creating templates for config entries. Not passing a `hass` object will trigger a deprecation warning and fail in Home Assistant Core 2025.10. +- The helper function `template.attach` no longer serves a purpose and is no longer used by core. It has been marked as deprecated, and scheduled for removal in Home Assistant Core 2025.10.