Use SchemaOptionsFlowHandler in balboa (#82899)

* Use SchemaOptionsFlowHandler in balboa

* Make CONF_SYNC_TIME required
pull/82925/head
epenet 2022-11-29 13:37:05 +01:00 committed by GitHub
parent e6333c15eb
commit f8e1cb5bcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 29 deletions

View File

@ -12,11 +12,24 @@ from homeassistant.const import CONF_HOST
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.device_registry import format_mac
from homeassistant.helpers.schema_config_entry_flow import (
SchemaFlowFormStep,
SchemaOptionsFlowHandler,
)
from .const import _LOGGER, CONF_SYNC_TIME, DOMAIN
DATA_SCHEMA = vol.Schema({vol.Required(CONF_HOST): str})
OPTIONS_SCHEMA = vol.Schema(
{
vol.Required(CONF_SYNC_TIME, default=False): bool,
}
)
OPTIONS_FLOW = {
"init": SchemaFlowFormStep(OPTIONS_SCHEMA),
}
async def validate_input(data: dict[str, Any]) -> dict[str, str]:
"""Validate the user input allows us to connect."""
@ -47,9 +60,9 @@ class BalboaSpaClientFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
@callback
def async_get_options_flow(
config_entry: config_entries.ConfigEntry,
) -> config_entries.OptionsFlow:
) -> SchemaOptionsFlowHandler:
"""Get the options flow for this handler."""
return BalboaSpaClientOptionsFlowHandler(config_entry)
return SchemaOptionsFlowHandler(config_entry, OPTIONS_FLOW)
async def async_step_user(
self, user_input: dict[str, Any] | None = None
@ -77,30 +90,3 @@ class BalboaSpaClientFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
class CannotConnect(exceptions.HomeAssistantError):
"""Error to indicate we cannot connect."""
class BalboaSpaClientOptionsFlowHandler(config_entries.OptionsFlow):
"""Handle Balboa Spa Client options."""
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
"""Initialize Balboa Spa Client options flow."""
self.config_entry = config_entry
async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Manage Balboa Spa Client 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.Optional(
CONF_SYNC_TIME,
default=self.config_entry.options.get(CONF_SYNC_TIME, False),
): bool,
}
),
)