mirror of
https://github.com/jdejaegh/irm-kmi-ha.git
synced 2025-06-27 03:35:56 +02:00
Add config migration test and optimize imports
This commit is contained in:
parent
e74e7c2873
commit
b4685a397f
7 changed files with 45 additions and 20 deletions
|
@ -7,9 +7,10 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryError
|
||||
|
||||
from .const import (CONF_DARK_MODE, CONF_STYLE, OPTION_STYLE_STD, DOMAIN,
|
||||
PLATFORMS, OPTION_DEPRECATED_FORECAST_NOT_USED,
|
||||
CONF_USE_DEPRECATED_FORECAST)
|
||||
from .const import (CONF_DARK_MODE, CONF_STYLE, CONF_USE_DEPRECATED_FORECAST,
|
||||
CONFIG_FLOW_VERSION, DOMAIN,
|
||||
OPTION_DEPRECATED_FORECAST_NOT_USED, OPTION_STYLE_STD,
|
||||
PLATFORMS)
|
||||
from .coordinator import IrmKmiCoordinator
|
||||
from .weather import IrmKmiWeather
|
||||
|
||||
|
@ -51,7 +52,7 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry):
|
|||
"""Migrate old entry."""
|
||||
_LOGGER.debug(f"Migrating from version {config_entry.version}")
|
||||
|
||||
if config_entry.version > 2:
|
||||
if config_entry.version > CONFIG_FLOW_VERSION - 1:
|
||||
# This means the user has downgraded from a future version
|
||||
return False
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import logging
|
|||
|
||||
import voluptuous as vol
|
||||
from homeassistant.components.zone import DOMAIN as ZONE_DOMAIN
|
||||
from homeassistant.config_entries import ConfigFlow, OptionsFlow, ConfigEntry
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow
|
||||
from homeassistant.const import CONF_ZONE
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
|
@ -13,16 +13,18 @@ from homeassistant.helpers.selector import (EntitySelector,
|
|||
SelectSelectorConfig,
|
||||
SelectSelectorMode)
|
||||
|
||||
from .utils import get_config_value
|
||||
from .const import (CONF_DARK_MODE, CONF_STYLE, CONF_STYLE_OPTIONS,
|
||||
OPTION_STYLE_STD, DOMAIN, CONF_USE_DEPRECATED_FORECAST, OPTION_DEPRECATED_FORECAST_NOT_USED,
|
||||
CONF_USE_DEPRECATED_FORECAST_OPTIONS)
|
||||
CONF_USE_DEPRECATED_FORECAST,
|
||||
CONF_USE_DEPRECATED_FORECAST_OPTIONS, CONFIG_FLOW_VERSION,
|
||||
DOMAIN, OPTION_DEPRECATED_FORECAST_NOT_USED,
|
||||
OPTION_STYLE_STD)
|
||||
from .utils import get_config_value
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IrmKmiConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
VERSION = 3
|
||||
VERSION = CONFIG_FLOW_VERSION
|
||||
|
||||
@staticmethod
|
||||
@callback
|
||||
|
|
|
@ -16,6 +16,8 @@ from homeassistant.const import Platform
|
|||
|
||||
DOMAIN: Final = 'irm_kmi'
|
||||
PLATFORMS: Final = [Platform.WEATHER, Platform.CAMERA]
|
||||
CONFIG_FLOW_VERSION = 3
|
||||
|
||||
OUT_OF_BENELUX: Final = ["außerhalb der Benelux (Brussels)",
|
||||
"Hors de Belgique (Bxl)",
|
||||
"Outside the Benelux (Brussels)",
|
||||
|
|
|
@ -7,6 +7,7 @@ from typing import Any, List, Tuple
|
|||
|
||||
import async_timeout
|
||||
import pytz
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from homeassistant.components.weather import Forecast
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, CONF_ZONE
|
||||
|
@ -15,7 +16,6 @@ from homeassistant.exceptions import ConfigEntryError
|
|||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.update_coordinator import (DataUpdateCoordinator,
|
||||
UpdateFailed)
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
from .api import IrmKmiApiClient, IrmKmiApiError
|
||||
from .const import CONF_DARK_MODE, CONF_STYLE, OPTION_STYLE_SATELLITE
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Support for IRM KMI weather."""
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import List
|
||||
|
||||
|
@ -13,9 +12,10 @@ from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import DOMAIN, CONF_USE_DEPRECATED_FORECAST
|
||||
from .const import OPTION_DEPRECATED_FORECAST_HOURLY, OPTION_DEPRECATED_FORECAST_NOT_USED, \
|
||||
OPTION_DEPRECATED_FORECAST_DAILY
|
||||
from . import CONF_USE_DEPRECATED_FORECAST, DOMAIN
|
||||
from .const import (OPTION_DEPRECATED_FORECAST_DAILY,
|
||||
OPTION_DEPRECATED_FORECAST_HOURLY,
|
||||
OPTION_DEPRECATED_FORECAST_NOT_USED)
|
||||
from .coordinator import IrmKmiCoordinator
|
||||
from .utils import get_config_value
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@ from pytest_homeassistant_custom_component.common import (MockConfigEntry,
|
|||
load_fixture)
|
||||
|
||||
from custom_components.irm_kmi.api import IrmKmiApiParametersError
|
||||
from custom_components.irm_kmi.const import (CONF_DARK_MODE, CONF_STYLE,
|
||||
OPTION_STYLE_STD, DOMAIN, OPTION_DEPRECATED_FORECAST_NOT_USED,
|
||||
CONF_USE_DEPRECATED_FORECAST)
|
||||
from custom_components.irm_kmi.const import (
|
||||
CONF_DARK_MODE, CONF_STYLE, CONF_USE_DEPRECATED_FORECAST, DOMAIN,
|
||||
OPTION_DEPRECATED_FORECAST_NOT_USED, OPTION_STYLE_STD)
|
||||
|
||||
|
||||
async def patched(url: str, params: dict | None = None) -> bytes:
|
||||
|
|
|
@ -7,10 +7,13 @@ from homeassistant.config_entries import SOURCE_USER
|
|||
from homeassistant.const import CONF_ZONE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from pytest_homeassistant_custom_component.common import MockConfigEntry
|
||||
|
||||
from custom_components.irm_kmi.const import (CONF_DARK_MODE, CONF_STYLE,
|
||||
OPTION_STYLE_STD, DOMAIN, CONF_USE_DEPRECATED_FORECAST,
|
||||
OPTION_DEPRECATED_FORECAST_NOT_USED)
|
||||
from custom_components.irm_kmi import async_migrate_entry
|
||||
from custom_components.irm_kmi.const import (
|
||||
CONF_DARK_MODE, CONF_STYLE, CONF_USE_DEPRECATED_FORECAST,
|
||||
CONFIG_FLOW_VERSION, DOMAIN, OPTION_DEPRECATED_FORECAST_NOT_USED,
|
||||
OPTION_STYLE_STD)
|
||||
|
||||
|
||||
async def test_full_user_flow(
|
||||
|
@ -38,3 +41,20 @@ async def test_full_user_flow(
|
|||
CONF_STYLE: OPTION_STYLE_STD,
|
||||
CONF_DARK_MODE: False,
|
||||
CONF_USE_DEPRECATED_FORECAST: OPTION_DEPRECATED_FORECAST_NOT_USED}
|
||||
|
||||
|
||||
async def test_config_entry_migration(hass: HomeAssistant) -> None:
|
||||
"""Ensure that config entry migration takes the configuration to the latest version"""
|
||||
entry = MockConfigEntry(
|
||||
title="Home",
|
||||
domain=DOMAIN,
|
||||
data={CONF_ZONE: "zone.home"},
|
||||
unique_id="zone.home",
|
||||
version=1
|
||||
)
|
||||
|
||||
entry.add_to_hass(hass)
|
||||
await async_migrate_entry(hass, entry)
|
||||
result_entry = hass.config_entries.async_get_entry(entry_id=entry.entry_id)
|
||||
|
||||
assert result_entry.version == CONFIG_FLOW_VERSION
|
||||
|
|
Loading…
Add table
Reference in a new issue