diff --git a/homeassistant/components/rainmachine/__init__.py b/homeassistant/components/rainmachine/__init__.py index 0e0dd726f75..5ffdc7951db 100644 --- a/homeassistant/components/rainmachine/__init__.py +++ b/homeassistant/components/rainmachine/__init__.py @@ -344,10 +344,9 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if version == 1: version = entry.version = 2 - ent_reg = er.async_get(hass) - for entity_entry in [ - e for e in ent_reg.entities.values() if e.config_entry_id == entry.entry_id - ]: + @callback + def migrate_unique_id(entity_entry: er.RegistryEntry) -> dict[str, Any]: + """Migrate the unique ID to a new format.""" unique_id_pieces = entity_entry.unique_id.split("_") old_mac = unique_id_pieces[0] new_mac = ":".join(old_mac[i : i + 2] for i in range(0, len(old_mac), 2)) @@ -356,9 +355,9 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if entity_entry.entity_id.startswith("switch"): unique_id_pieces[1] = unique_id_pieces[1][11:].lower() - ent_reg.async_update_entity( - entity_entry.entity_id, new_unique_id="_".join(unique_id_pieces) - ) + return {"new_unique_id": "_".join(unique_id_pieces)} + + await er.async_migrate_entries(hass, entry.entry_id, migrate_unique_id) LOGGER.info("Migration to version %s successful", version)