1
mirror of https://github.com/home-assistant/core synced 2024-09-28 03:04:04 +02:00

Use SchemaOptionsFlowHandler in aurora (#82687)

This commit is contained in:
epenet 2022-11-25 16:09:09 +01:00 committed by GitHub
parent e00808bea8
commit 283ee94cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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),
),
}
),
)