1 """Adds config flow for Yale Smart Alarm integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 import voluptuous
as vol
9 from yalesmartalarmclient.client
import YaleSmartAlarmClient
10 from yalesmartalarmclient.exceptions
import AuthenticationError
24 CONF_LOCK_CODE_DIGITS,
31 DATA_SCHEMA = vol.Schema(
33 vol.Required(CONF_USERNAME): cv.string,
34 vol.Required(CONF_PASSWORD): cv.string,
35 vol.Required(CONF_AREA_ID, default=DEFAULT_AREA_ID): cv.string,
39 DATA_SCHEMA_AUTH = vol.Schema(
41 vol.Required(CONF_PASSWORD): cv.string,
45 OPTIONS_SCHEMA = vol.Schema(
48 CONF_LOCK_CODE_DIGITS,
55 """Validate credentials."""
56 errors: dict[str, str] = {}
58 YaleSmartAlarmClient(username, password)
59 except AuthenticationError:
60 errors = {
"base":
"invalid_auth"}
61 except YALE_BASE_ERRORS:
62 errors = {
"base":
"cannot_connect"}
67 """Handle a config flow for Yale integration."""
74 """Get the options flow for this handler."""
78 self, entry_data: Mapping[str, Any]
79 ) -> ConfigFlowResult:
80 """Handle initiation of re-authentication with Yale."""
84 self, user_input: dict[str, Any] |
None =
None
85 ) -> ConfigFlowResult:
86 """Dialog that informs the user that reauth is required."""
87 errors: dict[str, str] = {}
89 if user_input
is not None:
91 username = reauth_entry.data[CONF_USERNAME]
92 password = user_input[CONF_PASSWORD]
94 errors = await self.hass.async_add_executor_job(
95 validate_credentials, username, password
100 data_updates={CONF_PASSWORD: password},
104 step_id=
"reauth_confirm",
105 data_schema=DATA_SCHEMA_AUTH,
110 self, user_input: dict[str, Any] |
None =
None
111 ) -> ConfigFlowResult:
112 """Handle reconfiguration of existing entry."""
113 errors: dict[str, str] = {}
115 if user_input
is not None:
117 username = user_input[CONF_USERNAME]
119 errors = await self.hass.async_add_executor_job(
120 validate_credentials, username, user_input[CONF_PASSWORD]
123 username != reconfigure_entry.unique_id
126 errors[
"base"] =
"unique_id_exists"
131 data_updates=user_input,
135 step_id=
"reconfigure",
136 data_schema=DATA_SCHEMA,
141 self, user_input: dict[str, Any] |
None =
None
142 ) -> ConfigFlowResult:
143 """Handle the initial step."""
144 errors: dict[str, str] = {}
146 if user_input
is not None:
147 username = user_input[CONF_USERNAME]
148 password = user_input[CONF_PASSWORD]
150 area = user_input.get(CONF_AREA_ID, DEFAULT_AREA_ID)
152 errors = await self.hass.async_add_executor_job(
153 validate_credentials, username, password
162 CONF_USERNAME: username,
163 CONF_PASSWORD: password,
171 data_schema=DATA_SCHEMA,
177 """Handle Yale options."""
180 self, user_input: dict[str, Any] |
None =
None
181 ) -> ConfigFlowResult:
182 """Manage Yale options."""
184 if user_input
is not None:
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)
ConfigFlowResult async_step_reconfigure(self, dict[str, Any]|None user_input=None)
YaleOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_init(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)
ConfigEntry _get_reconfigure_entry(self)
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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
vol.Schema add_suggested_values_to_schema(self, vol.Schema data_schema, Mapping[str, Any]|None suggested_values)
_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)
dict[str, Any] validate_credentials(str username, str password)