From e5f13b41263de85a4fe20247dffab560f29f5372 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Thu, 19 Mar 2026 17:21:43 +0100 Subject: [PATCH] Add state_attr_translated template filter and function (#165317) Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: piitaya <5878303+piitaya@users.noreply.github.com> Co-authored-by: Martin Hjelmare --- homeassistant/helpers/template/__init__.py | 53 ++++++++- homeassistant/helpers/translation.py | 40 +++++++ tests/helpers/template/test_init.py | 130 +++++++++++++++++++++ tests/helpers/test_translation.py | 86 ++++++++++++++ 4 files changed, 307 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/template/__init__.py b/homeassistant/helpers/template/__init__.py index 13d67e6939d..05f16f4355e 100644 --- a/homeassistant/helpers/template/__init__.py +++ b/homeassistant/helpers/template/__init__.py @@ -8,6 +8,7 @@ import collections.abc from collections.abc import Callable, Generator, Iterable from copy import deepcopy from datetime import datetime, timedelta +from enum import Enum from functools import cache, lru_cache, partial, wraps import json import logging @@ -57,7 +58,10 @@ from homeassistant.core import ( from homeassistant.exceptions import TemplateError from homeassistant.helpers import entity_registry as er, location as loc_helper from homeassistant.helpers.singleton import singleton -from homeassistant.helpers.translation import async_translate_state +from homeassistant.helpers.translation import ( + async_translate_state, + async_translate_state_attr, +) from homeassistant.helpers.typing import TemplateVarsType from homeassistant.util import convert, location as location_util from homeassistant.util.async_ import run_callback_threadsafe @@ -807,6 +811,48 @@ class StateTranslated: return "