1 """Config flow to configure the Nextcloud integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from nextcloudmonitor
import (
10 NextcloudMonitorAuthorizationError,
11 NextcloudMonitorConnectionError,
12 NextcloudMonitorRequestError,
14 import voluptuous
as vol
19 from .const
import DEFAULT_VERIFY_SSL, DOMAIN
21 DATA_SCHEMA_USER = vol.Schema(
23 vol.Required(CONF_URL): str,
24 vol.Required(CONF_USERNAME): str,
25 vol.Required(CONF_PASSWORD): str,
26 vol.Required(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): bool,
29 DATA_SCHEMA_REAUTH = vol.Schema(
31 vol.Required(CONF_USERNAME): str,
32 vol.Required(CONF_PASSWORD): str,
38 """Handle a Nextcloud config flow."""
43 """Try to connect to nextcloud server."""
44 return NextcloudMonitor(
46 user_input[CONF_USERNAME],
47 user_input[CONF_PASSWORD],
48 user_input.get(CONF_VERIFY_SSL, DEFAULT_VERIFY_SSL),
52 self, user_input: dict[str, Any] |
None =
None
53 ) -> ConfigFlowResult:
54 """Handle a flow initialized by the user."""
57 if user_input
is not None:
60 await self.hass.async_add_executor_job(self.
_try_connect_nc_try_connect_nc, user_input)
61 except NextcloudMonitorAuthorizationError:
62 errors[
"base"] =
"invalid_auth"
63 except (NextcloudMonitorConnectionError, NextcloudMonitorRequestError):
64 errors[
"base"] =
"connection_error"
67 title=user_input[CONF_URL],
73 step_id=
"user", data_schema=data_schema, errors=errors
77 self, entry_data: Mapping[str, Any]
78 ) -> ConfigFlowResult:
79 """Handle flow upon an API authentication error."""
83 self, user_input: dict[str, Any] |
None =
None
84 ) -> ConfigFlowResult:
85 """Handle reauthorization flow."""
89 if user_input
is not None:
91 await self.hass.async_add_executor_job(
92 self.
_try_connect_nc_try_connect_nc, {**reauth_entry.data, **user_input}
94 except NextcloudMonitorAuthorizationError:
95 errors[
"base"] =
"invalid_auth"
96 except (NextcloudMonitorConnectionError, NextcloudMonitorRequestError):
97 errors[
"base"] =
"connection_error"
100 reauth_entry, data_updates=user_input
105 {CONF_USERNAME: reauth_entry.data[CONF_USERNAME], **(user_input
or {})},
108 step_id=
"reauth_confirm",
109 data_schema=data_schema,
110 description_placeholders={
"url": reauth_entry.data[CONF_URL]},
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
NextcloudMonitor _try_connect_nc(self, dict user_input)
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)
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)
vol.Schema add_suggested_values_to_schema(self, vol.Schema data_schema, Mapping[str, Any]|None suggested_values)
_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)