1 """Config flow for Prosegur Alarm integration."""
3 from collections.abc
import Mapping
7 from pyprosegur.auth
import COUNTRY, Auth
8 from pyprosegur.installation
import Installation
9 import voluptuous
as vol
17 from .const
import CONF_CONTRACT, DOMAIN
19 _LOGGER = logging.getLogger(__name__)
21 STEP_USER_DATA_SCHEMA = vol.Schema(
23 vol.Required(CONF_USERNAME): str,
24 vol.Required(CONF_PASSWORD): str,
25 vol.Required(CONF_COUNTRY): selector.CountrySelector(
26 selector.CountrySelectorConfig(countries=
list(COUNTRY))
33 """Validate the user input allows us to connect."""
34 session = aiohttp_client.async_get_clientsession(hass)
35 auth = Auth(session, data[CONF_USERNAME], data[CONF_PASSWORD], data[CONF_COUNTRY])
37 contracts = await Installation.list(auth)
38 except ConnectionRefusedError:
39 raise InvalidAuth
from ConnectionRefusedError
40 except ConnectionError:
41 raise CannotConnect
from ConnectionError
42 return auth, contracts
46 """Handle a config flow for Prosegur Alarm."""
51 contracts: list[dict[str, str]]
54 self, user_input: dict[str, Any] |
None =
None
55 ) -> ConfigFlowResult:
56 """Handle the initial step."""
63 errors[
"base"] =
"cannot_connect"
65 errors[
"base"] =
"invalid_auth"
67 _LOGGER.exception(
"Unexpected exception")
68 errors[
"base"] =
"unknown"
74 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
78 self, user_input: Any |
None =
None
79 ) -> ConfigFlowResult:
80 """Let user decide which contract is being setup."""
86 self.
user_inputuser_input[CONF_CONTRACT] = user_input[CONF_CONTRACT]
89 title=f
"Contract {user_input[CONF_CONTRACT]}", data=self.
user_inputuser_input
93 selector.SelectOptionDict(value=c[
"contractId"], label=c[
"description"])
98 step_id=
"choose_contract",
99 data_schema=vol.Schema(
101 vol.Required(CONF_CONTRACT): selector.SelectSelector(
102 selector.SelectSelectorConfig(options=contract_options)
109 self, entry_data: Mapping[str, Any]
110 ) -> ConfigFlowResult:
111 """Handle initiation of re-authentication with Prosegur."""
115 self, user_input: dict[str, str] |
None =
None
116 ) -> ConfigFlowResult:
117 """Handle re-authentication with Prosegur."""
118 errors: dict[str, str] = {}
123 user_input[CONF_COUNTRY] = reauth_entry.data[CONF_COUNTRY]
126 except CannotConnect:
127 errors[
"base"] =
"cannot_connect"
129 errors[
"base"] =
"invalid_auth"
131 _LOGGER.exception(
"Unexpected exception")
132 errors[
"base"] =
"unknown"
137 CONF_USERNAME: user_input[CONF_USERNAME],
138 CONF_PASSWORD: user_input[CONF_PASSWORD],
143 step_id=
"reauth_confirm",
144 data_schema=vol.Schema(
147 CONF_USERNAME, default=reauth_entry.data[CONF_USERNAME]
149 vol.Required(CONF_PASSWORD): str,
157 """Error to indicate we cannot connect."""
161 """Error to indicate there is invalid auth."""
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, str]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_choose_contract(self, 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)
def validate_input(HomeAssistant hass, data)