Use SchemaOptionsFlowHandler in azure-event-hub (#82619)

* Use SchemaOptionsFlowHandler in azure-event-hub

* Update config_flow.py

* black
This commit is contained in:
epenet 2022-11-25 17:26:50 +01:00 committed by GitHub
parent 0a4549e202
commit 3c3f48fe28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,10 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.schema_config_entry_flow import (
SchemaFlowFormStep,
SchemaOptionsFlowHandler,
)
from .client import AzureEventHubClient
from .const import (
@ -52,6 +56,15 @@ SAS_SCHEMA = vol.Schema(
}
)
OPTIONS_SCHEMA = vol.Schema(
{
vol.Required(CONF_SEND_INTERVAL): int,
}
)
OPTIONS_FLOW = {
"init": SchemaFlowFormStep(OPTIONS_SCHEMA),
}
async def validate_data(data: dict[str, Any]) -> dict[str, str] | None:
"""Validate the input."""
@ -81,9 +94,9 @@ class AEHConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
@callback
def async_get_options_flow(
config_entry: config_entries.ConfigEntry,
) -> AEHOptionsFlowHandler:
) -> SchemaOptionsFlowHandler:
"""Get the options flow for this handler."""
return AEHOptionsFlowHandler(config_entry)
return SchemaOptionsFlowHandler(config_entry, OPTIONS_FLOW)
async def async_step_user(
self, user_input: dict[str, Any] | None = None
@ -167,32 +180,3 @@ class AEHConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
return None
self._data.update(user_input)
return await validate_data(self._data)
class AEHOptionsFlowHandler(config_entries.OptionsFlow):
"""Handle azure event hub options."""
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
"""Initialize AEH options flow."""
self.config_entry = config_entry
self.options = deepcopy(dict(config_entry.options))
async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Manage the AEH 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_SEND_INTERVAL,
default=self.options.get(CONF_SEND_INTERVAL),
): int
}
),
last_step=True,
)