mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Improve config flow type hints in starline (#125202)
This commit is contained in:
parent
186c9aa33b
commit
643fd34478
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from starline import StarlineAuth
|
from starline import StarlineAuth
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -33,6 +31,10 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
|
_app_code: str
|
||||||
|
_app_token: str
|
||||||
|
_captcha_image: str
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize flow."""
|
"""Initialize flow."""
|
||||||
self._app_id: str | None = None
|
self._app_id: str | None = None
|
||||||
@ -41,59 +43,64 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
self._password: str | None = None
|
self._password: str | None = None
|
||||||
self._mfa_code: str | None = None
|
self._mfa_code: str | None = None
|
||||||
|
|
||||||
self._app_code = None
|
|
||||||
self._app_token = None
|
|
||||||
self._user_slid = None
|
self._user_slid = None
|
||||||
self._user_id = None
|
self._user_id = None
|
||||||
self._slnet_token = None
|
self._slnet_token = None
|
||||||
self._slnet_token_expires = None
|
self._slnet_token_expires = None
|
||||||
self._captcha_image = None
|
self._captcha_sid: str | None = None
|
||||||
self._captcha_sid = None
|
self._captcha_code: str | None = None
|
||||||
self._captcha_code = None
|
|
||||||
self._phone_number = None
|
self._phone_number = None
|
||||||
|
|
||||||
self._auth = StarlineAuth()
|
self._auth = StarlineAuth()
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, str] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle a flow initialized by the user."""
|
"""Handle a flow initialized by the user."""
|
||||||
return await self.async_step_auth_app(user_input)
|
return await self.async_step_auth_app(user_input)
|
||||||
|
|
||||||
async def async_step_auth_app(self, user_input=None, error=None):
|
async def async_step_auth_app(
|
||||||
|
self, user_input: dict[str, str] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
"""Authenticate application step."""
|
"""Authenticate application step."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
self._app_id = user_input[CONF_APP_ID]
|
self._app_id = user_input[CONF_APP_ID]
|
||||||
self._app_secret = user_input[CONF_APP_SECRET]
|
self._app_secret = user_input[CONF_APP_SECRET]
|
||||||
return await self._async_authenticate_app(error)
|
return await self._async_authenticate_app()
|
||||||
return self._async_form_auth_app(error)
|
return self._async_form_auth_app()
|
||||||
|
|
||||||
async def async_step_auth_user(self, user_input=None, error=None):
|
async def async_step_auth_user(
|
||||||
|
self, user_input: dict[str, str] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
"""Authenticate user step."""
|
"""Authenticate user step."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
self._username = user_input[CONF_USERNAME]
|
self._username = user_input[CONF_USERNAME]
|
||||||
self._password = user_input[CONF_PASSWORD]
|
self._password = user_input[CONF_PASSWORD]
|
||||||
return await self._async_authenticate_user(error)
|
return await self._async_authenticate_user()
|
||||||
return self._async_form_auth_user(error)
|
return self._async_form_auth_user()
|
||||||
|
|
||||||
async def async_step_auth_mfa(self, user_input=None, error=None):
|
async def async_step_auth_mfa(
|
||||||
|
self, user_input: dict[str, str] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
"""Authenticate mfa step."""
|
"""Authenticate mfa step."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
self._mfa_code = user_input[CONF_MFA_CODE]
|
self._mfa_code = user_input[CONF_MFA_CODE]
|
||||||
return await self._async_authenticate_user(error)
|
return await self._async_authenticate_user()
|
||||||
return self._async_form_auth_mfa(error)
|
return self._async_form_auth_mfa()
|
||||||
|
|
||||||
async def async_step_auth_captcha(self, user_input=None, error=None):
|
async def async_step_auth_captcha(
|
||||||
|
self, user_input: dict[str, str] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
"""Captcha verification step."""
|
"""Captcha verification step."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
self._captcha_code = user_input[CONF_CAPTCHA_CODE]
|
self._captcha_code = user_input[CONF_CAPTCHA_CODE]
|
||||||
return await self._async_authenticate_user(error)
|
return await self._async_authenticate_user()
|
||||||
return self._async_form_auth_captcha(error)
|
return self._async_form_auth_captcha()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_form_auth_app(self, error=None):
|
def _async_form_auth_app(self, error: str | None = None) -> ConfigFlowResult:
|
||||||
"""Authenticate application form."""
|
"""Authenticate application form."""
|
||||||
errors = {}
|
errors: dict[str, str] = {}
|
||||||
if error is not None:
|
if error is not None:
|
||||||
errors["base"] = error
|
errors["base"] = error
|
||||||
|
|
||||||
@ -113,7 +120,7 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_form_auth_user(self, error=None):
|
def _async_form_auth_user(self, error: str | None = None) -> ConfigFlowResult:
|
||||||
"""Authenticate user form."""
|
"""Authenticate user form."""
|
||||||
errors = {}
|
errors = {}
|
||||||
if error is not None:
|
if error is not None:
|
||||||
@ -135,7 +142,7 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_form_auth_mfa(self, error=None):
|
def _async_form_auth_mfa(self, error: str | None = None) -> ConfigFlowResult:
|
||||||
"""Authenticate mfa form."""
|
"""Authenticate mfa form."""
|
||||||
errors = {}
|
errors = {}
|
||||||
if error is not None:
|
if error is not None:
|
||||||
@ -155,7 +162,7 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_form_auth_captcha(self, error=None):
|
def _async_form_auth_captcha(self, error: str | None = None) -> ConfigFlowResult:
|
||||||
"""Captcha verification form."""
|
"""Captcha verification form."""
|
||||||
errors = {}
|
errors = {}
|
||||||
if error is not None:
|
if error is not None:
|
||||||
@ -176,7 +183,9 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _async_authenticate_app(self, error=None):
|
async def _async_authenticate_app(
|
||||||
|
self, error: str | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
"""Authenticate application."""
|
"""Authenticate application."""
|
||||||
try:
|
try:
|
||||||
self._app_code = await self.hass.async_add_executor_job(
|
self._app_code = await self.hass.async_add_executor_job(
|
||||||
@ -190,7 +199,9 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
_LOGGER.error("Error auth StarLine: %s", err)
|
_LOGGER.error("Error auth StarLine: %s", err)
|
||||||
return self._async_form_auth_app(ERROR_AUTH_APP)
|
return self._async_form_auth_app(ERROR_AUTH_APP)
|
||||||
|
|
||||||
async def _async_authenticate_user(self, error=None):
|
async def _async_authenticate_user(
|
||||||
|
self, error: str | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
"""Authenticate user."""
|
"""Authenticate user."""
|
||||||
try:
|
try:
|
||||||
state, data = await self.hass.async_add_executor_job(
|
state, data = await self.hass.async_add_executor_job(
|
||||||
@ -223,7 +234,7 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
_LOGGER.error("Error auth user: %s", err)
|
_LOGGER.error("Error auth user: %s", err)
|
||||||
return self._async_form_auth_user(ERROR_AUTH_USER)
|
return self._async_form_auth_user(ERROR_AUTH_USER)
|
||||||
|
|
||||||
async def _async_get_entry(self):
|
async def _async_get_entry(self) -> ConfigFlowResult:
|
||||||
"""Create entry."""
|
"""Create entry."""
|
||||||
(
|
(
|
||||||
self._slnet_token,
|
self._slnet_token,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user