Skip to content

Commit

Permalink
Fix: Migrate only correct entities
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajNyiri committed Oct 5, 2023
1 parent ad80dc0 commit 4746625
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions custom_components/tapo_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,19 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry):
registerController, host, username, password
)
camData = await getCamData(hass, tapoController)
macAddress = camData["basic_info"]["mac"]
macAddress = camData["basic_info"]["mac"].lower()

@callback
def update_unique_id(entity_entry):
return {
"new_unique_id": "{}-{}".format(
macAddress, entity_entry.unique_id
).lower()
}
if (
macAddress not in entity_entry.unique_id
and macAddress.replace("-", "_") not in entity_entry.unique_id
):
return {
"new_unique_id": "{}-{}".format(
macAddress, entity_entry.unique_id
).lower()
}

await homeassistant.helpers.entity_registry.async_migrate_entries(
hass, config_entry.entry_id, update_unique_id
Expand All @@ -222,7 +226,7 @@ def update_unique_id(entity_entry):
)
raise ConfigEntryNotReady

# config_entry.version = 15
config_entry.version = 15

LOGGER.info("Migration to version %s successful", config_entry.version)

Expand Down

0 comments on commit 4746625

Please sign in to comment.