Skip to content

Commit

Permalink
Add migration components
Browse files Browse the repository at this point in the history
  • Loading branch information
vingerha committed Nov 10, 2023
1 parent 9bbc70d commit e515bda
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 18 additions & 5 deletions custom_components/gtfs2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,25 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry) -> bool:

if config_entry.version == 1:

new = {**config_entry.data}
new['extract_from'] = 'url'
new.pop('refresh_interval')

config_entry.version = 2
new_data = {**config_entry.data}
new_data['extract_from'] = 'url'
new_data.pop('refresh_interval')

new_options = {**config_entry.options}
new_options['real_time'] = False
new_options['refresh_interval'] = 15

config_entry.version = 3
hass.config_entries.async_update_entry(config_entry, data=new)
hass.config_entries.async_update_entry(config_entry, options=new_options)

if config_entry.version == 2:

new_options = {**config_entry.options}
new_options['real_time'] = False

config_entry.version = 3
hass.config_entries.async_update_entry(config_entry, options=new_options)

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

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

VERSION = 2
VERSION = 3

def __init__(self) -> None:
"""Init ConfigFlow."""
Expand Down

0 comments on commit e515bda

Please sign in to comment.