1 """Adds config flow for 17track.net."""
3 from __future__
import annotations
8 from pyseventeentrack
import Client
as SeventeenTrackClient
9 from pyseventeentrack.errors
import SeventeenTrackError
10 import voluptuous
as vol
18 SchemaOptionsFlowHandler,
24 DEFAULT_SHOW_ARCHIVED,
25 DEFAULT_SHOW_DELIVERED,
30 vol.Optional(CONF_SHOW_ARCHIVED, default=DEFAULT_SHOW_ARCHIVED): bool,
31 vol.Optional(CONF_SHOW_DELIVERED, default=DEFAULT_SHOW_DELIVERED): bool,
34 _LOGGER = logging.getLogger(__name__)
36 OPTIONS_SCHEMA = vol.Schema(CONF_SHOW)
41 USER_SCHEMA = vol.Schema(
43 vol.Required(CONF_USERNAME): str,
44 vol.Required(CONF_PASSWORD): str,
50 """17track config flow."""
57 config_entry: ConfigEntry,
58 ) -> SchemaOptionsFlowHandler:
59 """Get options flow for this handler."""
63 self, user_input: dict[str, Any] |
None =
None
64 ) -> ConfigFlowResult:
65 """Handle a flow initialized by the user."""
72 if not await client.profile.login(
73 user_input[CONF_USERNAME], user_input[CONF_PASSWORD]
75 errors[
"base"] =
"invalid_auth"
76 except SeventeenTrackError
as err:
77 _LOGGER.error(
"There was an error while logging in: %s", err)
78 errors[
"base"] =
"cannot_connect"
81 account_id = client.profile.account_id
86 title=user_input[CONF_USERNAME],
89 CONF_SHOW_ARCHIVED: DEFAULT_SHOW_ARCHIVED,
90 CONF_SHOW_DELIVERED: DEFAULT_SHOW_DELIVERED,
96 data_schema=USER_SCHEMA,
102 session = aiohttp_client.async_get_clientsession(self.hass)
103 return SeventeenTrackClient(session=session)
SchemaOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
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|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_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)