mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Allow updating of via_device in device registry (#24921)
* Allow updating of via_device in device registry * Added test
This commit is contained in:
parent
3c487928d4
commit
a491f97eb9
@ -138,12 +138,12 @@ class DeviceRegistry:
|
|||||||
def async_update_device(
|
def async_update_device(
|
||||||
self, device_id, *, area_id=_UNDEF,
|
self, device_id, *, area_id=_UNDEF,
|
||||||
name=_UNDEF, name_by_user=_UNDEF,
|
name=_UNDEF, name_by_user=_UNDEF,
|
||||||
new_identifiers=_UNDEF):
|
new_identifiers=_UNDEF, via_device_id=_UNDEF):
|
||||||
"""Update properties of a device."""
|
"""Update properties of a device."""
|
||||||
return self._async_update_device(
|
return self._async_update_device(
|
||||||
device_id, area_id=area_id,
|
device_id, area_id=area_id,
|
||||||
name=name, name_by_user=name_by_user,
|
name=name, name_by_user=name_by_user,
|
||||||
new_identifiers=new_identifiers)
|
new_identifiers=new_identifiers, via_device_id=via_device_id)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_update_device(self, device_id, *, add_config_entry_id=_UNDEF,
|
def _async_update_device(self, device_id, *, add_config_entry_id=_UNDEF,
|
||||||
|
@ -395,7 +395,7 @@ async def test_format_mac(registry):
|
|||||||
|
|
||||||
|
|
||||||
async def test_update(registry):
|
async def test_update(registry):
|
||||||
"""Verify that we can update area_id of a device."""
|
"""Verify that we can update some attributes of a device."""
|
||||||
entry = registry.async_get_or_create(
|
entry = registry.async_get_or_create(
|
||||||
config_entry_id='1234',
|
config_entry_id='1234',
|
||||||
connections={
|
connections={
|
||||||
@ -412,13 +412,14 @@ async def test_update(registry):
|
|||||||
with patch.object(registry, 'async_schedule_save') as mock_save:
|
with patch.object(registry, 'async_schedule_save') as mock_save:
|
||||||
updated_entry = registry.async_update_device(
|
updated_entry = registry.async_update_device(
|
||||||
entry.id, area_id='12345A', name_by_user='Test Friendly Name',
|
entry.id, area_id='12345A', name_by_user='Test Friendly Name',
|
||||||
new_identifiers=new_identifiers)
|
new_identifiers=new_identifiers, via_device_id='98765B')
|
||||||
|
|
||||||
assert mock_save.call_count == 1
|
assert mock_save.call_count == 1
|
||||||
assert updated_entry != entry
|
assert updated_entry != entry
|
||||||
assert updated_entry.area_id == '12345A'
|
assert updated_entry.area_id == '12345A'
|
||||||
assert updated_entry.name_by_user == 'Test Friendly Name'
|
assert updated_entry.name_by_user == 'Test Friendly Name'
|
||||||
assert updated_entry.identifiers == new_identifiers
|
assert updated_entry.identifiers == new_identifiers
|
||||||
|
assert updated_entry.via_device_id == '98765B'
|
||||||
|
|
||||||
|
|
||||||
async def test_loading_race_condition(hass):
|
async def test_loading_race_condition(hass):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user