1 """Config flow to configure StarLine component."""
3 from __future__
import annotations
5 from starline
import StarlineAuth
6 import voluptuous
as vol
30 """Handle a StarLine config flow."""
40 """Initialize flow."""
41 self.
_app_id_app_id: str |
None =
None
43 self.
_username_username: str |
None =
None
44 self.
_password_password: str |
None =
None
45 self.
_mfa_code_mfa_code: str |
None =
None
54 self.
_auth_auth = StarlineAuth()
57 self, user_input: dict[str, str] |
None =
None
58 ) -> ConfigFlowResult:
59 """Handle a flow initialized by the user."""
63 self, user_input: dict[str, str] |
None =
None
64 ) -> ConfigFlowResult:
65 """Authenticate application step."""
66 if user_input
is not None:
67 self.
_app_id_app_id = user_input[CONF_APP_ID]
73 self, user_input: dict[str, str] |
None =
None
74 ) -> ConfigFlowResult:
75 """Authenticate user step."""
76 if user_input
is not None:
83 self, user_input: dict[str, str] |
None =
None
84 ) -> ConfigFlowResult:
85 """Authenticate mfa step."""
86 if user_input
is not None:
92 self, user_input: dict[str, str] |
None =
None
93 ) -> ConfigFlowResult:
94 """Captcha verification step."""
95 if user_input
is not None:
102 """Authenticate application form."""
103 errors: dict[str, str] = {}
104 if error
is not None:
105 errors[
"base"] = error
109 data_schema=vol.Schema(
112 CONF_APP_ID, default=self.
_app_id_app_id
or vol.UNDEFINED
115 CONF_APP_SECRET, default=self.
_app_secret_app_secret
or vol.UNDEFINED
124 """Authenticate user form."""
126 if error
is not None:
127 errors[
"base"] = error
131 data_schema=vol.Schema(
134 CONF_USERNAME, default=self.
_username_username
or vol.UNDEFINED
137 CONF_PASSWORD, default=self.
_password_password
or vol.UNDEFINED
146 """Authenticate mfa form."""
148 if error
is not None:
149 errors[
"base"] = error
153 data_schema=vol.Schema(
156 CONF_MFA_CODE, default=self.
_mfa_code_mfa_code
or vol.UNDEFINED
161 description_placeholders={
"phone_number": self.
_phone_number_phone_number},
166 """Captcha verification form."""
168 if error
is not None:
169 errors[
"base"] = error
172 step_id=
"auth_captcha",
173 data_schema=vol.Schema(
176 CONF_CAPTCHA_CODE, default=self.
_captcha_code_captcha_code
or vol.UNDEFINED
181 description_placeholders={
182 "captcha_img":
'<img src="' + self.
_captcha_image_captcha_image +
'"/>'
187 self, error: str |
None =
None
188 ) -> ConfigFlowResult:
189 """Authenticate application."""
191 self.
_app_code_app_code = await self.hass.async_add_executor_job(
194 self.
_app_token_app_token = await self.hass.async_add_executor_job(
198 except Exception
as err:
199 _LOGGER.error(
"Error auth StarLine: %s", err)
203 self, error: str |
None =
None
204 ) -> ConfigFlowResult:
205 """Authenticate user."""
207 state, data = await self.hass.async_add_executor_job(
208 self.
_auth_auth.get_slid_user_token,
218 self.
_user_slid_user_slid = data[
"user_token"]
224 error = ERROR_AUTH_MFA
227 if "captchaSid" in data:
232 raise Exception(data)
233 except Exception
as err:
234 _LOGGER.error(
"Error auth user: %s", err)
243 ) = await self.hass.async_add_executor_job(
248 title=f
"Application {self._app_id}",
250 DATA_USER_ID: self.
_user_id_user_id,
ConfigFlowResult _async_get_entry(self)
ConfigFlowResult _async_form_auth_captcha(self, str|None error=None)
ConfigFlowResult _async_authenticate_app(self, str|None error=None)
ConfigFlowResult async_step_auth_app(self, dict[str, str]|None user_input=None)
ConfigFlowResult async_step_auth_user(self, dict[str, str]|None user_input=None)
ConfigFlowResult _async_form_auth_user(self, str|None error=None)
ConfigFlowResult _async_form_auth_mfa(self, str|None error=None)
ConfigFlowResult async_step_auth_mfa(self, dict[str, str]|None user_input=None)
ConfigFlowResult async_step_auth_captcha(self, dict[str, str]|None user_input=None)
ConfigFlowResult _async_authenticate_user(self, str|None error=None)
ConfigFlowResult _async_form_auth_app(self, str|None error=None)
ConfigFlowResult async_step_user(self, dict[str, str]|None user_input=None)
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)