mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Remigrate device_registry created_at/modified_at (#122490)
* Remigrate device_registry created_at/modified_at Nightly current does not boot up because the device registry will have KeyError: created_at if the previous nightly was installed. * reduce * split migration per discord comments
This commit is contained in:
@@ -993,12 +993,12 @@ async def test_migration_1_5_to_1_7(
|
||||
|
||||
@pytest.mark.parametrize("load_registries", [False])
|
||||
@pytest.mark.usefixtures("freezer")
|
||||
async def test_migration_1_6_to_1_7(
|
||||
async def test_migration_1_6_to_1_8(
|
||||
hass: HomeAssistant,
|
||||
hass_storage: dict[str, Any],
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test migration from version 1.6 to 1.7."""
|
||||
"""Test migration from version 1.6 to 1.8."""
|
||||
hass_storage[dr.STORAGE_KEY] = {
|
||||
"version": 1,
|
||||
"minor_version": 6,
|
||||
@@ -1131,6 +1131,148 @@ async def test_migration_1_6_to_1_7(
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("load_registries", [False])
|
||||
@pytest.mark.usefixtures("freezer")
|
||||
async def test_migration_1_7_to_1_8(
|
||||
hass: HomeAssistant,
|
||||
hass_storage: dict[str, Any],
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test migration from version 1.7 to 1.8."""
|
||||
hass_storage[dr.STORAGE_KEY] = {
|
||||
"version": 1,
|
||||
"minor_version": 7,
|
||||
"key": dr.STORAGE_KEY,
|
||||
"data": {
|
||||
"devices": [
|
||||
{
|
||||
"area_id": None,
|
||||
"config_entries": [mock_config_entry.entry_id],
|
||||
"configuration_url": None,
|
||||
"connections": [["Zigbee", "01.23.45.67.89"]],
|
||||
"disabled_by": None,
|
||||
"entry_type": "service",
|
||||
"hw_version": "hw_version",
|
||||
"id": "abcdefghijklm",
|
||||
"identifiers": [["serial", "123456ABCDEF"]],
|
||||
"labels": ["blah"],
|
||||
"manufacturer": "manufacturer",
|
||||
"model": "model",
|
||||
"model_id": None,
|
||||
"name": "name",
|
||||
"name_by_user": None,
|
||||
"primary_config_entry": mock_config_entry.entry_id,
|
||||
"serial_number": 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,
|
||||
"hw_version": None,
|
||||
"id": "invalid-entry-type",
|
||||
"identifiers": [["serial", "mock-id-invalid-entry"]],
|
||||
"labels": ["blah"],
|
||||
"manufacturer": None,
|
||||
"model": None,
|
||||
"model_id": None,
|
||||
"name_by_user": None,
|
||||
"primary_config_entry": None,
|
||||
"name": None,
|
||||
"serial_number": None,
|
||||
"sw_version": None,
|
||||
"via_device_id": None,
|
||||
},
|
||||
],
|
||||
"deleted_devices": [],
|
||||
},
|
||||
}
|
||||
|
||||
await dr.async_load(hass)
|
||||
registry = dr.async_get(hass)
|
||||
|
||||
# Test data was loaded
|
||||
entry = registry.async_get_or_create(
|
||||
config_entry_id=mock_config_entry.entry_id,
|
||||
connections={("Zigbee", "01.23.45.67.89")},
|
||||
identifiers={("serial", "123456ABCDEF")},
|
||||
)
|
||||
assert entry.id == "abcdefghijklm"
|
||||
|
||||
# Update to trigger a store
|
||||
entry = registry.async_get_or_create(
|
||||
config_entry_id=mock_config_entry.entry_id,
|
||||
connections={("Zigbee", "01.23.45.67.89")},
|
||||
identifiers={("serial", "123456ABCDEF")},
|
||||
sw_version="new_version",
|
||||
)
|
||||
assert entry.id == "abcdefghijklm"
|
||||
|
||||
# Check we store migrated data
|
||||
await flush_store(registry._store)
|
||||
|
||||
assert hass_storage[dr.STORAGE_KEY] == {
|
||||
"version": dr.STORAGE_VERSION_MAJOR,
|
||||
"minor_version": dr.STORAGE_VERSION_MINOR,
|
||||
"key": dr.STORAGE_KEY,
|
||||
"data": {
|
||||
"devices": [
|
||||
{
|
||||
"area_id": None,
|
||||
"config_entries": [mock_config_entry.entry_id],
|
||||
"configuration_url": None,
|
||||
"connections": [["Zigbee", "01.23.45.67.89"]],
|
||||
"created_at": "1970-01-01T00:00:00+00:00",
|
||||
"disabled_by": None,
|
||||
"entry_type": "service",
|
||||
"hw_version": "hw_version",
|
||||
"id": "abcdefghijklm",
|
||||
"identifiers": [["serial", "123456ABCDEF"]],
|
||||
"labels": ["blah"],
|
||||
"manufacturer": "manufacturer",
|
||||
"model": "model",
|
||||
"name": "name",
|
||||
"model_id": None,
|
||||
"modified_at": "1970-01-01T00:00:00+00:00",
|
||||
"name_by_user": None,
|
||||
"primary_config_entry": mock_config_entry.entry_id,
|
||||
"serial_number": None,
|
||||
"sw_version": "new_version",
|
||||
"via_device_id": None,
|
||||
},
|
||||
{
|
||||
"area_id": None,
|
||||
"config_entries": [None],
|
||||
"configuration_url": None,
|
||||
"connections": [],
|
||||
"created_at": "1970-01-01T00:00:00+00:00",
|
||||
"disabled_by": None,
|
||||
"entry_type": None,
|
||||
"hw_version": None,
|
||||
"id": "invalid-entry-type",
|
||||
"identifiers": [["serial", "mock-id-invalid-entry"]],
|
||||
"labels": ["blah"],
|
||||
"manufacturer": None,
|
||||
"model": None,
|
||||
"model_id": None,
|
||||
"modified_at": "1970-01-01T00:00:00+00:00",
|
||||
"name_by_user": None,
|
||||
"name": None,
|
||||
"primary_config_entry": None,
|
||||
"serial_number": None,
|
||||
"sw_version": None,
|
||||
"via_device_id": None,
|
||||
},
|
||||
],
|
||||
"deleted_devices": [],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
async def test_removing_config_entries(
|
||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user