Improve plugwise device cleanup (#126419)
* Improve code * Ruff-suggestion * Change as suggested
This commit is contained in:
parent
96b7fc9a75
commit
90aa9aa98f
1 changed files with 6 additions and 11 deletions
|
@ -104,24 +104,19 @@ class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[PlugwiseData]):
|
||||||
device_list = dr.async_entries_for_config_entry(
|
device_list = dr.async_entries_for_config_entry(
|
||||||
device_reg, self.config_entry.entry_id
|
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
|
# First find the Plugwise via_device
|
||||||
for device_entry in device_list:
|
gateway_device = device_reg.async_get_device(
|
||||||
for identifier in device_entry.identifiers:
|
{(DOMAIN, data.gateway[GATEWAY_ID])}
|
||||||
if identifier[0] != DOMAIN or identifier[1] != data.gateway[GATEWAY_ID]:
|
)
|
||||||
continue
|
assert gateway_device is not None
|
||||||
via_device = device_entry.id
|
via_device_id = gateway_device.id
|
||||||
break
|
|
||||||
|
|
||||||
# Then remove the connected orphaned device(s)
|
# Then remove the connected orphaned device(s)
|
||||||
for device_entry in device_list:
|
for device_entry in device_list:
|
||||||
for identifier in device_entry.identifiers:
|
for identifier in device_entry.identifiers:
|
||||||
if identifier[0] == DOMAIN:
|
if identifier[0] == DOMAIN:
|
||||||
if (
|
if (
|
||||||
device_entry.via_device_id == via_device
|
device_entry.via_device_id == via_device_id
|
||||||
and identifier[1] not in data.devices
|
and identifier[1] not in data.devices
|
||||||
):
|
):
|
||||||
device_reg.async_update_device(
|
device_reg.async_update_device(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue