1 """Config flow for Schlage integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from pyschlage.exceptions
import NotAuthorizedError
10 import voluptuous
as vol
15 from .const
import DOMAIN, LOGGER
17 STEP_USER_DATA_SCHEMA = vol.Schema(
18 {vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
20 STEP_REAUTH_DATA_SCHEMA = vol.Schema({vol.Required(CONF_PASSWORD): str})
24 """Handle a config flow for Schlage."""
29 self, user_input: dict[str, Any] |
None =
None
30 ) -> ConfigFlowResult:
31 """Handle the initial step."""
32 if user_input
is None:
34 username = user_input[CONF_USERNAME].lower()
35 password = user_input[CONF_PASSWORD]
36 user_id, errors = await self.hass.async_add_executor_job(
37 _authenticate, username, password
46 CONF_USERNAME: username,
47 CONF_PASSWORD: password,
52 """Show the user form."""
54 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
58 self, entry_data: Mapping[str, Any]
59 ) -> ConfigFlowResult:
60 """Handle reauth upon an API authentication error."""
64 self, user_input: dict[str, Any] |
None =
None
65 ) -> ConfigFlowResult:
66 """Dialog that informs the user that reauth is required."""
67 if user_input
is None:
71 username = reauth_entry.data[CONF_USERNAME]
72 password = user_input[CONF_PASSWORD]
73 user_id, errors = await self.hass.async_add_executor_job(
74 _authenticate, username, password
83 CONF_USERNAME: username,
84 CONF_PASSWORD: user_input[CONF_PASSWORD],
89 """Show the reauth form."""
91 step_id=
"reauth_confirm",
92 data_schema=STEP_REAUTH_DATA_SCHEMA,
97 def _authenticate(username: str, password: str) -> tuple[str |
None, dict[str, str]]:
98 """Authenticate with the Schlage API."""
100 errors: dict[str, str] = {}
102 auth = pyschlage.Auth(username, password)
104 except NotAuthorizedError:
105 errors[
"base"] =
"invalid_auth"
107 LOGGER.exception(
"Unknown error")
108 errors[
"base"] =
"unknown"
112 user_id = auth.user_id
113 return user_id, errors
ConfigFlowResult _show_reauth_form(self, dict[str, str] errors)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult _show_user_form(self, dict[str, str] errors)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
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)
None _abort_if_unique_id_mismatch(self, *str reason="unique_id_mismatch", Mapping[str, str]|None description_placeholders=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)
tuple[str|None, dict[str, str]] _authenticate(str username, str password)