Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow to configure zone component."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 import httpx
8 from iaqualink.client import AqualinkClient
9 from iaqualink.exception import (
10  AqualinkServiceException,
11  AqualinkServiceUnauthorizedException,
12 )
13 import voluptuous as vol
14 
15 from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
16 from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
17 
18 from .const import DOMAIN
19 
20 
21 class AqualinkFlowHandler(ConfigFlow, domain=DOMAIN):
22  """Aqualink config flow."""
23 
24  VERSION = 1
25 
26  async def async_step_user(
27  self, user_input: dict[str, Any] | None = None
28  ) -> ConfigFlowResult:
29  """Handle a flow start."""
30  errors = {}
31 
32  if user_input is not None:
33  username = user_input[CONF_USERNAME]
34  password = user_input[CONF_PASSWORD]
35 
36  try:
37  async with AqualinkClient(username, password):
38  pass
39  except AqualinkServiceUnauthorizedException:
40  errors["base"] = "invalid_auth"
41  except (AqualinkServiceException, httpx.HTTPError):
42  errors["base"] = "cannot_connect"
43  else:
44  return self.async_create_entryasync_create_entryasync_create_entry(title=username, data=user_input)
45 
46  return self.async_show_formasync_show_formasync_show_form(
47  step_id="user",
48  data_schema=vol.Schema(
49  {
50  vol.Required(CONF_USERNAME): str,
51  vol.Required(CONF_PASSWORD): str,
52  }
53  ),
54  errors=errors,
55  )
ConfigFlowResult async_create_entry(self, *str title, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None, Mapping[str, Any]|None options=None)
ConfigFlowResult async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_create_entry(self, *str|None title=None, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None)