Fix heos migration (#137887)

* Fix heos migration

* Fix for loop
This commit is contained in:
Paulus Schoutsen 2025-02-08 11:56:23 -05:00 committed by GitHub
parent bd32a6ab83
commit 907826e909
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,24 +37,24 @@ async def async_setup_entry(hass: HomeAssistant, entry: HeosConfigEntry) -> bool
for device in device_registry.devices.get_devices_for_config_entry_id( for device in device_registry.devices.get_devices_for_config_entry_id(
entry.entry_id entry.entry_id
): ):
for domain, player_id in device.identifiers: for ident in device.identifiers:
if domain == DOMAIN and not isinstance(player_id, str): if ident[0] != DOMAIN or isinstance(ident[1], str):
# Create set of identifiers excluding this integration continue
identifiers = { # type: ignore[unreachable]
(domain, identifier) player_id = int(ident[1]) # type: ignore[unreachable]
for domain, identifier in device.identifiers
if domain != DOMAIN # Create set of identifiers excluding this integration
} identifiers = {ident for ident in device.identifiers if ident[0] != DOMAIN}
migrated_identifiers = {(DOMAIN, str(player_id))} migrated_identifiers = {(DOMAIN, str(player_id))}
# Add migrated if not already present in another device, which occurs if the user downgraded and then upgraded # Add migrated if not already present in another device, which occurs if the user downgraded and then upgraded
if not device_registry.async_get_device(migrated_identifiers): if not device_registry.async_get_device(migrated_identifiers):
identifiers.update(migrated_identifiers) identifiers.update(migrated_identifiers)
if len(identifiers) > 0: if len(identifiers) > 0:
device_registry.async_update_device( device_registry.async_update_device(
device.id, new_identifiers=identifiers device.id, new_identifiers=identifiers
) )
else: else:
device_registry.async_remove_device(device.id) device_registry.async_remove_device(device.id)
break break
coordinator = HeosCoordinator(hass, entry) coordinator = HeosCoordinator(hass, entry)