1 """Config flow for tractive integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
10 import voluptuous
as vol
17 from .const
import DOMAIN
19 _LOGGER = logging.getLogger(__name__)
21 USER_DATA_SCHEMA = vol.Schema(
22 {vol.Required(CONF_EMAIL): str, vol.Required(CONF_PASSWORD): str}
26 async
def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
27 """Validate the user input allows us to connect.
29 Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
32 client = aiotractive.api.API(data[CONF_EMAIL], data[CONF_PASSWORD])
34 user_id = await client.user_id()
35 except aiotractive.exceptions.UnauthorizedError
as error:
36 raise InvalidAuth
from error
40 return {
"title": data[CONF_EMAIL],
"user_id": user_id}
44 """Handle a config flow for tractive."""
49 self, user_input: dict[str, Any] |
None =
None
50 ) -> ConfigFlowResult:
51 """Handle the initial step."""
52 if user_input
is None:
60 errors[
"base"] =
"invalid_auth"
62 _LOGGER.exception(
"Unexpected exception")
63 errors[
"base"] =
"unknown"
70 step_id=
"user", data_schema=USER_DATA_SCHEMA, errors=errors
74 self, entry_data: Mapping[str, Any]
75 ) -> ConfigFlowResult:
76 """Handle configuration by re-auth."""
80 self, user_input: dict[str, Any] |
None =
None
81 ) -> ConfigFlowResult:
82 """Dialog that informs the user that reauth is required."""
86 if user_input
is not None:
90 errors[
"base"] =
"invalid_auth"
92 _LOGGER.exception(
"Unexpected exception")
93 errors[
"base"] =
"unknown"
97 await self.hass.config_entries.async_reload(existing_entry.entry_id)
102 step_id=
"reauth_confirm",
103 data_schema=USER_DATA_SCHEMA,
109 """Error to indicate there is invalid auth."""
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_reauth(self, Mapping[str, Any] entry_data)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
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_abort(self, *str reason, 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)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
dict[str, Any] validate_input(HomeAssistant hass, dict[str, Any] data)