mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Skip unnecessary checks for entities with unique_id (#125051)
This commit is contained in:
parent
98a86c7636
commit
c175a68a26
@ -584,7 +584,7 @@ class EntityPlatform:
|
||||
"""Add entities for a single platform without updating.
|
||||
|
||||
In this case we are not updating the entities before adding them
|
||||
which means its unlikely that we will not have to yield control
|
||||
which means it is likely that we will not have to yield control
|
||||
to the event loop so we can await the coros directly without
|
||||
scheduling them as tasks.
|
||||
"""
|
||||
@ -728,7 +728,6 @@ class EntityPlatform:
|
||||
return
|
||||
|
||||
suggested_object_id: str | None = None
|
||||
generate_new_entity_id = False
|
||||
|
||||
entity_name = entity.name
|
||||
if entity_name is UNDEFINED:
|
||||
@ -838,33 +837,39 @@ class EntityPlatform:
|
||||
entity.device_entry = device
|
||||
entity.entity_id = entry.entity_id
|
||||
|
||||
# We won't generate an entity ID if the platform has already set one
|
||||
# We will however make sure that platform cannot pick a registered ID
|
||||
elif entity.entity_id is not None and entity_registry.async_is_registered(
|
||||
entity.entity_id
|
||||
):
|
||||
# If entity already registered, convert entity id to suggestion
|
||||
suggested_object_id = split_entity_id(entity.entity_id)[1]
|
||||
generate_new_entity_id = True
|
||||
else: # entity.unique_id is None
|
||||
generate_new_entity_id = False
|
||||
# We won't generate an entity ID if the platform has already set one
|
||||
# We will however make sure that platform cannot pick a registered ID
|
||||
if entity.entity_id is not None and entity_registry.async_is_registered(
|
||||
entity.entity_id
|
||||
):
|
||||
# If entity already registered, convert entity id to suggestion
|
||||
suggested_object_id = split_entity_id(entity.entity_id)[1]
|
||||
generate_new_entity_id = True
|
||||
|
||||
# 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 or DEVICE_DEFAULT_NAME
|
||||
)
|
||||
# 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
|
||||
or DEVICE_DEFAULT_NAME
|
||||
)
|
||||
|
||||
if self.entity_namespace is not None:
|
||||
suggested_object_id = f"{self.entity_namespace} {suggested_object_id}"
|
||||
entity.entity_id = entity_registry.async_generate_entity_id(
|
||||
self.domain, suggested_object_id, self.entities
|
||||
)
|
||||
if self.entity_namespace is not None:
|
||||
suggested_object_id = (
|
||||
f"{self.entity_namespace} {suggested_object_id}"
|
||||
)
|
||||
entity.entity_id = entity_registry.async_generate_entity_id(
|
||||
self.domain, suggested_object_id, self.entities
|
||||
)
|
||||
|
||||
# Make sure it is valid in case an entity set the value themselves
|
||||
# Avoid calling valid_entity_id if we already know it is valid
|
||||
# since it already made it in the registry
|
||||
if not entity.registry_entry and not valid_entity_id(entity.entity_id):
|
||||
entity.add_to_platform_abort()
|
||||
raise HomeAssistantError(f"Invalid entity ID: {entity.entity_id}")
|
||||
# Make sure it is valid in case an entity set the value themselves
|
||||
# Avoid calling valid_entity_id if we already know it is valid
|
||||
# since it already made it in the registry
|
||||
if not valid_entity_id(entity.entity_id):
|
||||
entity.add_to_platform_abort()
|
||||
raise HomeAssistantError(f"Invalid entity ID: {entity.entity_id}")
|
||||
|
||||
already_exists, restored = self._entity_id_already_exists(entity.entity_id)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user