Skip to content

Commit

Permalink
Added config migration support
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-r committed Jan 15, 2024
1 parent 5977532 commit e302148
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions custom_components/ohme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,20 @@ async def async_unload_entry(hass, entry):
"""Unload a config entry."""

return await hass.config_entries.async_unload_platforms(entry, ENTITY_TYPES)

async def async_migrate_entry(hass: core.HomeAssistant, config_entry) -> bool:
"""Migrate old entry."""
# Version number has gone backwards
if CONFIG_VERSION < config_entry.version:
_LOGGER.error("Backwards migration not possible. Please update the integration.")
return False

# Version number has gone up
if config_entry.version < CONFIG_VERSION:
_LOGGER.debug("Migrating from version %s", config_entry.version)
new_data = config_entry.data

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

return True
3 changes: 2 additions & 1 deletion custom_components/ohme/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import voluptuous as vol
from homeassistant.config_entries import (ConfigFlow, OptionsFlow)
from .const import DOMAIN
from .const import DOMAIN, CONFIG_VERSION
from .api_client import OhmeApiClient


Expand All @@ -11,6 +11,7 @@

class OhmeConfigFlow(ConfigFlow, domain=DOMAIN):
"""Config flow."""
VERSION = CONFIG_VERSION

async def async_step_user(self, info):
errors = {}
Expand Down
2 changes: 2 additions & 0 deletions custom_components/ohme/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
DOMAIN = "ohme"
USER_AGENT = "dan-r-homeassistant-ohme"
INTEGRATION_VERSION = "0.3.2"
CONFIG_VERSION = 1
ENTITY_TYPES = ["sensor", "binary_sensor", "switch", "button", "number", "time"]

DATA_CLIENT = "client"
DATA_COORDINATORS = "coordinators"
Expand Down

0 comments on commit e302148

Please sign in to comment.