1 """Config flow for PEGELONLINE."""
3 from __future__
import annotations
7 from aiopegelonline
import CONNECT_ERRORS, PegelOnline
8 import voluptuous
as vol
29 from .const
import CONF_STATION, DEFAULT_RADIUS, DOMAIN
33 """Handle a config flow."""
38 """Init the FlowHandler."""
40 self.
_data_data: dict[str, Any] = {}
41 self._stations: dict[str, str] = {}
44 self, user_input: dict[str, Any] |
None =
None
45 ) -> ConfigFlowResult:
46 """Handle a flow initialized by the user."""
52 stations = await api.async_get_nearby_stations(
53 user_input[CONF_LOCATION][CONF_LATITUDE],
54 user_input[CONF_LOCATION][CONF_LONGITUDE],
55 user_input[CONF_RADIUS],
57 except CONNECT_ERRORS:
58 return self.
_show_form_user_show_form_user(user_input, errors={
"base":
"cannot_connect"})
60 if len(stations) == 0:
61 return self.
_show_form_user_show_form_user(user_input, errors={CONF_RADIUS:
"no_stations"})
63 for uuid, station
in stations.items():
64 self._stations[uuid] = f
"{station.name} {station.water_name}"
71 self, user_input: dict[str, Any] |
None =
None
72 ) -> ConfigFlowResult:
73 """Handle the step select_station of a flow initialized by the user."""
79 step_id=
"select_station",
80 description_placeholders={
"stations_count":
str(len(self._stations))},
81 data_schema=vol.Schema(
85 options=stations, mode=SelectSelectorMode.DROPDOWN
96 title=self._stations[user_input[CONF_STATION]],
102 user_input: dict[str, Any] |
None =
None,
103 errors: dict[str, Any] |
None =
None,
104 ) -> ConfigFlowResult:
105 if user_input
is None:
109 data_schema=vol.Schema(
113 default=user_input.get(
116 "latitude": self.hass.config.latitude,
117 "longitude": self.hass.config.longitude,
122 CONF_RADIUS, default=user_input.get(CONF_RADIUS, DEFAULT_RADIUS)
128 unit_of_measurement=UnitOfLength.KILOMETERS,
ConfigFlowResult _show_form_user(self, dict[str, Any]|None user_input=None, dict[str, Any]|None errors=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_select_station(self, dict[str, Any]|None user_input=None)
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)
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)