1
mirror of https://github.com/home-assistant/core synced 2024-07-18 12:02:20 +02:00

Avoid calling valid_entity_id when adding entities if they are already registered (#115388)

This commit is contained in:
J. Nick Koston 2024-04-10 15:18:47 -10:00 committed by GitHub
parent 288f3d84ba
commit 6bd6adc4f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -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}")

View File

@ -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: