diff --git a/homeassistant/helpers/device_registry.py b/homeassistant/helpers/device_registry.py index c8ae7fd148c..e31b77d3ae2 100644 --- a/homeassistant/helpers/device_registry.py +++ b/homeassistant/helpers/device_registry.py @@ -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( diff --git a/tests/helpers/test_device_registry.py b/tests/helpers/test_device_registry.py index a689cc9ac3d..455c90b8f65 100644 --- a/tests/helpers/test_device_registry.py +++ b/tests/helpers/test_device_registry.py @@ -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": [], },