1 """Config flow for Vogel's MotionMount."""
8 import voluptuous
as vol
12 DEFAULT_DISCOVERY_UNIQUE_ID,
19 from .const
import DOMAIN, EMPTY_MAC
21 _LOGGER = logging.getLogger(__name__)
31 """Handle a Vogel's MotionMount config flow."""
36 """Set up the instance."""
37 self.discovery_info: dict[str, Any] = {}
40 self, user_input: dict[str, Any] |
None =
None
41 ) -> ConfigFlowResult:
42 """Handle a flow initiated by the user."""
43 if user_input
is None:
49 except (ConnectionError, socket.gaierror):
53 except motionmount.NotConnectedError:
55 except motionmount.MotionMountResponseError:
62 info[CONF_UUID] = DEFAULT_DISCOVERY_UNIQUE_ID
65 if info.get(CONF_UUID, EMPTY_MAC) != EMPTY_MAC:
66 unique_id = info[CONF_UUID]
68 unique_id = DEFAULT_DISCOVERY_UNIQUE_ID
70 name = info.get(CONF_NAME, user_input[CONF_HOST])
75 CONF_HOST: user_input[CONF_HOST],
76 CONF_PORT: user_input[CONF_PORT],
83 self, discovery_info: zeroconf.ZeroconfServiceInfo
84 ) -> ConfigFlowResult:
85 """Handle zeroconf discovery."""
88 host = discovery_info.hostname
89 port = discovery_info.port
90 zctype = discovery_info.type
91 name = discovery_info.name.removesuffix(f
".{zctype}")
92 unique_id = discovery_info.properties.get(
"mac")
94 self.discovery_info.
update(
108 updates={CONF_HOST: host, CONF_PORT: port}
114 self.context.
update({
"title_placeholders": {
"name": name}})
118 except (ConnectionError, socket.gaierror):
122 except motionmount.NotConnectedError:
124 except motionmount.MotionMountResponseError:
129 if info.get(CONF_UUID, EMPTY_MAC) != EMPTY_MAC:
130 unique_id = info[CONF_UUID]
135 updates={CONF_HOST: host, CONF_PORT: port}
143 self, user_input: dict[str, Any] |
None =
None
144 ) -> ConfigFlowResult:
145 """Handle a confirmation flow initiated by zeroconf."""
146 if user_input
is None:
148 step_id=
"zeroconf_confirm",
149 description_placeholders={CONF_NAME: self.discovery_info[CONF_NAME]},
154 title=self.discovery_info[CONF_NAME],
155 data=self.discovery_info,
159 """Validate the user input allows us to connect."""
161 mm = motionmount.MotionMount(data[CONF_HOST], data[CONF_PORT])
165 await mm.disconnect()
167 return {CONF_UUID:
format_mac(mm.mac.hex()), CONF_NAME: mm.name}
170 self, errors: dict[str, str] |
None =
None
171 ) -> ConfigFlowResult:
172 """Show the setup form to the user."""
175 data_schema=vol.Schema(
177 vol.Required(CONF_HOST): str,
178 vol.Required(CONF_PORT, default=23): int,
dict[str, Any] _validate_input(self, dict data)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult _show_setup_form(self, dict[str, str]|None errors=None)
ConfigFlowResult async_step_zeroconf_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_zeroconf(self, zeroconf.ZeroconfServiceInfo discovery_info)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
None _async_handle_discovery_without_unique_id(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)
list[ConfigEntry] _async_current_entries(self, bool|None include_ignore=None)
ConfigFlowResult async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=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)
_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)
IssData update(pyiss.ISS iss)