Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow to configure the Stookwijzer integration."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from stookwijzer import Stookwijzer
8 import voluptuous as vol
9 
10 from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
11 from homeassistant.const import CONF_LATITUDE, CONF_LOCATION, CONF_LONGITUDE
12 from homeassistant.helpers.aiohttp_client import async_get_clientsession
13 from homeassistant.helpers.selector import LocationSelector
14 
15 from .const import DOMAIN
16 
17 
18 class StookwijzerFlowHandler(ConfigFlow, domain=DOMAIN):
19  """Config flow for Stookwijzer."""
20 
21  VERSION = 2
22 
23  async def async_step_user(
24  self, user_input: dict[str, Any] | None = None
25  ) -> ConfigFlowResult:
26  """Handle a flow initialized by the user."""
27  errors = {}
28  if user_input is not None:
29  latitude, longitude = await Stookwijzer.async_transform_coordinates(
30  async_get_clientsession(self.hass),
31  user_input[CONF_LOCATION][CONF_LATITUDE],
32  user_input[CONF_LOCATION][CONF_LONGITUDE],
33  )
34  if latitude and longitude:
35  return self.async_create_entryasync_create_entryasync_create_entry(
36  title="Stookwijzer",
37  data={CONF_LATITUDE: latitude, CONF_LONGITUDE: longitude},
38  )
39  errors["base"] = "unknown"
40 
41  return self.async_show_formasync_show_formasync_show_form(
42  step_id="user",
43  errors=errors,
44  data_schema=vol.Schema(
45  {
46  vol.Required(
47  CONF_LOCATION,
48  default={
49  CONF_LATITUDE: self.hass.config.latitude,
50  CONF_LONGITUDE: self.hass.config.longitude,
51  },
52  ): LocationSelector()
53  }
54  ),
55  )
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:25
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)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)