1 """Config flow for iotawatt integration."""
3 from __future__
import annotations
8 from iotawattpy.iotawatt
import Iotawatt
9 import voluptuous
as vol
17 from .const
import CONNECTION_ERRORS, DOMAIN
19 _LOGGER = logging.getLogger(__name__)
22 async
def validate_input(hass: HomeAssistant, data: dict[str, str]) -> dict[str, str]:
23 """Validate the user input allows us to connect."""
27 httpx_client.get_async_client(hass),
28 data.get(CONF_USERNAME),
29 data.get(CONF_PASSWORD),
32 is_connected = await iotawatt.connect()
33 except CONNECTION_ERRORS:
34 return {
"base":
"cannot_connect"}
36 _LOGGER.exception(
"Unexpected exception")
37 return {
"base":
"unknown"}
40 return {
"base":
"invalid_auth"}
46 """Handle a config flow for iotawatt."""
52 self._data: dict[str, Any] = {}
55 self, user_input: dict[str, Any] |
None =
None
56 ) -> ConfigFlowResult:
57 """Handle the initial step."""
58 if user_input
is None:
63 vol.Required(CONF_HOST, default=user_input.get(CONF_HOST,
"")): str,
72 if errors == {
"base":
"invalid_auth"}:
73 self._data.
update(user_input)
79 self, user_input: dict[str, Any] |
None =
None
80 ) -> ConfigFlowResult:
81 """Authenticate user if authentication is enabled on the IoTaWatt device."""
82 if user_input
is None:
85 data_schema = vol.Schema(
88 CONF_USERNAME, default=user_input.get(CONF_USERNAME,
"")
91 CONF_PASSWORD, default=user_input.get(CONF_PASSWORD,
"")
98 data = {**self._data, **user_input}
102 step_id=
"auth", data_schema=data_schema, errors=errors
109 """Error to indicate we cannot connect."""
112 class InvalidAuth(HomeAssistantError):
113 """Error to indicate there is invalid auth."""
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_auth(self, dict[str, Any]|None user_input=None)
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)
dict[str, str] validate_input(HomeAssistant hass, dict[str, str] data)
IssData update(pyiss.ISS iss)