mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +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.
|
"""Add entities for a single platform without updating.
|
||||||
|
|
||||||
In this case we are not updating the entities before adding them
|
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
|
to the event loop so we can await the coros directly without
|
||||||
scheduling them as tasks.
|
scheduling them as tasks.
|
||||||
"""
|
"""
|
||||||
@ -728,7 +728,6 @@ class EntityPlatform:
|
|||||||
return
|
return
|
||||||
|
|
||||||
suggested_object_id: str | None = None
|
suggested_object_id: str | None = None
|
||||||
generate_new_entity_id = False
|
|
||||||
|
|
||||||
entity_name = entity.name
|
entity_name = entity.name
|
||||||
if entity_name is UNDEFINED:
|
if entity_name is UNDEFINED:
|
||||||
@ -838,9 +837,11 @@ class EntityPlatform:
|
|||||||
entity.device_entry = device
|
entity.device_entry = device
|
||||||
entity.entity_id = entry.entity_id
|
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 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
|
# 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
|
entity.entity_id
|
||||||
):
|
):
|
||||||
# If entity already registered, convert entity id to suggestion
|
# If entity already registered, convert entity id to suggestion
|
||||||
@ -850,11 +851,15 @@ class EntityPlatform:
|
|||||||
# Generate entity ID
|
# Generate entity ID
|
||||||
if entity.entity_id is None or generate_new_entity_id:
|
if entity.entity_id is None or generate_new_entity_id:
|
||||||
suggested_object_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:
|
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(
|
entity.entity_id = entity_registry.async_generate_entity_id(
|
||||||
self.domain, suggested_object_id, self.entities
|
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
|
# 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
|
# Avoid calling valid_entity_id if we already know it is valid
|
||||||
# since it already made it in the registry
|
# 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()
|
entity.add_to_platform_abort()
|
||||||
raise HomeAssistantError(f"Invalid entity ID: {entity.entity_id}")
|
raise HomeAssistantError(f"Invalid entity ID: {entity.entity_id}")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user