1 """Config flow to configure the Meteoclimatic integration."""
6 from meteoclimatic
import MeteoclimaticClient
7 from meteoclimatic.exceptions
import MeteoclimaticError, StationNotFound
8 import voluptuous
as vol
12 from .const
import CONF_STATION_CODE, DOMAIN
14 _LOGGER = logging.getLogger(__name__)
18 """Handle a Meteoclimatic config flow."""
23 """Show the setup form to the user."""
24 if user_input
is None:
29 data_schema=vol.Schema(
32 CONF_STATION_CODE, default=user_input.get(CONF_STATION_CODE,
"")
40 self, user_input: dict[str, Any] |
None =
None
41 ) -> ConfigFlowResult:
42 """Handle a flow initiated by the user."""
43 errors: dict[str, str] = {}
45 if user_input
is None:
48 station_code = user_input[CONF_STATION_CODE]
49 client = MeteoclimaticClient()
52 weather = await self.hass.async_add_executor_job(
53 client.weather_at_station, station_code
55 except StationNotFound
as exp:
56 _LOGGER.error(
"Station not found: %s", exp)
57 errors[
"base"] =
"not_found"
59 except MeteoclimaticError
as exp:
60 _LOGGER.error(
"Error when obtaining Meteoclimatic weather: %s", exp)
67 title=weather.station.name, data={CONF_STATION_CODE: station_code}
def _show_setup_form(self, user_input=None, errors=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
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)