1 """Config flow for the Hydrawise integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable, Mapping
8 from aiohttp
import ClientError
9 from pydrawise
import auth, client
10 from pydrawise.exceptions
import NotAuthorizedError
11 import voluptuous
as vol
16 from .const
import DOMAIN, LOGGER
20 """Handle a config flow for Hydrawise."""
29 on_failure: Callable[[str], ConfigFlowResult],
30 ) -> ConfigFlowResult:
31 """Create the config entry."""
34 api = client.Hydrawise(auth.Auth(username, password))
37 user = await api.get_user(fetch_zones=
False)
38 except NotAuthorizedError:
39 return on_failure(
"invalid_auth")
41 return on_failure(
"timeout_connect")
42 except ClientError
as ex:
43 LOGGER.error(
"Unable to connect to Hydrawise cloud service: %s", ex)
44 return on_failure(
"cannot_connect")
52 data={CONF_USERNAME: username, CONF_PASSWORD: password},
57 data_updates={CONF_USERNAME: username, CONF_PASSWORD: password},
61 self, user_input: dict[str, Any] |
None =
None
62 ) -> ConfigFlowResult:
63 """Handle the initial setup."""
64 if user_input
is not None:
65 username = user_input[CONF_USERNAME]
66 password = user_input[CONF_PASSWORD]
69 username=username, password=password, on_failure=self.
_show_form_show_form
73 def _show_form(self, error_type: str |
None =
None) -> ConfigFlowResult:
75 if error_type
is not None:
76 errors[
"base"] = error_type
79 data_schema=vol.Schema(
80 {vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
86 self, entry_data: Mapping[str, Any]
87 ) -> ConfigFlowResult:
88 """Perform reauth after updating config to username/password."""
ConfigFlowResult _create_or_update_entry(self, str username, str password, *Callable[[str], ConfigFlowResult] on_failure)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult _show_form(self, str|None error_type=None)
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_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)