From 283ee94cf345b204033592c963907800477a99dc Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 25 Nov 2022 16:09:09 +0100 Subject: [PATCH] Use SchemaOptionsFlowHandler in aurora (#82687) --- .../components/aurora/config_flow.py | 50 +++++++------------ 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/homeassistant/components/aurora/config_flow.py b/homeassistant/components/aurora/config_flow.py index a2331c19ec6..4649a3adc08 100644 --- a/homeassistant/components/aurora/config_flow.py +++ b/homeassistant/components/aurora/config_flow.py @@ -11,11 +11,26 @@ from homeassistant import config_entries from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME from homeassistant.core import callback from homeassistant.helpers import aiohttp_client +from homeassistant.helpers.schema_config_entry_flow import ( + SchemaFlowFormStep, + SchemaOptionsFlowHandler, +) from .const import CONF_THRESHOLD, DEFAULT_NAME, DEFAULT_THRESHOLD, DOMAIN _LOGGER = logging.getLogger(__name__) +OPTIONS_SCHEMA = vol.Schema( + { + vol.Required(CONF_THRESHOLD, default=DEFAULT_THRESHOLD): vol.All( + vol.Coerce(int), vol.Range(min=0, max=100) + ), + } +) +OPTIONS_FLOW = { + "init": SchemaFlowFormStep(OPTIONS_SCHEMA), +} + class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Handle a config flow for NOAA Aurora Integration.""" @@ -26,9 +41,9 @@ class ConfigFlow(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) + return SchemaOptionsFlowHandler(config_entry, OPTIONS_FLOW) async def async_step_user(self, user_input=None): """Handle the initial step.""" @@ -81,34 +96,3 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ), errors=errors, ) - - -class OptionsFlowHandler(config_entries.OptionsFlow): - """Handle options flow changes.""" - - 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): - """Manage options.""" - - if user_input is not None: - return self.async_create_entry(title="", data=user_input) - - return self.async_show_form( - step_id="init", - data_schema=vol.Schema( - { - vol.Required( - CONF_THRESHOLD, - default=self.config_entry.options.get( - CONF_THRESHOLD, DEFAULT_THRESHOLD - ), - ): vol.All( - vol.Coerce(int), - vol.Range(min=0, max=100), - ), - } - ), - )