Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow to configure the Kitchen Sink component."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Mapping
6 from typing import Any
7 
8 import voluptuous as vol
9 
10 from homeassistant import data_entry_flow
11 from homeassistant.config_entries import (
12  ConfigEntry,
13  ConfigFlow,
14  ConfigFlowResult,
15  OptionsFlow,
16 )
17 from homeassistant.core import callback
18 
19 from . import DOMAIN
20 
21 CONF_BOOLEAN = "bool"
22 CONF_INT = "int"
23 
24 
25 class KitchenSinkConfigFlow(ConfigFlow, domain=DOMAIN):
26  """Kitchen Sink configuration flow."""
27 
28  VERSION = 1
29 
30  @staticmethod
31  @callback
33  config_entry: ConfigEntry,
34  ) -> OptionsFlowHandler:
35  """Get the options flow for this handler."""
36  return OptionsFlowHandler()
37 
38  async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
39  """Set the config entry up from yaml."""
40  return self.async_create_entryasync_create_entryasync_create_entry(title="Kitchen Sink", data=import_data)
41 
42  async def async_step_reauth(
43  self, entry_data: Mapping[str, Any]
44  ) -> ConfigFlowResult:
45  """Reauth step."""
46  return await self.async_step_reauth_confirmasync_step_reauth_confirm()
47 
49  self, user_input: dict[str, Any] | None = None
50  ) -> ConfigFlowResult:
51  """Reauth confirm step."""
52  if user_input is None:
53  return self.async_show_formasync_show_formasync_show_form(step_id="reauth_confirm")
54  return self.async_abortasync_abortasync_abort(reason="reauth_successful")
55 
56 
58  """Handle options."""
59 
60  async def async_step_init(
61  self, user_input: dict[str, Any] | None = None
62  ) -> ConfigFlowResult:
63  """Manage the options."""
64  return await self.async_step_options_1async_step_options_1()
65 
67  self, user_input: dict[str, Any] | None = None
68  ) -> ConfigFlowResult:
69  """Manage the options."""
70  if user_input is not None:
71  return self.async_create_entryasync_create_entry(data=self.config_entryconfig_entryconfig_entry.options | user_input)
72 
73  return self.async_show_formasync_show_form(
74  step_id="options_1",
75  data_schema=vol.Schema(
76  {
77  vol.Required("section_1"): data_entry_flow.section(
78  vol.Schema(
79  {
80  vol.Optional(
81  CONF_BOOLEAN,
82  default=self.config_entryconfig_entryconfig_entry.options.get(
83  CONF_BOOLEAN, False
84  ),
85  ): bool,
86  vol.Optional(
87  CONF_INT,
88  default=self.config_entryconfig_entryconfig_entry.options.get(CONF_INT, 10),
89  ): int,
90  }
91  ),
92  {"collapsed": False},
93  ),
94  }
95  ),
96  )
ConfigFlowResult async_step_import(self, dict[str, Any] import_data)
Definition: config_flow.py:38
OptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
Definition: config_flow.py:34
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:50
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
Definition: config_flow.py:44
ConfigFlowResult async_step_options_1(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:68
ConfigFlowResult async_step_init(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:62
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_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)
None config_entry(self, ConfigEntry value)
_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)