From 38cee5399918f3da8356dffc4111552365a9ae4a Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk <11290930+bouwew@users.noreply.github.com> Date: Fri, 16 May 2025 13:28:31 +0200 Subject: [PATCH] Small code optimization for Plugwise (#145037) --- homeassistant/components/plugwise/coordinator.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/plugwise/coordinator.py b/homeassistant/components/plugwise/coordinator.py index b346f26492c..4ed100b538d 100644 --- a/homeassistant/components/plugwise/coordinator.py +++ b/homeassistant/components/plugwise/coordinator.py @@ -99,12 +99,10 @@ class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[dict[str, GwEntityData translation_key="unsupported_firmware", ) from err - self._async_add_remove_devices(data, self.config_entry) + self._async_add_remove_devices(data) return data - def _async_add_remove_devices( - self, data: dict[str, GwEntityData], entry: ConfigEntry - ) -> None: + def _async_add_remove_devices(self, data: dict[str, GwEntityData]) -> None: """Add new Plugwise devices, remove non-existing devices.""" # Check for new or removed devices self.new_devices = set(data) - self._current_devices @@ -112,11 +110,9 @@ class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[dict[str, GwEntityData self._current_devices = set(data) if removed_devices: - self._async_remove_devices(data, entry) + self._async_remove_devices(data) - def _async_remove_devices( - self, data: dict[str, GwEntityData], entry: ConfigEntry - ) -> None: + def _async_remove_devices(self, data: dict[str, GwEntityData]) -> None: """Clean registries when removed devices found.""" device_reg = dr.async_get(self.hass) device_list = dr.async_entries_for_config_entry( @@ -136,7 +132,8 @@ class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[dict[str, GwEntityData and identifier[1] not in data ): device_reg.async_update_device( - device_entry.id, remove_config_entry_id=entry.entry_id + device_entry.id, + remove_config_entry_id=self.config_entry.entry_id, ) LOGGER.debug( "Removed %s device %s %s from device_registry",