From 257742de46d586e89ffeb6849e4d29126ec59bf4 Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Sat, 10 Aug 2024 18:01:15 +0200 Subject: [PATCH] Fix cleanup of old orphan device entries in AVM Fritz!Tools (#123516) fix cleanup of old orphan device entries --- homeassistant/components/fritz/coordinator.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/fritz/coordinator.py b/homeassistant/components/fritz/coordinator.py index a67f385f3e8..13c442a1ace 100644 --- a/homeassistant/components/fritz/coordinator.py +++ b/homeassistant/components/fritz/coordinator.py @@ -652,8 +652,6 @@ class FritzBoxTools(DataUpdateCoordinator[UpdateCoordinatorDataType]): entities: list[er.RegistryEntry] = er.async_entries_for_config_entry( entity_reg, config_entry.entry_id ) - - orphan_macs: set[str] = set() for entity in entities: entry_mac = entity.unique_id.split("_")[0] if ( @@ -661,17 +659,16 @@ class FritzBoxTools(DataUpdateCoordinator[UpdateCoordinatorDataType]): or "_internet_access" in entity.unique_id ) and entry_mac not in device_hosts: _LOGGER.info("Removing orphan entity entry %s", entity.entity_id) - orphan_macs.add(entry_mac) entity_reg.async_remove(entity.entity_id) device_reg = dr.async_get(self.hass) - orphan_connections = { - (CONNECTION_NETWORK_MAC, dr.format_mac(mac)) for mac in orphan_macs + valid_connections = { + (CONNECTION_NETWORK_MAC, dr.format_mac(mac)) for mac in device_hosts } for device in dr.async_entries_for_config_entry( device_reg, config_entry.entry_id ): - if any(con in device.connections for con in orphan_connections): + if not any(con in device.connections for con in valid_connections): _LOGGER.debug("Removing obsolete device entry %s", device.name) device_reg.async_update_device( device.id, remove_config_entry_id=config_entry.entry_id