mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Avoid working out suggested id in entity_platform when already registered (#144079)
If the entity is already registered, avoid trying to work out the suggested_entity_id and suggested_object_id as async_get_or_create will discard them anyways.
This commit is contained in:
parent
b0f1c71129
commit
9861bd88b9
@ -843,24 +843,31 @@ class EntityPlatform:
|
|||||||
else:
|
else:
|
||||||
device = None
|
device = None
|
||||||
|
|
||||||
# An entity may suggest the entity_id by setting entity_id itself
|
if not registered_entity_id:
|
||||||
suggested_entity_id: str | None = entity.entity_id
|
# Do not bother working out a suggested_object_id
|
||||||
if suggested_entity_id is not None:
|
# if the entity is already registered as it will
|
||||||
suggested_object_id = split_entity_id(entity.entity_id)[1]
|
# be ignored.
|
||||||
else:
|
#
|
||||||
if device and entity.has_entity_name:
|
# An entity may suggest the entity_id by setting entity_id itself
|
||||||
device_name = device.name_by_user or device.name
|
suggested_entity_id: str | None = entity.entity_id
|
||||||
if entity.use_device_name:
|
if suggested_entity_id is not None:
|
||||||
suggested_object_id = device_name
|
suggested_object_id = split_entity_id(entity.entity_id)[1]
|
||||||
else:
|
else:
|
||||||
suggested_object_id = (
|
if device and entity.has_entity_name:
|
||||||
f"{device_name} {entity.suggested_object_id}"
|
device_name = device.name_by_user or device.name
|
||||||
)
|
if entity.use_device_name:
|
||||||
if not suggested_object_id:
|
suggested_object_id = device_name
|
||||||
suggested_object_id = entity.suggested_object_id
|
else:
|
||||||
|
suggested_object_id = (
|
||||||
|
f"{device_name} {entity.suggested_object_id}"
|
||||||
|
)
|
||||||
|
if not suggested_object_id:
|
||||||
|
suggested_object_id = entity.suggested_object_id
|
||||||
|
|
||||||
if self.entity_namespace is not None:
|
if self.entity_namespace is not None:
|
||||||
suggested_object_id = f"{self.entity_namespace} {suggested_object_id}"
|
suggested_object_id = (
|
||||||
|
f"{self.entity_namespace} {suggested_object_id}"
|
||||||
|
)
|
||||||
|
|
||||||
disabled_by: RegistryEntryDisabler | None = None
|
disabled_by: RegistryEntryDisabler | None = None
|
||||||
if not entity.entity_registry_enabled_default:
|
if not entity.entity_registry_enabled_default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user