mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07: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 typing import Any
|
||||
|
||||
from starline import StarlineAuth
|
||||
import voluptuous as vol
|
||||
|
||||
@ -33,6 +31,10 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
VERSION = 1
|
||||
|
||||
_app_code: str
|
||||
_app_token: str
|
||||
_captcha_image: str
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize flow."""
|
||||
self._app_id: str | None = None
|
||||
@ -41,59 +43,64 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
self._password: str | None = None
|
||||
self._mfa_code: str | None = None
|
||||
|
||||
self._app_code = None
|
||||
self._app_token = None
|
||||
self._user_slid = None
|
||||
self._user_id = None
|
||||
self._slnet_token = None
|
||||
self._slnet_token_expires = None
|
||||
self._captcha_image = None
|
||||
self._captcha_sid = None
|
||||
self._captcha_code = None
|
||||
self._captcha_sid: str | None = None
|
||||
self._captcha_code: str | None = None
|
||||
self._phone_number = None
|
||||
|
||||
self._auth = StarlineAuth()
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
self, user_input: dict[str, str] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle a flow initialized by the user."""
|
||||
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."""
|
||||
if user_input is not None:
|
||||
self._app_id = user_input[CONF_APP_ID]
|
||||
self._app_secret = user_input[CONF_APP_SECRET]
|
||||
return await self._async_authenticate_app(error)
|
||||
return self._async_form_auth_app(error)
|
||||
return await self._async_authenticate_app()
|
||||
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."""
|
||||
if user_input is not None:
|
||||
self._username = user_input[CONF_USERNAME]
|
||||
self._password = user_input[CONF_PASSWORD]
|
||||
return await self._async_authenticate_user(error)
|
||||
return self._async_form_auth_user(error)
|
||||
return await self._async_authenticate_user()
|
||||
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."""
|
||||
if user_input is not None:
|
||||
self._mfa_code = user_input[CONF_MFA_CODE]
|
||||
return await self._async_authenticate_user(error)
|
||||
return self._async_form_auth_mfa(error)
|
||||
return await self._async_authenticate_user()
|
||||
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."""
|
||||
if user_input is not None:
|
||||
self._captcha_code = user_input[CONF_CAPTCHA_CODE]
|
||||
return await self._async_authenticate_user(error)
|
||||
return self._async_form_auth_captcha(error)
|
||||
return await self._async_authenticate_user()
|
||||
return self._async_form_auth_captcha()
|
||||
|
||||
@callback
|
||||
def _async_form_auth_app(self, error=None):
|
||||
def _async_form_auth_app(self, error: str | None = None) -> ConfigFlowResult:
|
||||
"""Authenticate application form."""
|
||||
errors = {}
|
||||
errors: dict[str, str] = {}
|
||||
if error is not None:
|
||||
errors["base"] = error
|
||||
|
||||
@ -113,7 +120,7 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
|
||||
@callback
|
||||
def _async_form_auth_user(self, error=None):
|
||||
def _async_form_auth_user(self, error: str | None = None) -> ConfigFlowResult:
|
||||
"""Authenticate user form."""
|
||||
errors = {}
|
||||
if error is not None:
|
||||
@ -135,7 +142,7 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
|
||||
@callback
|
||||
def _async_form_auth_mfa(self, error=None):
|
||||
def _async_form_auth_mfa(self, error: str | None = None) -> ConfigFlowResult:
|
||||
"""Authenticate mfa form."""
|
||||
errors = {}
|
||||
if error is not None:
|
||||
@ -155,7 +162,7 @@ class StarlineFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
|
||||
@callback
|
||||
def _async_form_auth_captcha(self, error=None):
|
||||
def _async_form_auth_captcha(self, error: str | None = None) -> ConfigFlowResult:
|
||||
"""Captcha verification form."""
|
||||
errors = {}
|
||||
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."""
|
||||
try:
|
||||
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)
|
||||
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."""
|
||||
try:
|
||||
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)
|
||||
return self._async_form_auth_user(ERROR_AUTH_USER)
|
||||
|
||||
async def _async_get_entry(self):
|
||||
async def _async_get_entry(self) -> ConfigFlowResult:
|
||||
"""Create entry."""
|
||||
(
|
||||
self._slnet_token,
|
||||
|
Loading…
x
Reference in New Issue
Block a user