1 """Adds config flow for Sensibo integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from pysensibo.exceptions
import AuthenticationError
9 import voluptuous
as vol
16 from .const
import DEFAULT_NAME, DOMAIN
17 from .util
import NoDevicesError, NoUsernameError, async_validate_api
19 DATA_SCHEMA = vol.Schema(
27 hass: HomeAssistant, api_key: str
28 ) -> tuple[str |
None, dict[str, str]]:
29 """Validate the API key."""
30 errors: dict[str, str] = {}
31 username: str |
None =
None
34 except AuthenticationError:
35 errors[
"base"] =
"invalid_auth"
36 except ConnectionError:
37 errors[
"base"] =
"cannot_connect"
38 except NoDevicesError:
39 errors[
"base"] =
"no_devices"
40 except NoUsernameError:
41 errors[
"base"] =
"no_username"
42 return (username, errors)
46 """Handle a config flow for Sensibo integration."""
51 self, entry_data: Mapping[str, Any]
52 ) -> ConfigFlowResult:
53 """Handle re-authentication with Sensibo."""
57 self, user_input: dict[str, Any] |
None =
None
58 ) -> ConfigFlowResult:
59 """Confirm re-authentication with Sensibo."""
60 errors: dict[str, str] = {}
63 api_key = user_input[CONF_API_KEY]
64 username, errors = await
validate_api(self.hass, api_key)
67 if username == reauth_entry.unique_id:
71 CONF_API_KEY: api_key,
74 errors[
"base"] =
"incorrect_api_key"
77 step_id=
"reauth_confirm",
78 data_schema=DATA_SCHEMA,
83 self, user_input: dict[str, Any] |
None =
None
84 ) -> ConfigFlowResult:
85 """Reconfigure Sensibo."""
86 errors: dict[str, str] = {}
89 api_key = user_input[CONF_API_KEY]
90 username, errors = await
validate_api(self.hass, api_key)
93 if username == reconfigure_entry.unique_id:
97 CONF_API_KEY: api_key,
100 errors[
"base"] =
"incorrect_api_key"
103 step_id=
"reconfigure",
104 data_schema=DATA_SCHEMA,
109 self, user_input: dict[str, Any] |
None =
None
110 ) -> ConfigFlowResult:
111 """Handle the initial step."""
113 errors: dict[str, str] = {}
116 api_key = user_input[CONF_API_KEY]
117 username, errors = await
validate_api(self.hass, api_key)
124 data={CONF_API_KEY: api_key},
129 data_schema=DATA_SCHEMA,
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reconfigure(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry _get_reauth_entry(self)
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_update_reload_and_abort(self, ConfigEntry entry, *str|None|UndefinedType unique_id=UNDEFINED, str|UndefinedType title=UNDEFINED, Mapping[str, Any]|UndefinedType data=UNDEFINED, Mapping[str, Any]|UndefinedType data_updates=UNDEFINED, Mapping[str, Any]|UndefinedType options=UNDEFINED, str|UndefinedType reason=UNDEFINED, bool reload_even_if_entry_is_unchanged=True)
ConfigEntry _get_reconfigure_entry(self)
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)
tuple[str|None, dict[str, str]] validate_api(HomeAssistant hass, str api_key)
str async_validate_api(HomeAssistant hass, str api_key)