Migrate config entry

pull/31066/head
Aaron Bach 2020-01-21 14:08:12 -07:00
parent 6427360fce
commit 84fcf5120f
2 changed files with 21 additions and 1 deletions

View File

@ -10,10 +10,12 @@ import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT
from homeassistant.const import (
ATTR_ATTRIBUTION,
CONF_BINARY_SENSORS,
CONF_IP_ADDRESS,
CONF_PASSWORD,
CONF_PORT,
CONF_SCAN_INTERVAL,
CONF_SENSORS,
CONF_SSL,
)
from homeassistant.exceptions import ConfigEntryNotReady
@ -268,6 +270,24 @@ async def async_unload_entry(hass, config_entry):
return True
async def async_migrate_entry(hass, config_entry):
"""Migrate the config entry upon new versions."""
version = config_entry.version
data = {**config_entry.data}
_LOGGER.debug("Migrating from version %s", version)
# 1 -> 2: Remove unused condition data:
if version == 1:
data.pop(CONF_BINARY_SENSORS, None)
data.pop(CONF_SENSORS, None)
version = config_entry.version = 2
hass.config_entries.async_update_entry(config_entry, data=data)
_LOGGER.debug("Migration to version %s successful", version)
return True
class RainMachine:
"""Define a generic RainMachine object."""

View File

@ -33,7 +33,7 @@ def configured_instances(hass):
class RainMachineFlowHandler(config_entries.ConfigFlow):
"""Handle a RainMachine config flow."""
VERSION = 1
VERSION = 2
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
def __init__(self):