1 """Config flow to configure the Tile integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from pytile
import async_login
9 from pytile.errors
import InvalidAuthError, TileError
10 import voluptuous
as vol
16 from .const
import DOMAIN, LOGGER
18 STEP_REAUTH_SCHEMA = vol.Schema(
20 vol.Required(CONF_PASSWORD): str,
24 STEP_USER_SCHEMA = vol.Schema(
26 vol.Required(CONF_USERNAME): str,
27 vol.Required(CONF_PASSWORD): str,
33 """Handle a Tile config flow."""
38 """Initialize the config flow."""
39 self.
_password_password: str |
None =
None
40 self.
_username_username: str |
None =
None
42 async
def _async_verify(self, step_id: str, schema: vol.Schema) -> ConfigFlowResult:
43 """Attempt to authenticate the provided credentials."""
48 session = aiohttp_client.async_get_clientsession(self.hass)
52 except InvalidAuthError:
53 errors[
"base"] =
"invalid_auth"
54 except TileError
as err:
55 LOGGER.error(
"Unknown Tile error: %s", err)
56 errors[
"base"] =
"unknown"
60 step_id=step_id, data_schema=schema, errors=errors
63 data = {CONF_USERNAME: self.
_username_username, CONF_PASSWORD: self.
_password_password}
66 self.hass.config_entries.async_update_entry(existing_entry, data=data)
67 self.hass.async_create_task(
68 self.hass.config_entries.async_reload(existing_entry.entry_id)
75 """Import a config entry from configuration.yaml."""
79 self, entry_data: Mapping[str, Any]
80 ) -> ConfigFlowResult:
81 """Handle configuration by re-auth."""
86 self, user_input: dict[str, str] |
None =
None
87 ) -> ConfigFlowResult:
88 """Handle re-auth completion."""
91 step_id=
"reauth_confirm", data_schema=STEP_REAUTH_SCHEMA
96 return await self.
_async_verify_async_verify(
"reauth_confirm", STEP_REAUTH_SCHEMA)
99 self, user_input: dict[str, Any] |
None =
None
100 ) -> ConfigFlowResult:
101 """Handle the start of the config flow."""
108 self.
_username_username = user_input[CONF_USERNAME]
109 self.
_password_password = user_input[CONF_PASSWORD]
111 return await self.
_async_verify_async_verify(
"user", STEP_USER_SCHEMA)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, str]|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)
ConfigFlowResult _async_verify(self, str step_id, vol.Schema schema)
ConfigFlowResult async_step_import(self, dict[str, Any] import_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_step_user(self, dict[str, Any]|None user_input=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)