1 """Config flow for Shark IQ integration."""
3 from __future__
import annotations
6 from collections.abc
import Mapping
10 from sharkiq
import SharkIqAuthError, get_ayla_api
11 import voluptuous
as vol
23 SHARKIQ_REGION_DEFAULT,
24 SHARKIQ_REGION_EUROPE,
25 SHARKIQ_REGION_OPTIONS,
28 SHARKIQ_SCHEMA = vol.Schema(
30 vol.Required(CONF_USERNAME): str,
31 vol.Required(CONF_PASSWORD): str,
33 CONF_REGION, default=SHARKIQ_REGION_DEFAULT
34 ): selector.SelectSelector(
35 selector.SelectSelectorConfig(
36 options=SHARKIQ_REGION_OPTIONS, translation_key=
"region"
44 hass: HomeAssistant, data: Mapping[str, Any]
46 """Validate the user input allows us to connect."""
47 ayla_api = get_ayla_api(
48 username=data[CONF_USERNAME],
49 password=data[CONF_PASSWORD],
51 europe=(data[CONF_REGION] == SHARKIQ_REGION_EUROPE),
55 async
with asyncio.timeout(10):
56 LOGGER.debug(
"Initialize connection to Ayla networks API")
57 await ayla_api.async_sign_in()
58 except (TimeoutError, aiohttp.ClientError, TypeError)
as error:
61 "Unable to connect to SharkIQ services. Check your region settings."
63 except SharkIqAuthError
as error:
66 "Username or password incorrect. Please check your credentials."
68 except Exception
as error:
69 LOGGER.exception(
"Unexpected exception")
72 "An unknown error occurred. Check your region settings and open an issue on Github if the issue persists."
76 return {
"title": data[CONF_USERNAME]}
80 """Handle a config flow for Shark IQ."""
85 self, user_input: Mapping[str, Any]
86 ) -> tuple[dict[str, str] |
None, dict[str, str]]:
87 """Validate form input."""
95 errors[
"base"] =
"cannot_connect"
97 errors[
"base"] =
"invalid_auth"
99 errors[
"base"] =
"unknown"
103 self, user_input: dict[str, str] |
None =
None
104 ) -> ConfigFlowResult:
105 """Handle the initial step."""
106 errors: dict[str, str] = {}
107 if user_input
is not None:
115 step_id=
"user", data_schema=SHARKIQ_SCHEMA, errors=errors
119 self, entry_data: Mapping[str, Any]
120 ) -> ConfigFlowResult:
121 """Handle re-auth if login is invalid."""
125 self, user_input: dict[str, Any] |
None =
None
126 ) -> ConfigFlowResult:
127 """Handle a flow initiated by reauthentication."""
128 errors: dict[str, str] = {}
130 if user_input
is not None:
134 errors = {
"base":
"unknown"}
136 self.hass.config_entries.async_update_entry(entry, data=user_input)
139 if errors[
"base"] !=
"invalid_auth":
143 step_id=
"reauth_confirm",
144 data_schema=SHARKIQ_SCHEMA,
150 """Error to indicate we cannot connect."""
154 """Error to indicate there is invalid auth."""
158 """Error to indicate there is an uncaught auth error."""
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
tuple[dict[str, str]|None, dict[str, str]] _async_validate_input(self, Mapping[str, Any] user_input)
ConfigFlowResult async_step_user(self, dict[str, str]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry|None async_set_unique_id(self, str|None unique_id=None, *bool raise_on_progress=True)
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_abort(self, *str reason, Mapping[str, str]|None description_placeholders=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)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
dict[str, str] _validate_input(HomeAssistant hass, Mapping[str, Any] data)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)