2019-09-06 20:21:56 +00:00
|
|
|
"""Config flow to configure zone component."""
|
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
|
|
|
|
|
2019-09-06 20:21:56 +00:00
|
|
|
from iaqualink import AqualinkClient, AqualinkLoginException
|
2019-12-09 10:56:51 +00:00
|
|
|
import voluptuous as vol
|
2019-09-06 20:21:56 +00:00
|
|
|
|
|
|
|
from homeassistant import config_entries
|
|
|
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
2020-02-16 12:47:55 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType
|
2019-09-06 20:21:56 +00:00
|
|
|
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
|
|
|
2021-04-30 21:28:25 +00:00
|
|
|
class AqualinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
2019-09-06 20:21:56 +00:00
|
|
|
"""Aqualink config flow."""
|
|
|
|
|
|
|
|
VERSION = 1
|
|
|
|
|
2021-07-27 10:33:17 +00:00
|
|
|
async def async_step_user(self, user_input: dict[str, Any] | None = None):
|
2019-09-06 20:21:56 +00:00
|
|
|
"""Handle a flow start."""
|
|
|
|
# Supporting a single account.
|
2021-05-12 10:47:06 +00:00
|
|
|
entries = self._async_current_entries()
|
2019-09-06 20:21:56 +00:00
|
|
|
if entries:
|
2020-10-05 19:55:12 +00:00
|
|
|
return self.async_abort(reason="single_instance_allowed")
|
2019-09-06 20:21:56 +00:00
|
|
|
|
|
|
|
errors = {}
|
|
|
|
|
|
|
|
if user_input is not None:
|
|
|
|
username = user_input[CONF_USERNAME]
|
|
|
|
password = user_input[CONF_PASSWORD]
|
|
|
|
|
|
|
|
try:
|
|
|
|
aqualink = AqualinkClient(username, password)
|
|
|
|
await aqualink.login()
|
|
|
|
return self.async_create_entry(title=username, data=user_input)
|
|
|
|
except AqualinkLoginException:
|
2020-10-05 19:55:12 +00:00
|
|
|
errors["base"] = "cannot_connect"
|
2019-09-06 20:21:56 +00:00
|
|
|
|
|
|
|
return self.async_show_form(
|
|
|
|
step_id="user",
|
|
|
|
data_schema=vol.Schema(
|
|
|
|
{vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
|
|
|
|
),
|
|
|
|
errors=errors,
|
|
|
|
)
|
|
|
|
|
2021-03-18 09:02:00 +00:00
|
|
|
async def async_step_import(self, user_input: ConfigType | None = None):
|
2019-09-06 20:21:56 +00:00
|
|
|
"""Occurs when an entry is setup through config."""
|
|
|
|
return await self.async_step_user(user_input)
|