Guard bad entity ID in entity registry (#35271)

This commit is contained in:
Paulus Schoutsen 2020-05-05 15:07:54 -07:00 committed by GitHub
parent 87d58a544b
commit a330eba61c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -428,6 +428,12 @@ class EntityRegistry:
if data is not None:
for entity in data["entities"]:
# Some old installations can have some bad entities.
# Filter them out as they cause errors down the line.
# Can be removed in Jan 2021
if not valid_entity_id(entity["entity_id"]):
continue
entities[entity["entity_id"]] = RegistryEntry(
entity_id=entity["entity_id"],
config_entry_id=entity.get("config_entry_id"),

View File

@ -241,12 +241,20 @@ async def test_loading_extra_values(hass, hass_storage):
"unique_id": "disabled-hass",
"disabled_by": "hass",
},
{
"entity_id": "test.invalid__entity",
"platform": "super_platform",
"unique_id": "invalid-hass",
"disabled_by": "hass",
},
]
},
}
registry = await entity_registry.async_get_registry(hass)
assert len(registry.entities) == 4
entry_with_name = registry.async_get_or_create(
"test", "super_platform", "with-name"
)