diff --git a/custom_components/vigieau/__init__.py b/custom_components/vigieau/__init__.py index 946a83a..6c3a99a 100644 --- a/custom_components/vigieau/__init__.py +++ b/custom_components/vigieau/__init__.py @@ -59,12 +59,22 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry): new[ DEVICE_ID_KEY ] = "Vigieau" # hardcoded to match hardcoded id from version 0.3.9 + new[CONF_LATITUDE] = lat + new[CONF_LONGITUDE] = lon new[MIGRATED_FROM_VERSION_1] = True _LOGGER.warn( f"Migration detected insee code for current HA instance is {insee_code} in {city_name}" ) - config_entry.version = 2 + config_entry.version = 3 + hass.config_entries.async_update_entry(config_entry, data=new) + if config_entry.version == 2: + _LOGGER.warn("config entry version is 2, migrating to version 3") + new = {**config_entry.data} + insee_code, city_name, lat, lon = await get_insee_code_fromcoord(hass) + new[CONF_LATITUDE] = lat + new[CONF_LONGITUDE] = lon + config_entry.version = 3 hass.config_entries.async_update_entry(config_entry, data=new) return True diff --git a/custom_components/vigieau/config_flow.py b/custom_components/vigieau/config_flow.py index 8444c91..6ad2bbb 100644 --- a/custom_components/vigieau/config_flow.py +++ b/custom_components/vigieau/config_flow.py @@ -81,7 +81,7 @@ def _build_place_key(city) -> str: class SetupConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): - VERSION = 2 + VERSION = 3 def __init__(self): """Initialize"""