Skip to content

Commit

Permalink
🐛 Allow config migration to version from version 2
Browse files Browse the repository at this point in the history
Fix #39
  • Loading branch information
kamaradclimber committed Jul 28, 2023
1 parent 300ebfb commit 91373c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion custom_components/vigieau/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/vigieau/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down

0 comments on commit 91373c8

Please sign in to comment.