Skip to content

Commit

Permalink
Merge pull request #158 from suaveolent/main
Browse files Browse the repository at this point in the history
Migrate user options to reflect change from ct/kWh to currency/kWh
  • Loading branch information
suaveolent authored Nov 4, 2024
2 parents b100b6e + 3423419 commit 6fdb2a8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
56 changes: 43 additions & 13 deletions custom_components/epex_spot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Component for EPEX Spot support."""
import logging
from typing import Callable, Any

import asyncio
import logging
import random
from typing import Any, Callable

import homeassistant.helpers.config_validation as cv
import voluptuous as vol

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_DEVICE_ID, Platform
from homeassistant.core import (
Expand All @@ -14,31 +15,34 @@
ServiceResponse,
SupportsResponse,
)
from homeassistant.exceptions import HomeAssistantError, ConfigEntryNotReady
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import (
async_get as dr_async_get,
DeviceInfo,
DeviceEntryType,
DeviceInfo,
async_get as dr_async_get,
)
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.event import async_track_time_change
from homeassistant.helpers.update_coordinator import (
DataUpdateCoordinator,
CoordinatorEntity,
DataUpdateCoordinator,
)

from .const import (
ATTR_DATA,
CONF_DURATION,
CONF_EARLIEST_START_TIME,
CONF_EARLIEST_START_POST,
CONF_LATEST_END_TIME,
CONF_EARLIEST_START_TIME,
CONF_LATEST_END_POST,
CONF_LATEST_END_TIME,
CONF_SURCHARGE_ABS,
CONFIG_VERSION,
DOMAIN,
)
from .SourceShell import SourceShell
from .localization import CURRENCY_MAPPING
from .SourceShell import SourceShell

_LOGGER = logging.getLogger(__name__)

Expand All @@ -62,8 +66,8 @@


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up component from a config entry, config_entry contains data
from config entry database."""
"""Set up component from a config entry."""

source = SourceShell(entry, async_get_clientsession(hass))

try:
Expand Down Expand Up @@ -193,6 +197,32 @@ async def on_update_options_listener(hass, entry):
await coordinator.async_request_refresh()


async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Migrate old entry data to the new entry schema."""

data = config_entry.data.copy()

current_version = data.get("version", 1)

if current_version != CONFIG_VERSION:
_LOGGER.info(
"Migrating entry %s to version %s", config_entry.entry_id, CONFIG_VERSION
)
new_options = {**config_entry.options}

hass.config_entries.async_update_entry(
config_entry, options=new_options, version=CONFIG_VERSION
)

_LOGGER.info(
"Migration of entry %s to version %s successful",
config_entry.entry_id,
CONFIG_VERSION,
)

return True


class EpexSpotDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
"""Class to manage fetching AccuWeather data API."""

Expand Down
7 changes: 5 additions & 2 deletions custom_components/epex_spot/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
Used by UI to setup integration.
"""

import voluptuous as vol

from homeassistant import config_entries
from homeassistant.core import callback

Expand All @@ -18,12 +20,13 @@
CONF_SURCHARGE_PERC,
CONF_TAX,
CONF_TOKEN,
CONFIG_VERSION,
DEFAULT_SURCHARGE_ABS,
DEFAULT_SURCHARGE_PERC,
DEFAULT_TAX,
DOMAIN,
)
from .EPEXSpot import SMARD, Awattar, EPEXSpotWeb, smartENERGY, Tibber
from .EPEXSpot import SMARD, Awattar, EPEXSpotWeb, Tibber, smartENERGY

CONF_SOURCE_LIST = (
CONF_SOURCE_AWATTAR,
Expand All @@ -37,7 +40,7 @@
class EpexSpotConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): # type: ignore
"""Component config flow."""

VERSION = 1
VERSION = CONFIG_VERSION

def __init__(self):
self._source_name = None
Expand Down
1 change: 1 addition & 0 deletions custom_components/epex_spot/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ATTR_QUANTILE = "quantile"
ATTR_PRICE_PER_KWH = "price_per_kwh"

CONFIG_VERSION = 2
CONF_SOURCE = "source"
CONF_MARKET_AREA = "market_area"
CONF_TOKEN = "token"
Expand Down

0 comments on commit 6fdb2a8

Please sign in to comment.