Skip to content

Commit

Permalink
Add config flow version and migrate from config without phyn brand.
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanruthe committed Jan 24, 2024
1 parent de45812 commit bb99fcb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions custom_components/phyn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@

PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR, Platform.SWITCH, Platform.UPDATE, Platform.VALVE]

async def async_migrate_entry(hass, config_entry: ConfigEntry):
"""Migrate old entry."""
_LOGGER.debug("Migrating from version %s.%s", config_entry.version, config_entry.minor_version)

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

if config_entry.version == 1:
new = {**config_entry.data}
if config_entry.minor_version < 2:
if "Brand" not in new:
new['Brand'] = "phyn"

config_entry.version = 1
config_entry.minor_version = 2
hass.config_entries.async_update_entry(config_entry, data=new)

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

return True

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up flo from a config entry."""
Expand Down
1 change: 1 addition & 0 deletions custom_components/phyn/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for phyn."""

VERSION = 1
MINOR_VERSION = 2

async def async_step_user(self, user_input=None):
"""Handle the initial step."""
Expand Down

0 comments on commit bb99fcb

Please sign in to comment.