Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow for Local To-do integration."""
2 
3 from __future__ import annotations
4 
5 import logging
6 from typing import Any
7 
8 import voluptuous as vol
9 
10 from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
11 from homeassistant.util import slugify
12 
13 from .const import CONF_STORAGE_KEY, CONF_TODO_LIST_NAME, DOMAIN
14 
15 _LOGGER = logging.getLogger(__name__)
16 
17 STEP_USER_DATA_SCHEMA = vol.Schema(
18  {
19  vol.Required(CONF_TODO_LIST_NAME): str,
20  }
21 )
22 
23 
24 class LocalTodoConfigFlow(ConfigFlow, domain=DOMAIN):
25  """Handle a config flow for Local To-do."""
26 
27  VERSION = 1
28 
29  async def async_step_user(
30  self, user_input: dict[str, Any] | None = None
31  ) -> ConfigFlowResult:
32  """Handle the initial step."""
33  errors: dict[str, str] = {}
34  if user_input is not None:
35  key = slugify(user_input[CONF_TODO_LIST_NAME])
36  self._async_abort_entries_match_async_abort_entries_match({CONF_STORAGE_KEY: key})
37  user_input[CONF_STORAGE_KEY] = key
38  return self.async_create_entryasync_create_entryasync_create_entry(
39  title=user_input[CONF_TODO_LIST_NAME], data=user_input
40  )
41 
42  return self.async_show_formasync_show_formasync_show_form(
43  step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
44  )
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:31
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)
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)