Skip to content

Commit

Permalink
Improve, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bouwew committed Sep 21, 2024
1 parent 3223a0a commit 94805a9
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions custom_components/plugwise/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,18 @@ def _async_remove_devices(self, data: PlugwiseData, entry: ConfigEntry) -> None:
device_list = dr.async_entries_for_config_entry(
device_reg, self.config_entry.entry_id
)
# via_device cannot be None, this will result in the deletion
# of other Plugwise Gateways when present!
via_device: str = ""

# First find the Plugwise via_device
via_device_device = device_reg.async_get_device(identifiers={(DOMAIN, data.gateway[GATEWAY_ID])})
if via_device_device is not None:
via_device = via_device_device.id
gateway_device = device_reg.async_get_device({(DOMAIN, data.gateway[GATEWAY_ID])})
if gateway_device is not None:
via_device_id = gateway_device.id

# Then remove the connected orphaned device(s)
for device_entry in device_list:
for identifier in device_entry.identifiers:
if identifier[0] == DOMAIN:
if (
device_entry.via_device_id == via_device
device_entry.via_device_id == via_device_id
and identifier[1] not in data.devices
):
device_reg.async_update_device(
Expand Down

0 comments on commit 94805a9

Please sign in to comment.