Remove via_device links when a device is removed (#60153)
* Remove via_device links when a device is removed * Update test
This commit is contained in:
parent
8ece8d124d
commit
ca20fc857f
2 changed files with 8 additions and 1 deletions
|
@ -501,6 +501,9 @@ class DeviceRegistry:
|
|||
orphaned_timestamp=None,
|
||||
)
|
||||
)
|
||||
for other_device in list(self.devices.values()):
|
||||
if other_device.via_device_id == device_id:
|
||||
self._async_update_device(other_device.id, via_device_id=None)
|
||||
self.hass.bus.async_fire(
|
||||
EVENT_DEVICE_REGISTRY_UPDATED, {"action": "remove", "device_id": device_id}
|
||||
)
|
||||
|
|
|
@ -420,7 +420,7 @@ async def test_deleted_device_removing_area_id(registry):
|
|||
|
||||
|
||||
async def test_specifying_via_device_create(registry):
|
||||
"""Test specifying a via_device and updating."""
|
||||
"""Test specifying a via_device and removal of the hub device."""
|
||||
via = registry.async_get_or_create(
|
||||
config_entry_id="123",
|
||||
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||
|
@ -440,6 +440,10 @@ async def test_specifying_via_device_create(registry):
|
|||
|
||||
assert light.via_device_id == via.id
|
||||
|
||||
registry.async_remove_device(via.id)
|
||||
light = registry.async_get_device({("hue", "456")})
|
||||
assert light.via_device_id is None
|
||||
|
||||
|
||||
async def test_specifying_via_device_update(registry):
|
||||
"""Test specifying a via_device and updating."""
|
||||
|
|
Loading…
Add table
Reference in a new issue