1 """Config Flow for Flick Electric integration."""
7 from pyflick.authentication
import AuthException, SimpleFlickAuth
8 from pyflick.const
import DEFAULT_CLIENT_ID, DEFAULT_CLIENT_SECRET
9 import voluptuous
as vol
21 from .const
import DOMAIN
23 _LOGGER = logging.getLogger(__name__)
25 DATA_SCHEMA = vol.Schema(
27 vol.Required(CONF_USERNAME): str,
28 vol.Required(CONF_PASSWORD): str,
29 vol.Optional(CONF_CLIENT_ID): str,
30 vol.Optional(CONF_CLIENT_SECRET): str,
36 """Flick config flow."""
41 auth = SimpleFlickAuth(
42 username=user_input[CONF_USERNAME],
43 password=user_input[CONF_PASSWORD],
44 websession=aiohttp_client.async_get_clientsession(self.hass),
45 client_id=user_input.get(CONF_CLIENT_ID, DEFAULT_CLIENT_ID),
46 client_secret=user_input.get(CONF_CLIENT_SECRET, DEFAULT_CLIENT_SECRET),
50 async
with asyncio.timeout(60):
51 token = await auth.async_get_access_token()
52 except TimeoutError
as err:
53 raise CannotConnect
from err
54 except AuthException
as err:
55 raise InvalidAuth
from err
57 return token
is not None
60 self, user_input: dict[str, Any] |
None =
None
61 ) -> ConfigFlowResult:
62 """Handle gathering login info."""
64 if user_input
is not None:
68 errors[
"base"] =
"cannot_connect"
70 errors[
"base"] =
"invalid_auth"
72 _LOGGER.exception(
"Unexpected exception")
73 errors[
"base"] =
"unknown"
76 f
"flick_electric_{user_input[CONF_USERNAME]}"
81 title=f
"Flick Electric: {user_input[CONF_USERNAME]}",
86 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
91 """Error to indicate we cannot connect."""
94 class InvalidAuth(HomeAssistantError):
95 """Error to indicate there is invalid auth."""
def _validate_input(self, user_input)
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)