1 """Config flow to configure Motionblinds using their WLAN API."""
3 from __future__
import annotations
7 from motionblinds
import MotionDiscovery, MotionGateway
8 import voluptuous
as vol
26 DEFAULT_WAIT_FOR_PUSH,
29 from .gateway
import ConnectMotionGateway
31 CONFIG_SCHEMA = vol.Schema(
33 vol.Optional(CONF_HOST): str,
39 """Options for the component."""
42 self, user_input: dict[str, Any] |
None =
None
43 ) -> ConfigFlowResult:
44 """Manage the options."""
45 errors: dict[str, str] = {}
46 if user_input
is not None:
49 settings_schema = vol.Schema(
54 CONF_WAIT_FOR_PUSH, DEFAULT_WAIT_FOR_PUSH
61 step_id=
"init", data_schema=settings_schema, errors=errors
66 """Handle a Motionblinds config flow."""
71 """Initialize the Motionblinds flow."""
72 self.
_host_host: str |
None =
None
73 self.
_ips_ips: list[str] = []
79 config_entry: ConfigEntry,
80 ) -> OptionsFlowHandler:
81 """Get the options flow."""
85 self, discovery_info: dhcp.DhcpServiceInfo
86 ) -> ConfigFlowResult:
87 """Handle discovery via dhcp."""
88 mac_address =
format_mac(discovery_info.macaddress).replace(
":",
"")
92 gateway = MotionGateway(ip=discovery_info.ip, key=
"abcd1234-56ef-78")
95 await self.hass.async_add_executor_job(gateway.GetDeviceList)
99 if not gateway.available:
102 short_mac = mac_address[-6:].upper()
103 self.context[
"title_placeholders"] = {
104 "short_mac": short_mac,
105 "ip_address": discovery_info.ip,
112 self, user_input: dict[str, Any] |
None =
None
113 ) -> ConfigFlowResult:
114 """Handle a flow initialized by the user."""
116 if user_input
is not None:
117 self.
_host_host = user_input.get(CONF_HOST)
119 if self.
_host_host
is not None:
123 discover_class = MotionDiscovery()
124 gateways = await self.hass.async_add_executor_job(discover_class.discover)
127 if len(self.
_ips_ips) == 1:
131 if len(self.
_ips_ips) > 1:
134 errors[
"base"] =
"discovery_error"
137 step_id=
"user", data_schema=CONFIG_SCHEMA, errors=errors
141 self, user_input: dict[str, Any] |
None =
None
142 ) -> ConfigFlowResult:
143 """Handle multiple motion gateways found."""
144 if user_input
is not None:
145 self.
_host_host = user_input[
"select_ip"]
148 select_schema = vol.Schema({vol.Required(
"select_ip"): vol.In(self.
_ips_ips)})
153 self, user_input: dict[str, Any] |
None =
None
154 ) -> ConfigFlowResult:
155 """Connect to the Motion Gateway."""
156 errors: dict[str, str] = {}
157 if user_input
is not None:
158 key = user_input[CONF_API_KEY]
161 if not await connect_gateway_class.async_connect_gateway(self.
_host_host, key):
163 motion_gateway = connect_gateway_class.gateway_device
167 self.hass, interface=DEFAULT_INTERFACE
169 multicast_interface = await check_multicast_class.async_check_interface(
173 mac_address = motion_gateway.mac
178 CONF_HOST: self.
_host_host,
180 CONF_INTERFACE: multicast_interface,
185 title=DEFAULT_GATEWAY_NAME,
187 CONF_HOST: self.
_host_host,
189 CONF_INTERFACE: multicast_interface,
195 vol.Required(CONF_API_KEY): vol.All(str, vol.Length(min=16, max=16)),
200 step_id=
"connect", data_schema=self.
_config_settings_config_settings, errors=errors
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_select(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_dhcp(self, dhcp.DhcpServiceInfo discovery_info)
ConfigFlowResult async_step_connect(self, dict[str, Any]|None user_input=None)
OptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
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)
ConfigFlowResult async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=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)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)