1 """Config flow to configure Met component."""
3 from __future__
import annotations
7 import voluptuous
as vol
32 DEFAULT_HOME_LATITUDE,
33 DEFAULT_HOME_LONGITUDE,
41 """Return a set of configured met.no instances."""
43 for entry
in hass.config_entries.async_entries(DOMAIN):
44 if entry.data.get(
"track_home"):
45 entries.append(
"home")
48 f
"{entry.data.get(CONF_LATITUDE)}-{entry.data.get(CONF_LONGITUDE)}"
54 hass: HomeAssistant, config_entry: ConfigEntry |
None =
None
56 """Get a schema with default values."""
58 if config_entry
is None or config_entry.data.get(CONF_TRACK_HOME,
False):
61 vol.Required(CONF_NAME, default=HOME_LOCATION_NAME): str,
62 vol.Required(CONF_LATITUDE, default=hass.config.latitude): cv.latitude,
64 CONF_LONGITUDE, default=hass.config.longitude
67 CONF_ELEVATION, default=hass.config.elevation
70 mode=NumberSelectorMode.BOX,
71 unit_of_measurement=UnitOfLength.METERS,
79 vol.Required(CONF_NAME, default=config_entry.data.get(CONF_NAME)): str,
81 CONF_LATITUDE, default=config_entry.data.get(CONF_LATITUDE)
84 CONF_LONGITUDE, default=config_entry.data.get(CONF_LONGITUDE)
87 CONF_ELEVATION, default=config_entry.data.get(CONF_ELEVATION)
90 mode=NumberSelectorMode.BOX,
91 unit_of_measurement=UnitOfLength.METERS,
99 """Config flow for Met component."""
104 self, user_input: dict[str, Any] |
None =
None
105 ) -> ConfigFlowResult:
106 """Handle a flow initialized by the user."""
109 if user_input
is not None:
111 f
"{user_input.get(CONF_LATITUDE)}-{user_input.get(CONF_LONGITUDE)}"
115 title=user_input[CONF_NAME], data=user_input
117 errors[CONF_NAME] =
"already_configured"
126 self, data: dict[str, Any] |
None =
None
127 ) -> ConfigFlowResult:
128 """Handle a flow initialized by onboarding."""
131 if (
not self.hass.config.latitude
and not self.hass.config.longitude)
or (
132 self.hass.config.latitude == DEFAULT_HOME_LATITUDE
133 and self.hass.config.longitude == DEFAULT_HOME_LONGITUDE
138 title=HOME_LOCATION_NAME, data={CONF_TRACK_HOME:
True}
144 config_entry: ConfigEntry,
145 ) -> MetOptionsFlowHandler:
146 """Get the options flow for Met."""
151 """Options flow for Met component."""
154 self, user_input: dict[str, Any] |
None =
None
155 ) -> ConfigFlowResult:
156 """Configure options for Met."""
158 if user_input
is not None:
160 self.hass.config_entries.async_update_entry(
MetOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_onboarding(self, dict[str, Any]|None data=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
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_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)
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)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
set[str] configured_instances(HomeAssistant hass)
vol.Schema _get_data_schema(HomeAssistant hass, ConfigEntry|None config_entry=None)