1 """Config flow for Aurora."""
3 from __future__
import annotations
8 from aiohttp
import ClientError
9 from auroranoaa
import AuroraForecast
10 import voluptuous
as vol
18 SchemaOptionsFlowHandler,
21 from .const
import CONF_THRESHOLD, DEFAULT_THRESHOLD, DOMAIN
23 _LOGGER = logging.getLogger(__name__)
25 OPTIONS_SCHEMA = vol.Schema(
27 vol.Required(CONF_THRESHOLD, default=DEFAULT_THRESHOLD): vol.All(
28 vol.Coerce(int), vol.Range(min=0, max=100)
38 """Handle a config flow for NOAA Aurora Integration."""
45 config_entry: ConfigEntry,
46 ) -> SchemaOptionsFlowHandler:
47 """Get the options flow for this handler."""
51 self, user_input: dict[str, Any] |
None =
None
52 ) -> ConfigFlowResult:
53 """Handle the initial step."""
54 errors: dict[str, str] = {}
56 if user_input
is not None:
57 longitude = user_input[CONF_LONGITUDE]
58 latitude = user_input[CONF_LATITUDE]
60 session = aiohttp_client.async_get_clientsession(self.hass)
61 api = AuroraForecast(session=session)
64 await api.get_forecast_data(longitude, latitude)
66 errors[
"base"] =
"cannot_connect"
68 _LOGGER.exception(
"Unexpected exception")
69 errors[
"base"] =
"unknown"
72 f
"{user_input[CONF_LONGITUDE]}_{user_input[CONF_LATITUDE]}"
76 title=
"Aurora visibility", data=user_input
84 vol.Required(CONF_LONGITUDE): cv.longitude,
85 vol.Required(CONF_LATITUDE): cv.latitude,
89 CONF_LONGITUDE: self.hass.config.longitude,
90 CONF_LATITUDE: self.hass.config.latitude,
SchemaOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
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_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)