I used AI to generate the following, but the suggested fix has been tested on my local Home Assistant setup.
The duplicate-device cleanup added for #160 assumes every device registry identifier is a 2-tuple:
for domain, deviceid in device.identifiers:
That is not always true in Home Assistant. Some device entries have 3-part identifiers, for example:
('other_integration', 'old_device_identifier', 'device_type')
('bridge_integration', 'bridge_identifier', 'bridge_role')
As a result, on startup the integration logs errors like:
ERROR (MainThread) [custom_components.electrolux_status] Unable to remove old device idendifier, please report: {('other_integration', 'old_device_identifier', 'device_type')} too many values to unpack (expected 2, got 3)
ERROR (MainThread) [custom_components.electrolux_status] Unable to remove old device idendifier, please report: {('bridge_integration', 'bridge_identifier', 'bridge_role')} too many values to unpack (expected 2, got 3)
This makes unrelated integrations appear in Electrolux logs, but the actual bug is in electrolux_status’s cleanup logic.
Minimal safe fix is to only inspect identifiers belonging to this domain and not assume tuple length:
diff --git a/custom_components/electrolux_status/__init__.py b/custom_components/electrolux_status/__init__.py
@@
+def _electrolux_identifier_values(identifiers: set[tuple[str, ...]]) -> set[str]:
+ values: set[str] = set()
+ for identifier in identifiers:
+ if len(identifier) < 2:
+ continue
+ if identifier[0] != DOMAIN:
+ continue
+ values.add(identifier[1])
+ return values
@@
- for device in device_list:
- try:
- for domain, deviceid in device.identifiers:
- if domain != DOMAIN:
- continue
- if deviceid not in all_api_ids:
- device_registry.async_remove_device(device.id)
- except Exception as e:
- _LOGGER.error("Unable to remove old device idendifier, please report: %s %s", device.identifiers, e)
+ for device in device_list:
+ for deviceid in _electrolux_identifier_values(device.identifiers):
+ if deviceid in all_api_ids:
+ continue
+ device_registry.async_remove_device(device.id)
+ break
@@
- identifier_tuple = next(iter(device_entry.identifiers))[1]
- if identifier_tuple not in all_api_ids:
- return True
- return False
+ electrolux_ids = _electrolux_identifier_values(device_entry.identifiers)
+ if not electrolux_ids:
+ return False
+ return electrolux_ids.isdisjoint(all_api_ids)
This fixes the startup error and still preserves the intended cleanup behavior from #160.
References:
#160 duplicate empty devices
#169 duplicated device / cannot delete
I used AI to generate the following, but the suggested fix has been tested on my local Home Assistant setup.
The duplicate-device cleanup added for
#160assumes every device registry identifier is a 2-tuple:That is not always true in Home Assistant. Some device entries have 3-part identifiers, for example:
('other_integration', 'old_device_identifier', 'device_type')('bridge_integration', 'bridge_identifier', 'bridge_role')As a result, on startup the integration logs errors like:
This makes unrelated integrations appear in Electrolux logs, but the actual bug is in
electrolux_status’s cleanup logic.Minimal safe fix is to only inspect identifiers belonging to this domain and not assume tuple length:
This fixes the startup error and still preserves the intended cleanup behavior from
#160.References:
#160duplicate empty devices#169duplicated device / cannot delete