1 """Config flow to configure the OVO Energy integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from ovoenergy
import OVOEnergy
10 import voluptuous
as vol
16 from .const
import CONF_ACCOUNT, DOMAIN
18 REAUTH_SCHEMA = vol.Schema({vol.Required(CONF_PASSWORD): str})
19 USER_SCHEMA = vol.Schema(
21 vol.Required(CONF_USERNAME): str,
22 vol.Required(CONF_PASSWORD): str,
23 vol.Optional(CONF_ACCOUNT): str,
29 """Handle a OVO Energy config flow."""
34 """Initialize the flow."""
40 user_input: Mapping[str, Any] |
None =
None,
41 ) -> ConfigFlowResult:
42 """Handle a flow initiated by the user."""
44 if user_input
is not None:
49 if (custom_account := user_input.get(CONF_ACCOUNT))
is not None:
50 client.custom_account_id = custom_account
53 authenticated = await client.authenticate(
54 user_input[CONF_USERNAME],
55 user_input[CONF_PASSWORD],
57 await client.bootstrap_accounts()
58 except aiohttp.ClientError:
59 errors[
"base"] =
"cannot_connect"
66 title=client.username,
68 CONF_USERNAME: user_input[CONF_USERNAME],
69 CONF_PASSWORD: user_input[CONF_PASSWORD],
70 CONF_ACCOUNT: client.account_id,
74 errors[
"base"] =
"invalid_auth"
77 step_id=
"user", data_schema=USER_SCHEMA, errors=errors
82 entry_data: Mapping[str, Any],
83 ) -> ConfigFlowResult:
84 """Handle configuration by re-auth."""
85 self.
usernameusername = entry_data.get(CONF_USERNAME)
86 self.
accountaccount = entry_data.get(CONF_ACCOUNT)
90 self.context[
"title_placeholders"] = {CONF_USERNAME: self.
usernameusername}
96 user_input: Mapping[str, Any] |
None =
None,
97 ) -> ConfigFlowResult:
98 """Handle configuration by re-auth."""
101 if user_input
is not None:
106 if self.
accountaccount
is not None:
107 client.custom_account_id = self.
accountaccount
110 authenticated = await client.authenticate(
112 user_input[CONF_PASSWORD],
114 except aiohttp.ClientError:
115 errors[
"base"] =
"connection_error"
120 data_updates={CONF_PASSWORD: user_input[CONF_PASSWORD]},
123 errors[
"base"] =
"authorization_error"
126 step_id=
"reauth_confirm", data_schema=REAUTH_SCHEMA, errors=errors
ConfigFlowResult async_step_reauth_confirm(self, Mapping[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, Mapping[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
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_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)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)