From 75be1b4ff9265042f79dc5bd67e7718d260fc090 Mon Sep 17 00:00:00 2001 From: Arturo Date: Wed, 26 Apr 2023 13:44:40 -0600 Subject: [PATCH] Remove bridged matter devices when matter bridge is removed (#91995) * Removes bridged matter devices when matter bridge is removed * Didn't have the fetch the config entry since that is already provided to us * Switched to a safer method of removing the child devices --- homeassistant/components/matter/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/homeassistant/components/matter/__init__.py b/homeassistant/components/matter/__init__.py index e86e5c0ca49..4c47cd4d235 100644 --- a/homeassistant/components/matter/__init__.py +++ b/homeassistant/components/matter/__init__.py @@ -195,6 +195,17 @@ async def async_remove_config_entry_device( if node is None: return True + if node.is_bridge_device: + device_registry = dr.async_get(hass) + devices = dr.async_entries_for_config_entry( + device_registry, config_entry.entry_id + ) + for device in devices: + if device.via_device_id == device_entry.id: + device_registry.async_update_device( + device.id, remove_config_entry_id=config_entry.entry_id + ) + matter = get_matter(hass) await matter.matter_client.remove_node(node.node_id)