Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions zha/application/platforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Comment on lines +213 to +214
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attribute should always be present, though we also check this for translation_key and _attr_entity_category. I think the hasattr check can be removed for all off them. Not sure why it's there in the first place. But we can also clean up the other attributes in another PR.

return None

@property
def entity_category(self) -> EntityCategory | None:
"""Return the entity category."""
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions zha/zigbee/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading