1 """Config flow for todoist integration."""
3 from http
import HTTPStatus
7 from requests.exceptions
import HTTPError
8 from todoist_api_python.api_async
import TodoistAPIAsync
9 import voluptuous
as vol
14 from .const
import DOMAIN
16 _LOGGER = logging.getLogger(__name__)
18 SETTINGS_URL =
"https://app.todoist.com/app/settings/integrations/developer"
20 STEP_USER_DATA_SCHEMA = vol.Schema(
22 vol.Required(CONF_TOKEN): str,
28 """Handle a config flow for todoist."""
33 self, user_input: dict[str, Any] |
None =
None
34 ) -> ConfigFlowResult:
35 """Handle the initial step."""
39 errors: dict[str, str] = {}
40 if user_input
is not None:
41 api = TodoistAPIAsync(user_input[CONF_TOKEN])
44 except HTTPError
as err:
45 if err.response.status_code == HTTPStatus.UNAUTHORIZED:
46 errors[
"base"] =
"invalid_api_key"
48 errors[
"base"] =
"cannot_connect"
50 _LOGGER.exception(
"Unexpected exception")
51 errors[
"base"] =
"unknown"
57 data_schema=STEP_USER_DATA_SCHEMA,
59 description_placeholders={
"settings_url": SETTINGS_URL},
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
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)
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)