1 """Config flow for Fujitsu HVAC (based on Ayla IOT) integration."""
3 from collections.abc
import Mapping
7 from ayla_iot_unofficial
import AylaAuthError, new_ayla_api
8 from ayla_iot_unofficial.fujitsu_consts
import FGLAIR_APP_CREDENTIALS
9 import voluptuous
as vol
16 from .const
import API_TIMEOUT, CONF_REGION, DOMAIN, REGION_DEFAULT, REGION_EU
18 _LOGGER = logging.getLogger(__name__)
21 STEP_USER_DATA_SCHEMA = vol.Schema(
23 vol.Required(CONF_USERNAME): str,
24 vol.Required(CONF_PASSWORD): str,
27 options=[region.lower()
for region
in FGLAIR_APP_CREDENTIALS],
28 translation_key=CONF_REGION,
33 STEP_REAUTH_DATA_SCHEMA = vol.Schema(
35 vol.Required(CONF_PASSWORD): str,
41 """Handle a config flow for Fujitsu HVAC (based on Ayla IOT)."""
46 self, user_input: dict[str, Any]
48 errors: dict[str, str] = {}
49 app_id, app_secret = FGLAIR_APP_CREDENTIALS[user_input[CONF_REGION]]
51 user_input[CONF_USERNAME],
52 user_input[CONF_PASSWORD],
55 europe=user_input[CONF_REGION] == REGION_EU,
56 websession=aiohttp_client.async_get_clientsession(self.hass),
60 await api.async_sign_in()
62 errors[
"base"] =
"cannot_connect"
64 errors[
"base"] =
"invalid_auth"
66 _LOGGER.exception(
"Unexpected exception")
67 errors[
"base"] =
"unknown"
72 self, user_input: dict[str, Any] |
None =
None
73 ) -> ConfigFlowResult:
74 """Handle the initial step."""
75 errors: dict[str, str] = {}
83 title=f
"FGLair ({user_input[CONF_USERNAME]})",
88 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
92 self, entry_data: Mapping[str, Any]
93 ) -> ConfigFlowResult:
94 """Perform reauth upon an API authentication error."""
98 self, user_input: dict[str, Any] |
None =
None
99 ) -> ConfigFlowResult:
100 """Dialog that informs the user that reauth is required."""
101 errors: dict[str, str] = {}
106 reauth_entry.data | user_input
111 reauth_entry, data_updates=user_input
115 step_id=
"reauth_confirm",
116 data_schema=STEP_REAUTH_DATA_SCHEMA,
117 description_placeholders={
118 CONF_USERNAME: reauth_entry.data[CONF_USERNAME],
119 **self.context[
"title_placeholders"],
dict[str, str] _async_validate_credentials(self, dict[str, Any] user_input)
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_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 _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)
_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)