1 """Config flow for motionEye integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from motioneye_client.client
import (
9 MotionEyeClientConnectionError,
10 MotionEyeClientInvalidAuthError,
11 MotionEyeClientRequestError,
13 import voluptuous
as vol
29 from .
import create_motioneye_client
33 CONF_STREAM_URL_TEMPLATE,
34 CONF_SURVEILLANCE_PASSWORD,
35 CONF_SURVEILLANCE_USERNAME,
37 CONF_WEBHOOK_SET_OVERWRITE,
39 DEFAULT_WEBHOOK_SET_OVERWRITE,
45 """Handle a config flow for motionEye."""
48 _hassio_discovery: dict[str, Any] |
None =
None
51 self, user_input: dict[str, Any] |
None =
None
52 ) -> ConfigFlowResult:
53 """Handle the initial step."""
56 user_input: Mapping[str, Any], errors: dict[str, str] |
None =
None
57 ) -> ConfigFlowResult:
58 """Show the form to the user."""
59 url_schema: VolDictType = {}
63 vol.Required(CONF_URL, default=user_input.get(CONF_URL,
""))
68 data_schema=vol.Schema(
73 default=user_input.get(CONF_ADMIN_USERNAME),
77 default=user_input.get(CONF_ADMIN_PASSWORD,
""),
80 CONF_SURVEILLANCE_USERNAME,
81 default=user_input.get(CONF_SURVEILLANCE_USERNAME),
84 CONF_SURVEILLANCE_PASSWORD,
85 default=user_input.get(CONF_SURVEILLANCE_PASSWORD,
""),
92 if user_input
is None:
104 cv.url(user_input[CONF_URL])
106 return _get_form(user_input, {
"base":
"invalid_url"})
109 user_input[CONF_URL],
110 admin_username=user_input.get(CONF_ADMIN_USERNAME),
111 admin_password=user_input.get(CONF_ADMIN_PASSWORD),
112 surveillance_username=user_input.get(CONF_SURVEILLANCE_USERNAME),
113 surveillance_password=user_input.get(CONF_SURVEILLANCE_PASSWORD),
119 await client.async_client_login()
120 except MotionEyeClientConnectionError:
121 errors[
"base"] =
"cannot_connect"
122 except MotionEyeClientInvalidAuthError:
123 errors[
"base"] =
"invalid_auth"
124 except MotionEyeClientRequestError:
125 errors[
"base"] =
"unknown"
127 await client.async_client_close()
130 return _get_form(user_input, errors)
135 if CONF_WEBHOOK_ID
in reauth_entry.data:
136 user_input[CONF_WEBHOOK_ID] = reauth_entry.data[CONF_WEBHOOK_ID]
144 title = user_input[CONF_URL]
153 async
def async_step_reauth(
154 self, entry_data: Mapping[str, Any]
155 ) -> ConfigFlowResult:
156 """Handle a reauthentication flow."""
160 self, discovery_info: HassioServiceInfo
161 ) -> ConfigFlowResult:
162 """Handle Supervisor discovery."""
166 return await self.async_step_hassio_confirm()
168 async
def async_step_hassio_confirm(
169 self, user_input: dict[str, Any] |
None =
None
170 ) -> ConfigFlowResult:
171 """Confirm Supervisor discovery."""
174 step_id=
"hassio_confirm",
175 description_placeholders={
"addon": self.
_hassio_discovery_hassio_discovery[
"addon"]},
183 config_entry: ConfigEntry,
184 ) -> MotionEyeOptionsFlow:
185 """Get the Hyperion Options flow."""
190 """motionEye options flow."""
193 self, user_input: dict[str, Any] |
None =
None
194 ) -> ConfigFlowResult:
195 """Manage the options."""
196 if user_input
is not None:
199 schema: dict[vol.Marker, type] = {
208 CONF_WEBHOOK_SET_OVERWRITE,
210 CONF_WEBHOOK_SET_OVERWRITE,
211 DEFAULT_WEBHOOK_SET_OVERWRITE,
219 description: dict[str, str] |
None =
None
223 CONF_STREAM_URL_TEMPLATE
227 schema[vol.Optional(CONF_STREAM_URL_TEMPLATE, description=description)] = (
231 return self.
async_show_formasync_show_form(step_id=
"init", data_schema=vol.Schema(schema))
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_init(self, dict[str, Any]|None user_input=None)
None _async_handle_discovery_without_unique_id(self)
ConfigEntry _get_reauth_entry(self)
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_hassio(self, HassioServiceInfo discovery_info)
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)
OptionsFlow async_get_options_flow(ConfigEntry config_entry)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
bool show_advanced_options(self)
_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)
MotionEyeClient create_motioneye_client(*Any args, **Any kwargs)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)