1 """The Things Network's integration config flow."""
3 from collections.abc
import Mapping
7 from ttn_client
import TTNAuthError, TTNClient
8 import voluptuous
as vol
18 from .const
import CONF_APP_ID, DOMAIN, TTN_API_HOST
20 _LOGGER = logging.getLogger(__name__)
24 """Handle a config flow."""
29 self, user_input: Mapping[str, Any] |
None =
None
30 ) -> ConfigFlowResult:
31 """User initiated config flow."""
34 if user_input
is not None:
36 user_input[CONF_HOST],
37 user_input[CONF_APP_ID],
38 user_input[CONF_API_KEY],
42 await client.fetch_data()
44 _LOGGER.exception(
"Error authenticating with The Things Network")
45 errors[
"base"] =
"invalid_auth"
47 _LOGGER.exception(
"Unknown error occurred")
48 errors[
"base"] =
"unknown"
60 title=
str(user_input[CONF_APP_ID]),
69 user_input = {CONF_HOST: TTN_API_HOST}
74 vol.Required(CONF_HOST): str,
75 vol.Required(CONF_APP_ID): str,
78 type=TextSelectorType.PASSWORD, autocomplete=
"api_key"
88 self, entry_data: Mapping[str, Any]
89 ) -> ConfigFlowResult:
90 """Handle a flow initialized by a reauth event."""
94 self, user_input: dict[str, Any] |
None =
None
95 ) -> ConfigFlowResult:
96 """Dialog that informs the user that reauth is required."""
97 if user_input
is None:
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_user(self, Mapping[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth_confirm(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_step_user(self, dict[str, Any]|None user_input=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)
vol.Schema add_suggested_values_to_schema(self, vol.Schema data_schema, Mapping[str, Any]|None suggested_values)
_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)