diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 924d53c31c..4d9ed12f53 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -324,22 +324,26 @@ class Entity(ABC): return False @property - def suggested_object_id_input(self) -> str | None: + def suggested_object_id(self) -> str | None: """Return input for object id.""" - if hasattr(self, "_attr_name"): - return self._attr_name - if self.translation_key is not None and self.has_entity_name: - assert self.platform - name_translation_key = ( - f"component.{self.platform.platform_name}.entity.{self.platform.domain}" - f".{self.translation_key}.name" - ) - if name_translation_key in self.platform.object_id_entity_translations: - name: str = self.platform.object_id_entity_translations[ - name_translation_key - ] - return name - return self.name + if ( + hasattr(self, "_attr_name") + or self.translation_key is None + or not self.has_entity_name + ): + # Return self.name also if self._attr_name is set, because some integrations + # use self.name for other purposes than the entity name + return self.name + + assert self.platform + name_translation_key = ( + f"component.{self.platform.platform_name}.entity.{self.platform.domain}" + f".{self.translation_key}.name" + ) + if name_translation_key not in self.platform.object_id_entity_translations: + return self.name + name: str = self.platform.object_id_entity_translations[name_translation_key] + return name @property def name(self) -> str | None: diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index 9de88d8359..8d14e4edcf 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -662,10 +662,10 @@ class EntityPlatform: suggested_object_id = device_name else: suggested_object_id = ( - f"{device_name} {entity.suggested_object_id_input}" + f"{device_name} {entity.suggested_object_id}" ) if not suggested_object_id: - suggested_object_id = entity.suggested_object_id_input + suggested_object_id = entity.suggested_object_id if self.entity_namespace is not None: suggested_object_id = f"{self.entity_namespace} {suggested_object_id}" @@ -720,9 +720,7 @@ class EntityPlatform: # Generate entity ID if entity.entity_id is None or generate_new_entity_id: suggested_object_id = ( - suggested_object_id - or entity.suggested_object_id_input - or DEVICE_DEFAULT_NAME + suggested_object_id or entity.suggested_object_id or DEVICE_DEFAULT_NAME ) if self.entity_namespace is not None: