Skip unnecessary checks for entities with unique_id (#125051)

This commit is contained in:
Artur Pragacz 2024-10-01 18:27:14 +02:00 committed by GitHub
parent 98a86c7636
commit c175a68a26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,9 +837,11 @@ class EntityPlatform:
entity.device_entry = device
entity.entity_id = entry.entity_id
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
elif entity.entity_id is not None and entity_registry.async_is_registered(
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
@ -850,11 +851,15 @@ 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 or DEVICE_DEFAULT_NAME
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}"
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
)
@ -862,7 +867,7 @@ class EntityPlatform:
# 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):
if not valid_entity_id(entity.entity_id):
entity.add_to_platform_abort()
raise HomeAssistantError(f"Invalid entity ID: {entity.entity_id}")