mirror of
https://github.com/elisspace/core.git
synced 2026-08-29 15:43:55 +00:00
Fix logic
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user