1 """Config flow for EnergyFlip integration."""
6 from energyflip
import EnergyFlip, EnergyFlipConnectionException, EnergyFlipException
7 import voluptuous
as vol
13 from .const
import DOMAIN
15 _LOGGER = logging.getLogger(__name__)
17 DATA_SCHEMA = vol.Schema(
18 {vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
23 """Handle a config flow for EnergyFlip."""
28 self, user_input: dict[str, Any] |
None =
None
29 ) -> ConfigFlowResult:
30 """Handle a flow initiated by the user."""
31 if user_input
is None:
38 except EnergyFlipConnectionException
as exception:
39 _LOGGER.warning(exception)
40 errors[
"base"] =
"cannot_connect"
41 except EnergyFlipException
as exception:
42 _LOGGER.warning(exception)
43 errors[
"base"] =
"invalid_auth"
47 _LOGGER.exception(
"Unexpected exception")
48 errors[
"base"] =
"unknown"
56 title=user_input[CONF_USERNAME],
59 CONF_USERNAME: user_input[CONF_USERNAME],
60 CONF_PASSWORD: user_input[CONF_PASSWORD],
68 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
or {}
72 """Validate the user input allows us to connect.
74 Data has the keys from DATA_SCHEMA with values provided by the user.
76 username = user_input[CONF_USERNAME]
77 password = user_input[CONF_PASSWORD]
79 energyflip = EnergyFlip(username, password)
82 await energyflip.authenticate()
85 await energyflip.customer_overview()
87 return energyflip.get_user_id()
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
def _show_setup_form(self, user_input, errors=None)
def _validate_input(self, user_input)
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)