1
mirror of https://github.com/home-assistant/core synced 2024-07-30 21:18:57 +02:00

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:
Erik Montnemery 2021-11-23 09:36:03 +01:00 committed by GitHub
parent 8ece8d124d
commit ca20fc857f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -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}
)

View File

@ -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."""