Correct logic in honeywell for cleaning up stale devices (#106018)
* code quality fixes * remove unnecessary code * Remove comment * change config entry configuration order * update based on aladdin connect pr
This commit is contained in:
parent
09a0ace671
commit
061c144fe8
2 changed files with 55 additions and 28 deletions
|
@ -118,23 +118,17 @@ def remove_stale_devices(
|
|||
device_entries = dr.async_entries_for_config_entry(
|
||||
device_registry, config_entry.entry_id
|
||||
)
|
||||
all_device_ids: set = set()
|
||||
for device in devices.values():
|
||||
all_device_ids.add(device.deviceid)
|
||||
all_device_ids = {device.deviceid for device in devices.values()}
|
||||
|
||||
for device_entry in device_entries:
|
||||
device_id: str | None = None
|
||||
remove = True
|
||||
|
||||
for identifier in device_entry.identifiers:
|
||||
if identifier[0] != DOMAIN:
|
||||
remove = False
|
||||
continue
|
||||
if identifier[0] == DOMAIN:
|
||||
device_id = identifier[1]
|
||||
break
|
||||
|
||||
device_id = identifier[1]
|
||||
break
|
||||
|
||||
if remove and (device_id is None or device_id not in all_device_ids):
|
||||
if device_id is None or device_id not in all_device_ids:
|
||||
# If device_id is None an invalid device entry was found for this config entry.
|
||||
# If the device_id is not in existing device ids it's a stale device entry.
|
||||
# Remove config entry from this device entry in either case.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue