Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow to configure the Season integration."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 import voluptuous as vol
8 
9 from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
10 from homeassistant.const import CONF_TYPE
12  SelectSelector,
13  SelectSelectorConfig,
14  SelectSelectorMode,
15 )
16 
17 from .const import DEFAULT_NAME, DOMAIN, TYPE_ASTRONOMICAL, TYPE_METEOROLOGICAL
18 
19 
20 class SeasonConfigFlow(ConfigFlow, domain=DOMAIN):
21  """Config flow for Season."""
22 
23  VERSION = 1
24 
25  async def async_step_user(
26  self, user_input: dict[str, Any] | None = None
27  ) -> ConfigFlowResult:
28  """Handle a flow initialized by the user."""
29  if user_input is not None:
30  await self.async_set_unique_idasync_set_unique_id(user_input[CONF_TYPE])
31  self._abort_if_unique_id_configured_abort_if_unique_id_configured()
32  return self.async_create_entryasync_create_entryasync_create_entry(
33  title=DEFAULT_NAME,
34  data={CONF_TYPE: user_input[CONF_TYPE]},
35  )
36 
37  return self.async_show_formasync_show_formasync_show_form(
38  step_id="user",
39  data_schema=vol.Schema(
40  {
41  vol.Required(CONF_TYPE, default=TYPE_ASTRONOMICAL): SelectSelector(
43  translation_key="season_type",
44  mode=SelectSelectorMode.LIST,
45  options=[
46  TYPE_ASTRONOMICAL,
47  TYPE_METEOROLOGICAL,
48  ],
49  )
50  )
51  },
52  ),
53  )
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:27
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry|None async_set_unique_id(self, str|None unique_id=None, *bool raise_on_progress=True)
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_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)