Skip to content

Commit

Permalink
fix: add migration from old v1 configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
fcastilloec committed Jan 16, 2024
1 parent 7915ccd commit 734476f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions custom_components/gkeep_list_sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,20 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
def get_service_name(config_entry: ConfigEntry) -> str:
"""Retrieves the name for running a service."""
return SERVICE_NAME_BASE + "_" + config_entry.data.get(CONF_BASE_USERNAME)

async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Migrate from an old configuration version."""
_LOGGER.debug("Migrating from version %s", config_entry.version)

if config_entry.version == 1:
base_username = config_entry.data[CONF_USERNAME].partition("@")[0]
unique_id = f"{base_username}-{config_entry.data[CONF_LIST_ID]}"
data = {**config_entry.data, CONF_BASE_USERNAME: base_username}
hass.config_entries.async_update_entry(
config_entry, unique_id=unique_id, data=data
)
config_entry.version = 2

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

return True

0 comments on commit 734476f

Please sign in to comment.