mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Avoid calling valid_entity_id when adding entities if they are already registered (#115388)
This commit is contained in:
parent
288f3d84ba
commit
6bd6adc4f5
@ -843,7 +843,9 @@ 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
|
||||||
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()
|
entity.add_to_platform_abort()
|
||||||
raise HomeAssistantError(f"Invalid entity ID: {entity.entity_id}")
|
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
|
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(
|
async def test_device_info_called(
|
||||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry
|
hass: HomeAssistant, device_registry: dr.DeviceRegistry
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user