1 """Adds config flow for Trafikverket Weather integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from pytrafikverket.exceptions
import (
10 MultipleWeatherStationsFound,
11 NoWeatherStationFound,
13 from pytrafikverket.trafikverket_weather
import TrafikverketWeather
14 import voluptuous
as vol
26 from .const
import CONF_STATION, DOMAIN
30 """Handle a config flow for Trafikverket Weatherstation integration."""
35 """Validate input from user input."""
37 weather_api = TrafikverketWeather(web_session, sensor_api)
38 await weather_api.async_get_weather(station)
41 self, user_input: dict[str, str] |
None =
None
42 ) -> ConfigFlowResult:
43 """Handle the initial step."""
46 if user_input
is not None:
47 name = user_input[CONF_STATION]
48 api_key = user_input[CONF_API_KEY]
49 station = user_input[CONF_STATION]
53 except InvalidAuthentication:
54 errors[
"base"] =
"invalid_auth"
55 except NoWeatherStationFound:
56 errors[
"base"] =
"invalid_station"
57 except MultipleWeatherStationsFound:
58 errors[
"base"] =
"more_stations"
60 errors[
"base"] =
"cannot_connect"
65 CONF_API_KEY: api_key,
66 CONF_STATION: station,
72 data_schema=vol.Schema(
74 vol.Required(CONF_API_KEY): cv.string,
75 vol.Required(CONF_STATION): cv.string,
82 self, entry_data: Mapping[str, Any]
83 ) -> ConfigFlowResult:
84 """Handle re-authentication with Trafikverket."""
88 self, user_input: dict[str, Any] |
None =
None
89 ) -> ConfigFlowResult:
90 """Confirm re-authentication with Trafikverket."""
91 errors: dict[str, str] = {}
95 api_key = user_input[CONF_API_KEY]
98 await self.
validate_inputvalidate_input(api_key, reauth_entry.data[CONF_STATION])
99 except InvalidAuthentication:
100 errors[
"base"] =
"invalid_auth"
101 except NoWeatherStationFound:
102 errors[
"base"] =
"invalid_station"
103 except MultipleWeatherStationsFound:
104 errors[
"base"] =
"more_stations"
106 errors[
"base"] =
"cannot_connect"
109 reauth_entry, data_updates={CONF_API_KEY: api_key}
113 step_id=
"reauth_confirm",
114 data_schema=vol.Schema({vol.Required(CONF_API_KEY): cv.string}),
119 self, user_input: dict[str, Any] |
None =
None
120 ) -> ConfigFlowResult:
121 """Handle re-configuration with Trafikverket."""
122 errors: dict[str, str] = {}
127 user_input[CONF_API_KEY], user_input[CONF_STATION]
129 except InvalidAuthentication:
130 errors[
"base"] =
"invalid_auth"
131 except NoWeatherStationFound:
132 errors[
"base"] =
"invalid_station"
133 except MultipleWeatherStationsFound:
134 errors[
"base"] =
"more_stations"
136 errors[
"base"] =
"cannot_connect"
140 title=user_input[CONF_STATION],
157 step_id=
"reconfigure",
ConfigFlowResult async_step_reconfigure(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_user(self, dict[str, str]|None user_input=None)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
None validate_input(self, str sensor_api, str station)
ConfigEntry _get_reauth_entry(self)
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_update_reload_and_abort(self, ConfigEntry entry, *str|None|UndefinedType unique_id=UNDEFINED, str|UndefinedType title=UNDEFINED, Mapping[str, Any]|UndefinedType data=UNDEFINED, Mapping[str, Any]|UndefinedType data_updates=UNDEFINED, Mapping[str, Any]|UndefinedType options=UNDEFINED, str|UndefinedType reason=UNDEFINED, bool reload_even_if_entry_is_unchanged=True)
ConfigEntry _get_reconfigure_entry(self)
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)
vol.Schema add_suggested_values_to_schema(self, vol.Schema data_schema, Mapping[str, Any]|None suggested_values)
_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)