@@ -1432,6 +1432,141 @@ async def test_migration_from_1_7(
1432
1432
}
1433
1433
1434
1434
1435
+ @pytest .mark .parametrize ("load_registries" , [False ])
1436
+ @pytest .mark .usefixtures ("freezer" )
1437
+ async def test_migration_from_1_10 (
1438
+ hass : HomeAssistant ,
1439
+ hass_storage : dict [str , Any ],
1440
+ mock_config_entry : MockConfigEntry ,
1441
+ ) -> None :
1442
+ """Test migration from version 1.10."""
1443
+ hass_storage [dr .STORAGE_KEY ] = {
1444
+ "version" : 1 ,
1445
+ "minor_version" : 10 ,
1446
+ "key" : dr .STORAGE_KEY ,
1447
+ "data" : {
1448
+ "devices" : [
1449
+ {
1450
+ "area_id" : None ,
1451
+ "config_entries" : [mock_config_entry .entry_id ],
1452
+ "config_entries_subentries" : {mock_config_entry .entry_id : [None ]},
1453
+ "configuration_url" : None ,
1454
+ "connections" : [["mac" , "123456ABCDEF" ]],
1455
+ "created_at" : "1970-01-01T00:00:00+00:00" ,
1456
+ "disabled_by" : None ,
1457
+ "entry_type" : "service" ,
1458
+ "hw_version" : "hw_version" ,
1459
+ "id" : "abcdefghijklm" ,
1460
+ "identifiers" : [["serial" , "123456ABCDEF" ]],
1461
+ "labels" : ["blah" ],
1462
+ "manufacturer" : "manufacturer" ,
1463
+ "model" : "model" ,
1464
+ "name" : "name" ,
1465
+ "model_id" : None ,
1466
+ "modified_at" : "1970-01-01T00:00:00+00:00" ,
1467
+ "name_by_user" : None ,
1468
+ "primary_config_entry" : mock_config_entry .entry_id ,
1469
+ "serial_number" : None ,
1470
+ "sw_version" : "new_version" ,
1471
+ "via_device_id" : None ,
1472
+ },
1473
+ ],
1474
+ "deleted_devices" : [
1475
+ {
1476
+ "area_id" : None ,
1477
+ "config_entries" : ["234567" ],
1478
+ "config_entries_subentries" : {"234567" : [None ]},
1479
+ "connections" : [["mac" , "123456ABCDAB" ]],
1480
+ "created_at" : "1970-01-01T00:00:00+00:00" ,
1481
+ "disabled_by" : None ,
1482
+ "id" : "abcdefghijklm2" ,
1483
+ "identifiers" : [["serial" , "123456ABCDAB" ]],
1484
+ "labels" : [],
1485
+ "modified_at" : "1970-01-01T00:00:00+00:00" ,
1486
+ "name_by_user" : None ,
1487
+ "orphaned_timestamp" : "1970-01-01T00:00:00+00:00" ,
1488
+ },
1489
+ ],
1490
+ },
1491
+ }
1492
+
1493
+ await dr .async_load (hass )
1494
+ registry = dr .async_get (hass )
1495
+
1496
+ # Test data was loaded
1497
+ entry = registry .async_get_or_create (
1498
+ config_entry_id = mock_config_entry .entry_id ,
1499
+ identifiers = {("serial" , "123456ABCDEF" )},
1500
+ )
1501
+ assert entry .id == "abcdefghijklm"
1502
+ deleted_entry = registry .deleted_devices .get_entry (
1503
+ connections = set (),
1504
+ identifiers = {("serial" , "123456ABCDAB" )},
1505
+ )
1506
+ assert deleted_entry .id == "abcdefghijklm2"
1507
+
1508
+ # Update to trigger a store
1509
+ entry = registry .async_get_or_create (
1510
+ config_entry_id = mock_config_entry .entry_id ,
1511
+ identifiers = {("serial" , "123456ABCDEF" )},
1512
+ sw_version = "new_version" ,
1513
+ )
1514
+ assert entry .id == "abcdefghijklm"
1515
+
1516
+ # Check we store migrated data
1517
+ await flush_store (registry ._store )
1518
+
1519
+ assert hass_storage [dr .STORAGE_KEY ] == {
1520
+ "version" : dr .STORAGE_VERSION_MAJOR ,
1521
+ "minor_version" : dr .STORAGE_VERSION_MINOR ,
1522
+ "key" : dr .STORAGE_KEY ,
1523
+ "data" : {
1524
+ "devices" : [
1525
+ {
1526
+ "area_id" : None ,
1527
+ "config_entries" : [mock_config_entry .entry_id ],
1528
+ "config_entries_subentries" : {mock_config_entry .entry_id : [None ]},
1529
+ "configuration_url" : None ,
1530
+ "connections" : [["mac" , "12:34:56:ab:cd:ef" ]],
1531
+ "created_at" : "1970-01-01T00:00:00+00:00" ,
1532
+ "disabled_by" : None ,
1533
+ "entry_type" : "service" ,
1534
+ "hw_version" : "hw_version" ,
1535
+ "id" : "abcdefghijklm" ,
1536
+ "identifiers" : [["serial" , "123456ABCDEF" ]],
1537
+ "labels" : ["blah" ],
1538
+ "manufacturer" : "manufacturer" ,
1539
+ "model" : "model" ,
1540
+ "name" : "name" ,
1541
+ "model_id" : None ,
1542
+ "modified_at" : "1970-01-01T00:00:00+00:00" ,
1543
+ "name_by_user" : None ,
1544
+ "primary_config_entry" : mock_config_entry .entry_id ,
1545
+ "serial_number" : None ,
1546
+ "sw_version" : "new_version" ,
1547
+ "via_device_id" : None ,
1548
+ },
1549
+ ],
1550
+ "deleted_devices" : [
1551
+ {
1552
+ "area_id" : None ,
1553
+ "config_entries" : ["234567" ],
1554
+ "config_entries_subentries" : {"234567" : [None ]},
1555
+ "connections" : [["mac" , "12:34:56:ab:cd:ab" ]],
1556
+ "created_at" : "1970-01-01T00:00:00+00:00" ,
1557
+ "disabled_by" : None ,
1558
+ "id" : "abcdefghijklm2" ,
1559
+ "identifiers" : [["serial" , "123456ABCDAB" ]],
1560
+ "labels" : [],
1561
+ "modified_at" : "1970-01-01T00:00:00+00:00" ,
1562
+ "name_by_user" : None ,
1563
+ "orphaned_timestamp" : "1970-01-01T00:00:00+00:00" ,
1564
+ },
1565
+ ],
1566
+ },
1567
+ }
1568
+
1569
+
1435
1570
async def test_removing_config_entries (
1436
1571
hass : HomeAssistant , device_registry : dr .DeviceRegistry
1437
1572
) -> None :
@@ -4753,3 +4888,9 @@ async def test_update_device_no_connections_or_identifiers(
4753
4888
device_registry .async_update_device (
4754
4889
device .id , new_connections = set (), new_identifiers = set ()
4755
4890
)
4891
+
4892
+
4893
+ async def test_connections_validator () -> None :
4894
+ """Test checking connections validator."""
4895
+ with pytest .raises (ValueError , match = "Invalid mac address format" ):
4896
+ dr .DeviceEntry (connections = {(dr .CONNECTION_NETWORK_MAC , "123456ABCDEF" )})
0 commit comments