Avoid calling valid_entity_id when adding entities if they are already registered (#115388)
parent
288f3d84ba
commit
6bd6adc4f5
|
@ -843,7 +843,9 @@ class EntityPlatform:
|
|||
)
|
||||
|
||||
# Make sure it is valid in case an entity set the value themselves
|
||||
if not valid_entity_id(entity.entity_id):
|
||||
# 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}")
|
||||
|
||||
|
|
|
@ -1112,6 +1112,19 @@ async def test_entity_registry_updates_invalid_entity_id(hass: HomeAssistant) ->
|
|||
assert hass.states.get("diff_domain.world") is None
|
||||
|
||||
|
||||
async def test_add_entity_with_invalid_id(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test trying to add an entity with an invalid entity_id."""
|
||||
platform = MockEntityPlatform(hass)
|
||||
entity = MockEntity(entity_id="i.n.v.a.l.i.d")
|
||||
await platform.async_add_entities([entity])
|
||||
assert (
|
||||
"Error adding entity i.n.v.a.l.i.d for domain "
|
||||
"test_domain with platform test_platform" in caplog.text
|
||||
)
|
||||
|
||||
|
||||
async def test_device_info_called(
|
||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry
|
||||
) -> None:
|
||||
|
|
Loading…
Reference in New Issue