1 """Config flow for Sense integration."""
3 from collections.abc
import Mapping
4 from functools
import partial
8 from sense_energy
import (
10 SenseAuthenticationException,
11 SenseMFARequiredException,
13 import voluptuous
as vol
19 from .const
import ACTIVE_UPDATE_RATE, DEFAULT_TIMEOUT, DOMAIN, SENSE_CONNECT_EXCEPTIONS
21 _LOGGER = logging.getLogger(__name__)
23 DATA_SCHEMA = vol.Schema(
25 vol.Required(CONF_EMAIL): str,
26 vol.Required(CONF_PASSWORD): str,
27 vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): vol.Coerce(int),
33 """Handle a config flow for Sense."""
37 _gateway: ASyncSenseable
44 """Validate the user input allows us to connect.
46 Data has the keys from DATA_SCHEMA with values provided by the user.
49 timeout = self.
_auth_data_auth_data[CONF_TIMEOUT]
54 self.
_gateway_gateway = await self.hass.async_add_executor_job(
59 client_session=client_session,
62 self.
_gateway_gateway.rate_limit = ACTIVE_UPDATE_RATE
68 """Create the entry from the config data."""
75 if not existing_entry:
83 self, user_input: Mapping[str, Any], errors: dict[str, str]
84 ) -> ConfigFlowResult |
None:
85 """Validate the input and create the entry from the data."""
88 except SenseMFARequiredException:
90 except SENSE_CONNECT_EXCEPTIONS:
91 errors[
"base"] =
"cannot_connect"
92 except SenseAuthenticationException:
93 errors[
"base"] =
"invalid_auth"
95 _LOGGER.exception(
"Unexpected exception")
96 errors[
"base"] =
"unknown"
102 self, user_input: dict[str, str] |
None =
None
103 ) -> ConfigFlowResult:
104 """Handle validation (2fa) step."""
108 await self.
_gateway_gateway.validate_mfa(user_input[CONF_CODE])
109 except SENSE_CONNECT_EXCEPTIONS:
110 errors[
"base"] =
"cannot_connect"
111 except SenseAuthenticationException:
112 errors[
"base"] =
"invalid_auth"
114 _LOGGER.exception(
"Unexpected exception")
115 errors[
"base"] =
"unknown"
120 step_id=
"validation",
121 data_schema=vol.Schema({vol.Required(CONF_CODE): vol.All(str, vol.Strip)}),
126 self, user_input: dict[str, Any] |
None =
None
127 ) -> ConfigFlowResult:
128 """Handle the initial step."""
129 errors: dict[str, str] = {}
130 if user_input
is not None:
135 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
139 self, entry_data: Mapping[str, Any]
140 ) -> ConfigFlowResult:
141 """Handle configuration by re-auth."""
146 self, user_input: Mapping[str, Any]
147 ) -> ConfigFlowResult:
148 """Handle reauth and validation."""
149 errors: dict[str, str] = {}
150 if user_input
is not None:
155 step_id=
"reauth_validate",
156 data_schema=vol.Schema({vol.Required(CONF_PASSWORD): str}),
158 description_placeholders={
159 CONF_EMAIL: self.
_auth_data_auth_data[CONF_EMAIL],
ConfigFlowResult create_entry_from_data(self)
ConfigFlowResult async_step_reauth_validate(self, Mapping[str, Any] user_input)
ConfigFlowResult async_step_validation(self, dict[str, str]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult|None validate_input_and_create_entry(self, Mapping[str, Any] user_input, dict[str, str] errors)
None validate_input(self, Mapping[str, Any] data)
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)
IssData update(pyiss.ISS iss)
dict[str, str|bool] authenticate(HomeAssistant hass, str host, str security_code)
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)