1 """Config flow for A. O. Smith integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from py_aosmith
import AOSmithAPIClient, AOSmithInvalidCredentialsException
10 import voluptuous
as vol
16 from .const
import DOMAIN
18 _LOGGER = logging.getLogger(__name__)
22 """Handle a config flow for A. O. Smith."""
29 self, email: str, password: str
31 """Validate the credentials. Return an error string, or None if successful."""
32 session = aiohttp_client.async_get_clientsession(self.hass)
33 client = AOSmithAPIClient(email, password, session)
36 await client.get_devices()
37 except AOSmithInvalidCredentialsException:
40 _LOGGER.exception(
"Unexpected exception")
46 self, user_input: dict[str, Any] |
None =
None
47 ) -> ConfigFlowResult:
48 """Handle the initial step."""
49 errors: dict[str, str] = {}
50 if user_input
is not None:
51 unique_id = user_input[CONF_EMAIL].lower()
56 user_input[CONF_EMAIL], user_input[CONF_PASSWORD]
60 title=user_input[CONF_EMAIL], data=user_input
63 errors[
"base"] = error
67 data_schema=vol.Schema(
69 vol.Required(CONF_EMAIL): str,
70 vol.Required(CONF_PASSWORD): str,
77 self, entry_data: Mapping[str, Any]
78 ) -> ConfigFlowResult:
79 """Perform reauth if the user credentials have changed."""
84 self, user_input: dict[str, Any] |
None =
None
85 ) -> ConfigFlowResult:
86 """Handle user's reauth credentials."""
87 errors: dict[str, str] = {}
89 password = user_input[CONF_PASSWORD]
95 data_updates=user_input,
97 errors[
"base"] = error
100 step_id=
"reauth_confirm",
101 data_schema=vol.Schema({vol.Required(CONF_PASSWORD): str}),
102 description_placeholders={CONF_EMAIL: self.
_reauth_email_reauth_email},
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
str|None _async_validate_credentials(self, str email, str password)
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)