Area registry (#20435)
* First draft of area registry * Refactor based on input * Add tests for areas Add tests for updating device * Updating a device shouldn't require area * Fix Martins comment * Require admin * Save after deleting * Rename read to list_areas Fix device entry_dict Remove area id from device when deleting area * Fix tests
This commit is contained in:
parent
2c7060896b
commit
bd335e1ac1
9 changed files with 714 additions and 35 deletions
|
@ -133,6 +133,7 @@ async def test_loading_from_storage(hass, hass_storage):
|
|||
'model': 'model',
|
||||
'name': 'name',
|
||||
'sw_version': 'version',
|
||||
'area_id': '12345A'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -146,6 +147,7 @@ async def test_loading_from_storage(hass, hass_storage):
|
|||
identifiers={('serial', '12:34:56:AB:CD:EF')},
|
||||
manufacturer='manufacturer', model='model')
|
||||
assert entry.id == 'abcdefghijklm'
|
||||
assert entry.area_id == '12345A'
|
||||
assert isinstance(entry.config_entries, set)
|
||||
|
||||
|
||||
|
@ -186,6 +188,25 @@ async def test_removing_config_entries(registry):
|
|||
assert entry3.config_entries == set()
|
||||
|
||||
|
||||
async def test_removing_area_id(registry):
|
||||
"""Make sure we can clear area id."""
|
||||
entry = registry.async_get_or_create(
|
||||
config_entry_id='123',
|
||||
connections={
|
||||
(device_registry.CONNECTION_NETWORK_MAC, '12:34:56:AB:CD:EF')
|
||||
},
|
||||
identifiers={('bridgeid', '0123')},
|
||||
manufacturer='manufacturer', model='model')
|
||||
|
||||
entry_w_area = registry.async_update_device(entry.id, area_id='12345A')
|
||||
|
||||
registry.async_clear_area_id('12345A')
|
||||
entry_wo_area = registry.async_get_device({('bridgeid', '0123')}, set())
|
||||
|
||||
assert not entry_wo_area.area_id
|
||||
assert entry_w_area != entry_wo_area
|
||||
|
||||
|
||||
async def test_specifying_hub_device_create(registry):
|
||||
"""Test specifying a hub and updating."""
|
||||
hub = registry.async_get_or_create(
|
||||
|
@ -328,3 +349,19 @@ async def test_format_mac(registry):
|
|||
},
|
||||
)
|
||||
assert list(invalid_mac_entry.connections)[0][1] == invalid
|
||||
|
||||
|
||||
async def test_update(registry):
|
||||
"""Verify that we can update area_id of a device."""
|
||||
entry = registry.async_get_or_create(
|
||||
config_entry_id='1234',
|
||||
connections={
|
||||
(device_registry.CONNECTION_NETWORK_MAC, '12:34:56:AB:CD:EF')
|
||||
})
|
||||
|
||||
assert not entry.area_id
|
||||
|
||||
updated_entry = registry.async_update_device(entry.id, area_id='12345A')
|
||||
|
||||
assert updated_entry != entry
|
||||
assert updated_entry.area_id == '12345A'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue