1 """Config flow to configure the RainMachine component."""
3 from __future__
import annotations
7 from regenmaschine
import Client
8 from regenmaschine.controller
import Controller
9 from regenmaschine.errors
import RainMachineError
10 import voluptuous
as vol
24 CONF_ALLOW_INACTIVE_ZONES_TO_RUN,
25 CONF_DEFAULT_ZONE_RUN_TIME,
26 CONF_USE_APP_RUN_TIMES,
35 """Return the first local controller."""
36 return next(iter(client.controllers.values()))
40 hass: HomeAssistant, ip_address: str, password: str, port: int, ssl: bool
41 ) -> Controller |
None:
42 """Auth and fetch the mac address from the controller."""
43 websession = aiohttp_client.async_get_clientsession(hass)
44 client = Client(session=websession)
46 await client.load_local(ip_address, password, port=port, use_ssl=ssl)
47 except RainMachineError:
54 """Handle a RainMachine config flow."""
58 discovered_ip_address: str |
None =
None
63 config_entry: ConfigEntry,
64 ) -> RainMachineOptionsFlowHandler:
65 """Define the config flow to handle options."""
69 self, discovery_info: zeroconf.ZeroconfServiceInfo
70 ) -> ConfigFlowResult:
71 """Handle a flow initialized by homekit discovery."""
75 self, discovery_info: zeroconf.ZeroconfServiceInfo
76 ) -> ConfigFlowResult:
77 """Handle discovery via zeroconf."""
81 self, discovery_info: zeroconf.ZeroconfServiceInfo
82 ) -> ConfigFlowResult:
83 """Handle discovery via zeroconf."""
84 ip_address = discovery_info.host
93 entry.data[CONF_PASSWORD],
94 entry.data[CONF_PORT],
95 entry.data.get(CONF_SSL,
True),
99 updates={CONF_IP_ADDRESS: ip_address}, reload_on_update=
False
113 """Generate schema."""
117 vol.Required(CONF_PASSWORD): str,
118 vol.Optional(CONF_PORT, default=DEFAULT_PORT): int,
123 self, user_input: dict[str, Any] |
None =
None
124 ) -> ConfigFlowResult:
125 """Handle the start of the config flow."""
129 {CONF_IP_ADDRESS: user_input[CONF_IP_ADDRESS]}
133 user_input[CONF_IP_ADDRESS],
134 user_input[CONF_PASSWORD],
135 user_input[CONF_PORT],
136 user_input.get(CONF_SSL,
True),
146 title=controller.name.capitalize(),
148 CONF_IP_ADDRESS: user_input[CONF_IP_ADDRESS],
149 CONF_PASSWORD: user_input[CONF_PASSWORD],
150 CONF_PORT: user_input[CONF_PORT],
151 CONF_SSL: user_input.get(CONF_SSL,
True),
152 CONF_DEFAULT_ZONE_RUN_TIME: user_input.get(
153 CONF_DEFAULT_ZONE_RUN_TIME, DEFAULT_ZONE_RUN
158 errors = {CONF_PASSWORD:
"invalid_auth"}
169 """Handle a RainMachine options flow."""
172 self, user_input: dict[str, Any] |
None =
None
173 ) -> ConfigFlowResult:
174 """Manage the options."""
175 if user_input
is not None:
180 data_schema=vol.Schema(
183 CONF_DEFAULT_ZONE_RUN_TIME,
185 CONF_DEFAULT_ZONE_RUN_TIME
189 CONF_USE_APP_RUN_TIMES,
193 CONF_ALLOW_INACTIVE_ZONES_TO_RUN,
195 CONF_ALLOW_INACTIVE_ZONES_TO_RUN
vol.Schema _async_generate_schema(self)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_zeroconf(self, zeroconf.ZeroconfServiceInfo discovery_info)
RainMachineOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_homekit(self, zeroconf.ZeroconfServiceInfo discovery_info)
ConfigFlowResult async_step_homekit_zeroconf(self, zeroconf.ZeroconfServiceInfo discovery_info)
ConfigFlowResult async_step_init(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|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)
list[ConfigEntry] _async_current_entries(self, bool|None include_ignore=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)
Controller get_client_controller(Client client)
Controller|None async_get_controller(HomeAssistant hass, str ip_address, str password, int port, bool ssl)