1 """Config Flow for the zamg integration."""
3 from __future__
import annotations
7 import voluptuous
as vol
8 from zamg
import ZamgData
9 from zamg.exceptions
import ZamgApiError, ZamgNoDataError
14 from .const
import CONF_STATION_ID, DOMAIN, LOGGER
18 """Config flow for zamg integration."""
22 _client: ZamgData |
None =
None
25 self, user_input: dict[str, Any] |
None =
None
26 ) -> ConfigFlowResult:
27 """Handle a flow initiated by the user."""
32 if user_input
is None:
34 stations = await self.
_client_client.zamg_stations()
35 closest_station_id = await self.
_client_client.closest_station(
36 self.hass.config.latitude,
37 self.hass.config.longitude,
39 except (ZamgApiError, ZamgNoDataError)
as err:
40 LOGGER.error(
"Config_flow: Received error from ZAMG: %s", err)
42 LOGGER.debug(
"config_flow: closest station = %s", closest_station_id)
47 vol.Required(CONF_STATION_ID, default=closest_station_id): vol.In(
49 station: f
"{stations[station][2]} ({station})"
50 for station
in stations
57 station_id = user_input[CONF_STATION_ID]
64 self.
_client_client.set_default_station(station_id)
66 except (ZamgApiError, ZamgNoDataError)
as err:
67 LOGGER.error(
"Config_flow: Received error from ZAMG: %s", err)
71 title=self.
_client_client.get_station_name,
72 data={CONF_STATION_ID: station_id},
ConfigFlowResult async_step_user(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_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)
_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)
IssData update(pyiss.ISS iss)
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)