1 """Config flow for Vodafone Station integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from aiovodafone
import VodafoneStationSercommApi, exceptions
as aiovodafone_exceptions
9 import voluptuous
as vol
13 DEFAULT_CONSIDER_HOME,
24 from .const
import _LOGGER, DEFAULT_HOST, DEFAULT_USERNAME, DOMAIN
28 """Return user form schema."""
29 user_input = user_input
or {}
32 vol.Optional(CONF_HOST, default=DEFAULT_HOST): str,
33 vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): str,
34 vol.Required(CONF_PASSWORD): str,
39 STEP_REAUTH_DATA_SCHEMA = vol.Schema({vol.Required(CONF_PASSWORD): str})
42 async
def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, str]:
43 """Validate the user input allows us to connect."""
45 api = VodafoneStationSercommApi(
46 data[CONF_HOST], data[CONF_USERNAME], data[CONF_PASSWORD]
55 return {
"title": data[CONF_HOST]}
59 """Handle a config flow for Vodafone Station."""
66 config_entry: ConfigEntry,
67 ) -> VodafoneStationOptionsFlowHandler:
68 """Get the options flow for this handler."""
72 self, user_input: dict[str, Any] |
None =
None
73 ) -> ConfigFlowResult:
74 """Handle the initial step."""
75 if user_input
is None:
87 except aiovodafone_exceptions.AlreadyLogged:
88 errors[
"base"] =
"already_logged"
89 except aiovodafone_exceptions.CannotConnect:
90 errors[
"base"] =
"cannot_connect"
91 except aiovodafone_exceptions.CannotAuthenticate:
92 errors[
"base"] =
"invalid_auth"
93 except aiovodafone_exceptions.ModelNotSupported:
94 errors[
"base"] =
"model_not_supported"
96 _LOGGER.exception(
"Unexpected exception")
97 errors[
"base"] =
"unknown"
106 self, entry_data: Mapping[str, Any]
107 ) -> ConfigFlowResult:
108 """Handle reauth flow."""
109 self.context[
"title_placeholders"] = {
"host": entry_data[CONF_HOST]}
113 self, user_input: dict[str, Any] |
None =
None
114 ) -> ConfigFlowResult:
115 """Handle reauth confirm."""
119 if user_input
is not None:
121 await
validate_input(self.hass, {**reauth_entry.data, **user_input})
122 except aiovodafone_exceptions.AlreadyLogged:
123 errors[
"base"] =
"already_logged"
124 except aiovodafone_exceptions.CannotConnect:
125 errors[
"base"] =
"cannot_connect"
126 except aiovodafone_exceptions.CannotAuthenticate:
127 errors[
"base"] =
"invalid_auth"
129 _LOGGER.exception(
"Unexpected exception")
130 errors[
"base"] =
"unknown"
135 CONF_PASSWORD: user_input[CONF_PASSWORD],
140 step_id=
"reauth_confirm",
141 description_placeholders={CONF_HOST: reauth_entry.data[CONF_HOST]},
142 data_schema=STEP_REAUTH_DATA_SCHEMA,
148 """Handle a option flow."""
151 self, user_input: dict[str, Any] |
None =
None
152 ) -> ConfigFlowResult:
153 """Handle options flow."""
155 if user_input
is not None:
158 data_schema = vol.Schema(
163 CONF_CONSIDER_HOME, DEFAULT_CONSIDER_HOME.total_seconds()
165 ): vol.All(vol.Coerce(int), vol.Clamp(min=0, max=900))
168 return self.
async_show_formasync_show_form(step_id=
"init", data_schema=data_schema)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
VodafoneStationOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_init(self, dict[str, Any]|None user_input=None)
ConfigEntry _get_reauth_entry(self)
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 _async_abort_entries_match(self, dict[str, Any]|None match_dict=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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
_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, str] validate_input(HomeAssistant hass, dict[str, Any] data)
vol.Schema user_form_schema(dict[str, Any]|None user_input)