1 """Config flow for laundrify integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from laundrify_aio
import LaundrifyAPI
10 from laundrify_aio.exceptions
import (
11 ApiConnectionException,
15 from voluptuous
import Required, Schema
21 from .const
import DOMAIN
23 _LOGGER = logging.getLogger(__name__)
25 CONFIG_SCHEMA =
Schema({Required(CONF_CODE): str})
29 """Handle a config flow for laundrify."""
35 self, user_input: dict[str, Any] |
None =
None
36 ) -> ConfigFlowResult:
37 """Handle a flow initialized by the user."""
41 self, user_input: dict[str, Any] |
None =
None
42 ) -> ConfigFlowResult:
43 """Handle the initial step."""
44 if user_input
is None:
50 access_token = await LaundrifyAPI.exchange_auth_code(user_input[CONF_CODE])
53 api_client = LaundrifyAPI(access_token, session)
55 account_id = await api_client.get_account_id()
57 errors[CONF_CODE] =
"invalid_format"
58 except UnknownAuthCode:
59 errors[CONF_CODE] =
"invalid_auth"
60 except ApiConnectionException:
61 errors[
"base"] =
"cannot_connect"
63 _LOGGER.exception(
"Unexpected exception")
64 errors[
"base"] =
"unknown"
66 entry_data = {CONF_ACCESS_TOKEN: access_token}
78 step_id=
"init", data_schema=CONFIG_SCHEMA, errors=errors
82 self, entry_data: Mapping[str, Any]
83 ) -> ConfigFlowResult:
84 """Perform reauth upon an API authentication error."""
88 self, user_input: dict[str, Any] |
None =
None
89 ) -> ConfigFlowResult:
90 """Dialog that informs the user that reauth is required."""
91 if user_input
is None:
93 step_id=
"reauth_confirm",
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_init(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth_confirm(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|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_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)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)