From 20474e500c2c75ca18889dd5cdfa9d6cedca5657 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 25 Nov 2022 16:16:43 +0100 Subject: [PATCH] Use SchemaOptionsFlowHandler in aemet (#82638) * Use SchemaOptionsFlowHandler in aemet * Update homeassistant/components/aemet/config_flow.py * Update config_flow.py * black --- homeassistant/components/aemet/config_flow.py | 40 +++++++------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/aemet/config_flow.py b/homeassistant/components/aemet/config_flow.py index 1188df5b94f..9db0c6f7db1 100644 --- a/homeassistant/components/aemet/config_flow.py +++ b/homeassistant/components/aemet/config_flow.py @@ -8,9 +8,22 @@ from homeassistant import config_entries from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME from homeassistant.core import callback import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.schema_config_entry_flow import ( + SchemaFlowFormStep, + SchemaOptionsFlowHandler, +) from .const import CONF_STATION_UPDATES, DEFAULT_NAME, DOMAIN +OPTIONS_SCHEMA = vol.Schema( + { + vol.Required(CONF_STATION_UPDATES): bool, + } +) +OPTIONS_FLOW = { + "init": SchemaFlowFormStep(OPTIONS_SCHEMA), +} + class AemetConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Config flow for AEMET OpenData.""" @@ -54,32 +67,9 @@ class AemetConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): @callback def async_get_options_flow( config_entry: config_entries.ConfigEntry, - ) -> OptionsFlowHandler: + ) -> SchemaOptionsFlowHandler: """Get the options flow for this handler.""" - return OptionsFlowHandler(config_entry) - - -class OptionsFlowHandler(config_entries.OptionsFlow): - """Handle a option flow for AEMET.""" - - def __init__(self, config_entry: config_entries.ConfigEntry) -> None: - """Initialize options flow.""" - self.config_entry = config_entry - - async def async_step_init(self, user_input=None): - """Handle options flow.""" - if user_input is not None: - return self.async_create_entry(title="", data=user_input) - - data_schema = vol.Schema( - { - vol.Required( - CONF_STATION_UPDATES, - default=self.config_entry.options.get(CONF_STATION_UPDATES), - ): bool, - } - ) - return self.async_show_form(step_id="init", data_schema=data_schema) + return SchemaOptionsFlowHandler(config_entry, OPTIONS_FLOW) async def _is_aemet_api_online(hass, api_key):