diff --git a/custom_components/mikrotik_router/__init__.py b/custom_components/mikrotik_router/__init__.py index 83cebd3..3f13d3a 100644 --- a/custom_components/mikrotik_router/__init__.py +++ b/custom_components/mikrotik_router/__init__.py @@ -3,23 +3,24 @@ from __future__ import annotations import voluptuous as vol +import logging from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv from homeassistant.helpers import device_registry from homeassistant.config_entries import ConfigEntry -from .const import ( - PLATFORMS, - DOMAIN, - RUN_SCRIPT_COMMAND, -) +from homeassistant.const import CONF_VERIFY_SSL + +from .const import PLATFORMS, DOMAIN, RUN_SCRIPT_COMMAND, DEFAULT_VERIFY_SSL from .coordinator import MikrotikData, MikrotikCoordinator, MikrotikTrackerCoordinator SCRIPT_SCHEMA = vol.Schema( {vol.Required("router"): cv.string, vol.Required("script"): cv.string} ) +_LOGGER = logging.getLogger(__name__) + # --------------------------- # async_setup_entry @@ -77,3 +78,26 @@ async def async_remove_config_entry_device( ) -> bool: """Remove a config entry from a device.""" return True + + +# --------------------------- +# async_migrate_entry +# --------------------------- +async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry): + _LOGGER.debug( + "Migrating configuration from version %s.%s", + config_entry.version, + config_entry.minor_version, + ) + + if config_entry.version < 2: + new_data = {**config_entry.data} + new_data[CONF_VERIFY_SSL] = DEFAULT_VERIFY_SSL + hass.config_entries.async_update_entry(config_entry, data=new_data, version=2) + + _LOGGER.debug( + "Migration to configuration version %s.%s successful", + config_entry.version, + config_entry.minor_version, + ) + return True diff --git a/custom_components/mikrotik_router/config_flow.py b/custom_components/mikrotik_router/config_flow.py index 5bff1ae..ac210c4 100644 --- a/custom_components/mikrotik_router/config_flow.py +++ b/custom_components/mikrotik_router/config_flow.py @@ -86,7 +86,7 @@ def configured_instances(hass): class MikrotikControllerConfigFlow(ConfigFlow, domain=DOMAIN): """MikrotikControllerConfigFlow class""" - VERSION = 1 + VERSION = 2 CONNECTION_CLASS = CONN_CLASS_LOCAL_POLL def __init__(self):