1 """Config flow for Rachio integration."""
3 from __future__
import annotations
5 from http
import HTTPStatus
9 from rachiopy
import Rachio
10 from requests.exceptions
import ConnectTimeout
11 import voluptuous
as vol
26 DEFAULT_MANUAL_RUN_MINS,
33 _LOGGER = logging.getLogger(__name__)
35 DATA_SCHEMA = vol.Schema({vol.Required(CONF_API_KEY): str}, extra=vol.ALLOW_EXTRA)
39 """Validate the user input allows us to connect.
41 Data has the keys from DATA_SCHEMA with values provided by the user.
43 rachio = Rachio(data[CONF_API_KEY])
46 data = await hass.async_add_executor_job(rachio.person.info)
47 _LOGGER.debug(
"rachio.person.getInfo: %s", data)
48 if int(data[0][KEY_STATUS]) != HTTPStatus.OK:
51 rachio_id = data[1][KEY_ID]
52 data = await hass.async_add_executor_job(rachio.person.get, rachio_id)
53 _LOGGER.debug(
"rachio.person.get: %s", data)
54 if int(data[0][KEY_STATUS]) != HTTPStatus.OK:
57 username = data[1][KEY_USERNAME]
58 except ConnectTimeout
as error:
59 _LOGGER.error(
"Could not reach the Rachio API: %s", error)
60 raise CannotConnect
from error
63 return {
"title": username}
67 """Handle a config flow for Rachio."""
72 self, user_input: dict[str, Any] |
None =
None
73 ) -> ConfigFlowResult:
74 """Handle the initial step."""
76 if user_input
is not None:
83 errors[
"base"] =
"cannot_connect"
85 errors[
"base"] =
"invalid_auth"
87 _LOGGER.exception(
"Unexpected exception")
88 errors[
"base"] =
"unknown"
91 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
95 self, discovery_info: zeroconf.ZeroconfServiceInfo
96 ) -> ConfigFlowResult:
97 """Handle HomeKit discovery."""
100 discovery_info.properties[zeroconf.ATTR_PROPERTIES_ID]
108 config_entry: ConfigEntry,
109 ) -> OptionsFlowHandler:
110 """Get the options flow for this handler."""
115 """Handle a option flow for Rachio."""
118 self, user_input: dict[str, int] |
None =
None
119 ) -> ConfigFlowResult:
120 """Handle options flow."""
121 if user_input
is not None:
124 data_schema = vol.Schema(
127 CONF_MANUAL_RUN_MINS,
129 CONF_MANUAL_RUN_MINS, DEFAULT_MANUAL_RUN_MINS
134 return self.
async_show_formasync_show_form(step_id=
"init", data_schema=data_schema)
138 """Error to indicate we cannot connect."""
141 class InvalidAuth(HomeAssistantError):
142 """Error to indicate there is invalid auth."""
ConfigFlowResult async_step_init(self, dict[str, int]|None user_input=None)
ConfigFlowResult async_step_homekit(self, zeroconf.ZeroconfServiceInfo discovery_info)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
OptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
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_step_user(self, dict[str, Any]|None user_input=None)
None _async_abort_entries_match(self, dict[str, Any]|None match_dict=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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
_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)
def validate_input(HomeAssistant hass, data)