2019-09-06 20:21:56 +00:00
|
|
|
"""Config flow to configure zone component."""
|
2024-03-08 13:52:48 +00:00
|
|
|
|
2021-03-18 09:02:00 +00:00
|
|
|
from __future__ import annotations
|
2019-09-06 20:21:56 +00:00
|
|
|
|
2021-07-27 10:33:17 +00:00
|
|
|
from typing import Any
|
|
|
|
|
2023-02-12 08:04:59 +00:00
|
|
|
import httpx
|
2021-12-27 20:20:55 +00:00
|
|
|
from iaqualink.client import AqualinkClient
|
|
|
|
from iaqualink.exception import (
|
|
|
|
AqualinkServiceException,
|
|
|
|
AqualinkServiceUnauthorizedException,
|
|
|
|
)
|
2019-12-09 10:56:51 +00:00
|
|
|
import voluptuous as vol
|
2019-09-06 20:21:56 +00:00
|
|
|
|
2024-02-29 19:08:46 +00:00
|
|
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
2019-09-06 20:21:56 +00:00
|
|
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
|
|
|
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
|
|
|
2024-02-29 19:08:46 +00:00
|
|
|
class AqualinkFlowHandler(ConfigFlow, domain=DOMAIN):
|
2019-09-06 20:21:56 +00:00
|
|
|
"""Aqualink config flow."""
|
|
|
|
|
|
|
|
VERSION = 1
|
|
|
|
|
2022-05-24 08:49:05 +00:00
|
|
|
async def async_step_user(
|
|
|
|
self, user_input: dict[str, Any] | None = None
|
2024-02-29 19:08:46 +00:00
|
|
|
) -> ConfigFlowResult:
|
2019-09-06 20:21:56 +00:00
|
|
|
"""Handle a flow start."""
|
|
|
|
errors = {}
|
|
|
|
|
|
|
|
if user_input is not None:
|
|
|
|
username = user_input[CONF_USERNAME]
|
|
|
|
password = user_input[CONF_PASSWORD]
|
|
|
|
|
|
|
|
try:
|
2021-12-27 20:20:55 +00:00
|
|
|
async with AqualinkClient(username, password):
|
|
|
|
pass
|
|
|
|
except AqualinkServiceUnauthorizedException:
|
|
|
|
errors["base"] = "invalid_auth"
|
2023-02-12 08:04:59 +00:00
|
|
|
except (AqualinkServiceException, httpx.HTTPError):
|
2020-10-05 19:55:12 +00:00
|
|
|
errors["base"] = "cannot_connect"
|
2021-12-27 20:20:55 +00:00
|
|
|
else:
|
|
|
|
return self.async_create_entry(title=username, data=user_input)
|
2019-09-06 20:21:56 +00:00
|
|
|
|
|
|
|
return self.async_show_form(
|
|
|
|
step_id="user",
|
|
|
|
data_schema=vol.Schema(
|
2021-12-27 20:20:55 +00:00
|
|
|
{
|
|
|
|
vol.Required(CONF_USERNAME): str,
|
|
|
|
vol.Required(CONF_PASSWORD): str,
|
|
|
|
}
|
2019-09-06 20:21:56 +00:00
|
|
|
),
|
|
|
|
errors=errors,
|
|
|
|
)
|