From c5a190536995eb8c714eac91b742448493dda1e7 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 12 Sep 2025 11:27:50 +0200 Subject: [PATCH 1/2] Add support for translation_placeholders --- zha/application/platforms/__init__.py | 10 ++++++++++ zha/zigbee/device.py | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/zha/application/platforms/__init__.py b/zha/application/platforms/__init__.py index c9525a33..0092f2f8 100644 --- a/zha/application/platforms/__init__.py +++ b/zha/application/platforms/__init__.py @@ -56,6 +56,7 @@ class BaseEntityInfo: platform: str class_name: str translation_key: str | None + translation_placeholders: dict[str, str] | None device_class: str | None state_class: str | None entity_category: str | None @@ -117,6 +118,7 @@ class BaseEntity(LogMixin, EventBase): _attr_fallback_name: str | None = None _attr_icon: str | None = None _attr_translation_key: str | None = None + _attr_translation_placeholders: dict[str, str] | None = None _attr_entity_category: EntityCategory | None = None _attr_entity_registry_enabled_default: bool = True _attr_device_class: str | None = None @@ -205,6 +207,13 @@ def translation_key(self) -> str | None: return self._attr_translation_key return None + @property + def translation_placeholders(self) -> dict[str, str] | None: + """Return the translation placeholders.""" + if hasattr(self, "_attr_translation_placeholders"): + return self._attr_translation_placeholders + return None + @property def entity_category(self) -> EntityCategory | None: """Return the entity category.""" @@ -258,6 +267,7 @@ def info_object(self) -> BaseEntityInfo: class_name=self.__class__.__name__, fallback_name=self.fallback_name, translation_key=self.translation_key, + translation_placeholders=self.translation_placeholders, device_class=self.device_class, state_class=self.state_class, entity_category=self.entity_category, diff --git a/zha/zigbee/device.py b/zha/zigbee/device.py index af0202a2..09cb8511 100644 --- a/zha/zigbee/device.py +++ b/zha/zigbee/device.py @@ -908,6 +908,11 @@ def _apply_entity_metadata_changes(self, entity: PlatformEntity) -> None: if meta.new_translation_key is not None: entity._attr_translation_key = meta.new_translation_key + if meta.new_translation_placeholders is not None: + entity._attr_translation_placeholders = ( + meta.new_translation_placeholders + ) + if meta.new_device_class is not None: entity._attr_device_class = meta.new_device_class From 7a339a11b16c63d022c93e98f626c8bc8f5ddf57 Mon Sep 17 00:00:00 2001 From: TheJulianJES Date: Fri, 10 Oct 2025 17:07:39 +0200 Subject: [PATCH 2/2] Remove `hasattr` check for `self. _attr_translation_placeholders` --- zha/application/platforms/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/zha/application/platforms/__init__.py b/zha/application/platforms/__init__.py index 0092f2f8..06d30a23 100644 --- a/zha/application/platforms/__init__.py +++ b/zha/application/platforms/__init__.py @@ -210,9 +210,7 @@ def translation_key(self) -> str | None: @property def translation_placeholders(self) -> dict[str, str] | None: """Return the translation placeholders.""" - if hasattr(self, "_attr_translation_placeholders"): - return self._attr_translation_placeholders - return None + return self._attr_translation_placeholders @property def entity_category(self) -> EntityCategory | None: