Skip to content

Commit 46aa590

Browse files
committed
Improve
1 parent 5ca26a9 commit 46aa590

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

custom_components/plugwise/coordinator.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,22 @@ async def _async_add_remove_devices(self, data: dict[str, GwEntityData]) -> None
137137
self._current_devices = dr.async_entries_for_config_entry(
138138
self.device_registry, self.config_entry.entry_id
139139
)
140-
self.new_devices = list(set(data) - set(self._current_devices))
141-
removed_devices = list(set(self._current_devices) - set(data))
140+
current_device_ids = {
141+
identifier[1]
142+
for device_entry in self._current_devices
143+
for identifier in device_entry.identifiers
144+
if identifier[0] == DOMAIN
145+
}
146+
self.new_devices = list(set(data) - current_device_ids)
147+
removed_devices = list(current_device_ids - set(data))
142148

143149
if removed_devices:
144150
await self._async_remove_devices(data)
145151

146152
async def _async_remove_devices(self, data: dict[str, GwEntityData]) -> None:
147153
"""Clean registries when removed devices found."""
148154
# First find the Plugwise via_device
149-
gateway_device = self.device_reg.async_get_device({(DOMAIN, self.api.gateway_id)})
155+
gateway_device = self.device_registry.async_get_device({(DOMAIN, self.api.gateway_id)})
150156
if gateway_device is not None:
151157
via_device_id = gateway_device.id
152158

0 commit comments

Comments
 (0)