1 """Config flow for Verisure integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 Error
as VerisureError,
10 LoginError
as VerisureLoginError,
11 ResponseError
as VerisureResponseError,
14 import voluptuous
as vol
28 CONF_LOCK_CODE_DIGITS,
29 DEFAULT_LOCK_CODE_DIGITS,
36 """Handle a config flow for Verisure."""
47 config_entry: ConfigEntry,
48 ) -> VerisureOptionsFlowHandler:
49 """Get the options flow for this handler."""
53 self, user_input: dict[str, Any] |
None =
None
54 ) -> ConfigFlowResult:
55 """Handle the initial step."""
56 errors: dict[str, str] = {}
58 if user_input
is not None:
59 self.
emailemail = user_input[CONF_EMAIL]
60 self.
passwordpassword = user_input[CONF_PASSWORD]
62 username=self.
emailemail,
64 cookie_file_name=self.hass.config.path(
65 STORAGE_DIR, f
"verisure_{user_input[CONF_EMAIL]}"
70 await self.hass.async_add_executor_job(self.
verisureverisure.login)
71 except VerisureLoginError
as ex:
72 if "Multifactor authentication enabled" in str(ex):
74 await self.hass.async_add_executor_job(
80 VerisureResponseError,
83 "Unexpected response from Verisure during MFA set up, %s",
86 errors[
"base"] =
"unknown_mfa"
90 LOGGER.debug(
"Could not log in to Verisure, %s", ex)
91 errors[
"base"] =
"invalid_auth"
92 except (VerisureError, VerisureResponseError)
as ex:
93 LOGGER.debug(
"Unexpected response from Verisure, %s", ex)
94 errors[
"base"] =
"unknown"
100 data_schema=vol.Schema(
102 vol.Required(CONF_EMAIL): str,
103 vol.Required(CONF_PASSWORD): str,
110 self, user_input: dict[str, Any] |
None =
None
111 ) -> ConfigFlowResult:
112 """Handle multifactor authentication step."""
113 errors: dict[str, str] = {}
115 if user_input
is not None:
117 await self.hass.async_add_executor_job(
118 self.
verisureverisure.validate_mfa, user_input[CONF_CODE]
120 except VerisureLoginError
as ex:
121 LOGGER.debug(
"Could not log in to Verisure, %s", ex)
122 errors[
"base"] =
"invalid_auth"
123 except (VerisureError, VerisureResponseError)
as ex:
124 LOGGER.debug(
"Unexpected response from Verisure, %s", ex)
125 errors[
"base"] =
"unknown"
131 data_schema=vol.Schema(
133 vol.Required(CONF_CODE): vol.All(
134 vol.Coerce(str), vol.Length(min=6, max=6)
142 self, user_input: dict[str, Any] |
None =
None
143 ) -> ConfigFlowResult:
144 """Select Verisure installation to add."""
145 installations_data = await self.hass.async_add_executor_job(
146 self.
verisureverisure.get_installations
149 inst[
"giid"]: f
"{inst['alias']} ({inst['address']['street']})"
151 installations_data.get(
"data", {})
153 .
get(
"installations", [])
157 if user_input
is None:
158 if len(installations) != 1:
160 step_id=
"installation",
161 data_schema=vol.Schema(
162 {vol.Required(CONF_GIID): vol.In(installations)}
165 user_input = {CONF_GIID:
list(installations)[0]}
171 title=installations[user_input[CONF_GIID]],
173 CONF_EMAIL: self.
emailemail,
174 CONF_PASSWORD: self.
passwordpassword,
175 CONF_GIID: user_input[CONF_GIID],
180 self, entry_data: Mapping[str, Any]
181 ) -> ConfigFlowResult:
182 """Handle initiation of re-authentication with Verisure."""
186 self, user_input: dict[str, Any] |
None =
None
187 ) -> ConfigFlowResult:
188 """Handle re-authentication with Verisure."""
189 errors: dict[str, str] = {}
191 if user_input
is not None:
192 self.
emailemail = user_input[CONF_EMAIL]
193 self.
passwordpassword = user_input[CONF_PASSWORD]
196 username=self.
emailemail,
198 cookie_file_name=self.hass.config.path(
199 STORAGE_DIR, f
"verisure_{user_input[CONF_EMAIL]}"
204 await self.hass.async_add_executor_job(self.
verisureverisure.login)
205 except VerisureLoginError
as ex:
206 if "Multifactor authentication enabled" in str(ex):
208 await self.hass.async_add_executor_job(
214 VerisureResponseError,
217 "Unexpected response from Verisure during MFA set up, %s",
220 errors[
"base"] =
"unknown_mfa"
224 LOGGER.debug(
"Could not log in to Verisure, %s", ex)
225 errors[
"base"] =
"invalid_auth"
226 except (VerisureError, VerisureResponseError)
as ex:
227 LOGGER.debug(
"Unexpected response from Verisure, %s", ex)
228 errors[
"base"] =
"unknown"
233 CONF_EMAIL: user_input[CONF_EMAIL],
234 CONF_PASSWORD: user_input[CONF_PASSWORD],
239 step_id=
"reauth_confirm",
240 data_schema=vol.Schema(
245 vol.Required(CONF_PASSWORD): str,
252 self, user_input: dict[str, Any] |
None =
None
253 ) -> ConfigFlowResult:
254 """Handle multifactor authentication step during re-authentication."""
255 errors: dict[str, str] = {}
257 if user_input
is not None:
259 await self.hass.async_add_executor_job(
260 self.
verisureverisure.validate_mfa, user_input[CONF_CODE]
262 await self.hass.async_add_executor_job(self.
verisureverisure.login)
263 except VerisureLoginError
as ex:
264 LOGGER.debug(
"Could not log in to Verisure, %s", ex)
265 errors[
"base"] =
"invalid_auth"
266 except (VerisureError, VerisureResponseError)
as ex:
267 LOGGER.debug(
"Unexpected response from Verisure, %s", ex)
268 errors[
"base"] =
"unknown"
273 CONF_EMAIL: self.
emailemail,
274 CONF_PASSWORD: self.
passwordpassword,
279 step_id=
"reauth_mfa",
280 data_schema=vol.Schema(
282 vol.Required(CONF_CODE): vol.All(
284 vol.Length(min=6, max=6),
293 """Handle Verisure options."""
296 self, user_input: dict[str, Any] |
None =
None
297 ) -> ConfigFlowResult:
298 """Manage Verisure options."""
299 errors: dict[str, Any] = {}
301 if user_input
is not None:
306 data_schema=vol.Schema(
309 CONF_LOCK_CODE_DIGITS,
312 CONF_LOCK_CODE_DIGITS, DEFAULT_LOCK_CODE_DIGITS
ConfigFlowResult async_step_mfa(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_installation(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth_mfa(self, dict[str, Any]|None user_input=None)
VerisureOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
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_init(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)
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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
_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)
web.Response get(self, web.Request request, str config_key)