Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions custom_components/poollab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,18 @@
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_API_KEY, CONF_URL
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, HomeAssistantError
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .config_flow import PoolLabConfigFlow
from .const import DOMAIN
from .poollab import API_ENDPOINT, CloudAccount, PoolLabApi

DOMAIN = "poollab"
PLATFORMS = ["sensor"]

_LOGGER = logging.getLogger(__name__)


class InvalidAuth(HomeAssistantError):
"""Error to indicate there is invalid auth."""


class PoolLabConfigException(HomeAssistantError):
"""Error to indicate there is an error in config."""


class PoolLabCoordinator(DataUpdateCoordinator[CloudAccount]):
"""Coordinator for the PoolLab API."""

Expand Down Expand Up @@ -101,16 +94,32 @@ async def async_reload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->

async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Migrate old entry."""
version = config_entry.version
_LOGGER.debug("Migrating from version %s", version)

installed_version = PoolLabConfigFlow.VERSION
installed_minor_version = PoolLabConfigFlow.MINOR_VERSION

new_data = {**config_entry.data}
new_options = {**config_entry.options}

_LOGGER.debug(
"Migrating from version %s.%s", config_entry.version, config_entry.minor_version
)

if version == 1:
config_entry.version = 2
if CONF_URL not in config_entry.data:
new_data[CONF_URL] = API_ENDPOINT
hass.config_entries.async_update_entry(config_entry, data=new_data)
_LOGGER.info("Migration to version %s successful", config_entry.version)
return True

hass.config_entries.async_update_entry(
config_entry,
data=new_data,
options=new_options,
version=installed_version,
minor_version=installed_minor_version,
)
_LOGGER.info(
"Migration to version %s.%s successful",
installed_version,
installed_minor_version,
)
return True

return False
7 changes: 5 additions & 2 deletions custom_components/poollab/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from homeassistant.data_entry_flow import FlowResult
import homeassistant.helpers.config_validation as cv

from . import DOMAIN, InvalidAuth
from .const import DOMAIN, InvalidAuth
from .poollab import API_ENDPOINT, PoolLabApi

_LOGGER = logging.getLogger(__name__)
Expand All @@ -27,7 +27,10 @@
class PoolLabConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""PoolLab config flow."""

VERSION = 2
VERSION = 1
MINOR_VERSION = 2
data = None
options = None
_reauth_entry: config_entries.ConfigEntry | None = None

async def async_step_user(
Expand Down
9 changes: 9 additions & 0 deletions custom_components/poollab/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Common constants for integration."""

from homeassistant.exceptions import HomeAssistantError

DOMAIN = "poollab"


class InvalidAuth(HomeAssistantError):
"""Error to indicate there is invalid auth."""