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

Handle invalid device registry entry type (#60966)

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Paulus Schoutsen 2021-12-04 00:20:12 -08:00 committed by GitHub
parent 2fe48702f3
commit a59ec9ca5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 3 deletions

View File

@ -172,7 +172,11 @@ class DeviceRegistryStore(storage.Store):
# From version 1.1
for device in old_data["devices"]:
# Introduced in 0.110
device["entry_type"] = device.get("entry_type")
try:
device["entry_type"] = DeviceEntryType(device.get("entry_type"))
except ValueError:
device["entry_type"] = None
# Introduced in 0.79
# renamed in 0.95
device["via_device_id"] = device.get("via_device_id") or device.get(

View File

@ -252,7 +252,19 @@ async def test_migration_1_1_to_1_2(hass, hass_storage):
"model": "model",
"name": "name",
"sw_version": "version",
}
},
# Invalid entry type
{
"config_entries": [None],
"connections": [],
"entry_type": "INVALID_VALUE",
"id": "invalid-entry-type",
"identifiers": [["serial", "mock-id-invalid-entry"]],
"manufacturer": None,
"model": None,
"name": None,
"sw_version": None,
},
],
},
}
@ -300,7 +312,23 @@ async def test_migration_1_1_to_1_2(hass, hass_storage):
"name_by_user": None,
"sw_version": "new_version",
"via_device_id": None,
}
},
{
"area_id": None,
"config_entries": [None],
"configuration_url": None,
"connections": [],
"disabled_by": None,
"entry_type": None,
"id": "invalid-entry-type",
"identifiers": [["serial", "mock-id-invalid-entry"]],
"manufacturer": None,
"model": None,
"name_by_user": None,
"name": None,
"sw_version": None,
"via_device_id": None,
},
],
"deleted_devices": [],
},