1 """Config flow for Forecast.Solar integration."""
3 from __future__
import annotations
8 import voluptuous
as vol
30 RE_API_KEY = re.compile(
r"^[a-zA-Z0-9]{16}$")
34 """Handle a config flow for Forecast.Solar."""
41 config_entry: ConfigEntry,
42 ) -> ForecastSolarOptionFlowHandler:
43 """Get the options flow for this handler."""
47 self, user_input: dict[str, Any] |
None =
None
48 ) -> ConfigFlowResult:
49 """Handle a flow initiated by the user."""
50 if user_input
is not None:
52 title=user_input[CONF_NAME],
54 CONF_LATITUDE: user_input[CONF_LATITUDE],
55 CONF_LONGITUDE: user_input[CONF_LONGITUDE],
58 CONF_AZIMUTH: user_input[CONF_AZIMUTH],
59 CONF_DECLINATION: user_input[CONF_DECLINATION],
60 CONF_MODULES_POWER: user_input[CONF_MODULES_POWER],
66 data_schema=vol.Schema(
69 CONF_NAME, default=self.hass.config.location_name
72 CONF_LATITUDE, default=self.hass.config.latitude
75 CONF_LONGITUDE, default=self.hass.config.longitude
77 vol.Required(CONF_DECLINATION, default=25): vol.All(
78 vol.Coerce(int), vol.Range(min=0, max=90)
80 vol.Required(CONF_AZIMUTH, default=180): vol.All(
81 vol.Coerce(int), vol.Range(min=0, max=360)
83 vol.Required(CONF_MODULES_POWER): vol.All(
84 vol.Coerce(int), vol.Range(min=1)
95 self, user_input: dict[str, Any] |
None =
None
96 ) -> ConfigFlowResult:
97 """Manage the options."""
99 if user_input
is not None:
100 if (api_key := user_input.get(CONF_API_KEY))
and RE_API_KEY.match(
103 errors[CONF_API_KEY] =
"invalid_api_key"
106 title=
"", data=user_input | {CONF_API_KEY: api_key
or None}
111 data_schema=vol.Schema(
124 ): vol.All(vol.Coerce(int), vol.Range(min=0, max=90)),
128 ): vol.All(vol.Coerce(int), vol.Range(min=-0, max=360)),
132 ): vol.All(vol.Coerce(int), vol.Range(min=1)),
134 CONF_DAMPING_MORNING,
136 CONF_DAMPING_MORNING, 0.0
138 ): vol.Coerce(float),
140 CONF_DAMPING_EVENING,
142 CONF_DAMPING_EVENING, 0.0
144 ): vol.Coerce(float),
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ForecastSolarOptionFlowHandler async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_init(self, dict[str, Any]|None user_input=None)
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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
_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)