1 """Configuration flow for CalDav."""
3 from collections.abc
import Mapping
8 from caldav.lib.error
import AuthorizationError, DAVError
10 import voluptuous
as vol
16 from .const
import DOMAIN
18 _LOGGER = logging.getLogger(__name__)
21 STEP_USER_DATA_SCHEMA = vol.Schema(
23 vol.Required(CONF_URL): str,
24 vol.Required(CONF_USERNAME): cv.string,
25 vol.Optional(CONF_PASSWORD, default=
""): cv.string,
26 vol.Optional(CONF_VERIFY_SSL, default=
True): cv.boolean,
32 """Handle a config flow for caldav."""
37 self, user_input: dict[str, Any] |
None =
None
38 ) -> ConfigFlowResult:
39 """Handle the initial step."""
40 errors: dict[str, str] = {}
41 if user_input
is not None:
44 CONF_URL: user_input[CONF_URL],
45 CONF_USERNAME: user_input[CONF_USERNAME],
49 errors[
"base"] = error
52 title=user_input[CONF_USERNAME], data=user_input
57 data_schema=STEP_USER_DATA_SCHEMA,
62 """Test the connection to the CalDAV server and return an error if any."""
63 client = caldav.DAVClient(
65 username=user_input[CONF_USERNAME],
66 password=user_input[CONF_PASSWORD],
67 ssl_verify_cert=user_input[CONF_VERIFY_SSL],
70 await self.hass.async_add_executor_job(client.principal)
71 except AuthorizationError
as err:
72 _LOGGER.warning(
"Authorization Error connecting to CalDAV server: %s", err)
73 if err.reason ==
"Unauthorized":
77 return "cannot_connect"
78 except requests.ConnectionError
as err:
79 _LOGGER.warning(
"Connection Error connecting to CalDAV server: %s", err)
80 return "cannot_connect"
81 except DAVError
as err:
82 _LOGGER.warning(
"CalDAV client error: %s", err)
83 return "cannot_connect"
85 _LOGGER.exception(
"Unexpected exception")
90 self, entry_data: Mapping[str, Any]
91 ) -> ConfigFlowResult:
92 """Perform reauth upon an API authentication error."""
96 self, user_input: dict[str, str] |
None =
None
97 ) -> ConfigFlowResult:
98 """Confirm reauth dialog."""
101 if user_input
is not None:
102 user_input = {**reauth_entry.data, **user_input}
105 errors[
"base"] = error
110 description_placeholders={
111 CONF_USERNAME: reauth_entry.data[CONF_USERNAME],
113 step_id=
"reauth_confirm",
114 data_schema=vol.Schema(
116 vol.Required(CONF_PASSWORD): str,
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, str]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
str|None _test_connection(self, dict[str, Any] 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)
_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)