1 """Config flow for Sure Petcare integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
10 from surepy.exceptions
import SurePetcareAuthenticationError, SurePetcareError
11 import voluptuous
as vol
17 from .const
import DOMAIN, SURE_API_TIMEOUT
19 _LOGGER = logging.getLogger(__name__)
21 USER_DATA_SCHEMA = vol.Schema(
23 vol.Required(CONF_USERNAME): str,
24 vol.Required(CONF_PASSWORD): str,
30 """Handle a config flow for Sure Petcare."""
35 self, user_input: dict[str, Any] |
None =
None
36 ) -> ConfigFlowResult:
37 """Handle the initial step."""
39 if user_input
is not None:
40 client = surepy.Surepy(
41 user_input[CONF_USERNAME],
42 user_input[CONF_PASSWORD],
44 api_timeout=SURE_API_TIMEOUT,
48 token = await client.sac.get_token()
49 except SurePetcareAuthenticationError:
50 errors[
"base"] =
"invalid_auth"
51 except SurePetcareError:
52 errors[
"base"] =
"cannot_connect"
54 _LOGGER.exception(
"Unexpected exception")
55 errors[
"base"] =
"unknown"
62 data={**user_input, CONF_TOKEN: token},
66 step_id=
"user", data_schema=USER_DATA_SCHEMA, errors=errors
70 self, entry_data: Mapping[str, Any]
71 ) -> ConfigFlowResult:
72 """Handle configuration by re-auth."""
76 self, user_input: dict[str, Any] |
None =
None
77 ) -> ConfigFlowResult:
78 """Dialog that informs the user that reauth is required."""
81 if user_input
is not None:
82 client = surepy.Surepy(
83 reauth_entry.data[CONF_USERNAME],
84 user_input[CONF_PASSWORD],
86 api_timeout=SURE_API_TIMEOUT,
90 token = await client.sac.get_token()
91 except SurePetcareAuthenticationError:
92 errors[
"base"] =
"invalid_auth"
93 except SurePetcareError:
94 errors[
"base"] =
"cannot_connect"
96 _LOGGER.exception(
"Unexpected exception")
97 errors[
"base"] =
"unknown"
102 CONF_PASSWORD: user_input[CONF_PASSWORD],
108 step_id=
"reauth_confirm",
109 description_placeholders={
"username": reauth_entry.data[CONF_USERNAME]},
110 data_schema=vol.Schema({vol.Required(CONF_PASSWORD): str}),
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
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)
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)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)