1 """Config flow for Blue Current integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from bluecurrent_api
import Client
9 from bluecurrent_api.exceptions
import (
15 import voluptuous
as vol
20 from .const
import DOMAIN, LOGGER
22 DATA_SCHEMA = vol.Schema({vol.Required(CONF_API_TOKEN): str})
26 """Handle the config flow for Blue Current."""
31 self, user_input: dict[str, Any] |
None =
None
32 ) -> ConfigFlowResult:
33 """Handle the initial step."""
35 if user_input
is not None:
37 api_token = user_input[CONF_API_TOKEN]
40 customer_id = await client.validate_api_token(api_token)
41 email = await client.get_email()
42 except WebsocketError:
43 errors[
"base"] =
"cannot_connect"
44 except RequestLimitReached:
45 errors[
"base"] =
"limit_reached"
46 except AlreadyConnected:
47 errors[
"base"] =
"already_connected"
48 except InvalidApiToken:
49 errors[
"base"] =
"invalid_token"
51 LOGGER.exception(
"Unexpected exception")
52 errors[
"base"] =
"unknown"
61 if reauth_entry.unique_id == customer_id:
63 reauth_entry, data=user_input
67 reason=
"wrong_account",
68 description_placeholders={
"email": email},
71 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
75 self, entry_data: Mapping[str, Any]
76 ) -> ConfigFlowResult:
77 """Handle a reauthorization flow request."""
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
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 _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_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)