Skip to content

Commit

Permalink
update config flow version (#33)
Browse files Browse the repository at this point in the history
remove jet and morrisons in config version 3 as migration path (#33)
  • Loading branch information
pantherale0 authored Feb 3, 2025
1 parent d7b97d1 commit 3fabd23
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions custom_components/fuel_prices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,26 +168,34 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
_LOGGER.debug("Migrating configuration from version %s",
config_entry.version)

if config_entry.version > 1:
new_data = {**config_entry.data}
if config_entry.options:
new_data = {**config_entry.options}

if config_entry.version > 2:
# This means the user has downgraded from a future version
return False

if config_entry.version == 1:
if config_entry.version == 2:
_LOGGER.warning("Removing jet and morrisons from config entry.")
if "morrisons" in new_data[CONF_SOURCES]:
new_data[CONF_SOURCES].remove("morrisons")
if "jet" in new_data[CONF_SOURCES]:
new_data[CONF_SOURCES].remove("jet")
hass.config_entries.async_update_entry(
config_entry, data=new_data, version=3
)

new_data = {**config_entry.data}
if config_entry.options:
new_data = {**config_entry.options}
if config_entry.version == 1:
for area in new_data[CONF_AREAS]:
_LOGGER.debug("Upgrading area definition for %s", area[CONF_NAME])
area[CONF_CHEAPEST_SENSORS] = False
area[CONF_CHEAPEST_SENSORS_COUNT] = 5
area[CONF_CHEAPEST_SENSORS_FUEL_TYPE] = ""

hass.config_entries.async_update_entry(
config_entry, data=new_data, version=2)

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

return True

Expand Down
2 changes: 1 addition & 1 deletion custom_components/fuel_prices/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow."""

VERSION = 2
VERSION = 3
configured_areas: list[dict] = []
configured_sources = []
configuring_area = {}
Expand Down

0 comments on commit 3fabd23

Please sign in to comment.