mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Use migration helper in RainMachine (#62328)
This commit is contained in:
parent
b63c766ec0
commit
1b17c295d6
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user