1 """Config flow for TRIGGERcmd integration."""
3 from __future__
import annotations
9 from triggercmd
import TRIGGERcmdConnectionError, client
10 import voluptuous
as vol
16 from .const
import CONF_TOKEN, DOMAIN
18 _LOGGER = logging.getLogger(__name__)
20 DATA_SCHEMA = vol.Schema({(CONF_TOKEN): str})
24 """Validate the user input allows us to connect.
26 Data has the keys from DATA_SCHEMA with values provided by the user.
28 if len(data[CONF_TOKEN]) < 100:
31 token_data = jwt.decode(data[CONF_TOKEN], options={
"verify_signature":
False})
32 if not token_data[
"id"]:
36 await client.async_connection_test(data[CONF_TOKEN])
37 except Exception
as e:
38 raise TRIGGERcmdConnectionError
from e
40 return token_data[
"id"]
44 """Handle a config flow."""
49 self, user_input: dict[str, Any] |
None =
None
50 ) -> ConfigFlowResult:
51 """Handle the initial step."""
53 if user_input
is not None:
57 errors[CONF_TOKEN] =
"invalid_token"
58 except TRIGGERcmdConnectionError:
59 errors[
"base"] =
"cannot_connect"
61 _LOGGER.exception(
"Unexpected exception")
62 errors[
"base"] =
"unknown"
70 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
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)
str validate_input(HomeAssistant hass, dict data)