mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Simplify SchemaFlowStep typing (#82661)
* Simplify SchemaFlowStep typing * Adjust accuweather
This commit is contained in:
parent
6c024c8875
commit
9f9114cb4a
@ -19,7 +19,6 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.schema_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
SchemaFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
SchemaFlowMenuStep,
|
|
||||||
SchemaOptionsFlowHandler,
|
SchemaOptionsFlowHandler,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,8 +29,8 @@ OPTIONS_SCHEMA = vol.Schema(
|
|||||||
vol.Optional(CONF_FORECAST, default=False): bool,
|
vol.Optional(CONF_FORECAST, default=False): bool,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
OPTIONS_FLOW = {
|
||||||
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ from homeassistant.helpers import selector
|
|||||||
from homeassistant.helpers.schema_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
SchemaConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
SchemaFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
SchemaFlowMenuStep,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -76,12 +75,12 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
}
|
}
|
||||||
).extend(OPTIONS_SCHEMA.schema)
|
).extend(OPTIONS_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
CONFIG_FLOW = {
|
||||||
"user": SchemaFlowFormStep(CONFIG_SCHEMA)
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA),
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
OPTIONS_FLOW = {
|
||||||
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ def set_group_type(group_type: str) -> Callable[[dict[str, Any]], dict[str, Any]
|
|||||||
return _set_group_type
|
return _set_group_type
|
||||||
|
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
CONFIG_FLOW = {
|
||||||
"user": SchemaFlowMenuStep(GROUP_TYPES),
|
"user": SchemaFlowMenuStep(GROUP_TYPES),
|
||||||
"binary_sensor": SchemaFlowFormStep(
|
"binary_sensor": SchemaFlowFormStep(
|
||||||
BINARY_SENSOR_CONFIG_SCHEMA, set_group_type("binary_sensor")
|
BINARY_SENSOR_CONFIG_SCHEMA, set_group_type("binary_sensor")
|
||||||
@ -139,7 +139,7 @@ CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
OPTIONS_FLOW = {
|
||||||
"init": SchemaFlowFormStep(None, next_step=choose_options_step),
|
"init": SchemaFlowFormStep(None, next_step=choose_options_step),
|
||||||
"binary_sensor": SchemaFlowFormStep(binary_sensor_options_schema),
|
"binary_sensor": SchemaFlowFormStep(binary_sensor_options_schema),
|
||||||
"cover": SchemaFlowFormStep(partial(basic_group_options_schema, "cover")),
|
"cover": SchemaFlowFormStep(partial(basic_group_options_schema, "cover")),
|
||||||
|
@ -18,7 +18,6 @@ from homeassistant.helpers import selector
|
|||||||
from homeassistant.helpers.schema_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
SchemaConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
SchemaFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
SchemaFlowMenuStep,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -89,12 +88,12 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
CONFIG_FLOW = {
|
||||||
"user": SchemaFlowFormStep(CONFIG_SCHEMA)
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA),
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
OPTIONS_FLOW = {
|
||||||
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ from homeassistant.helpers import selector
|
|||||||
from homeassistant.helpers.schema_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
SchemaConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
SchemaFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
SchemaFlowMenuStep,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import CONF_ENTITY_IDS, CONF_ROUND_DIGITS, DOMAIN
|
from .const import CONF_ENTITY_IDS, CONF_ROUND_DIGITS, DOMAIN
|
||||||
@ -49,12 +48,12 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
}
|
}
|
||||||
).extend(OPTIONS_SCHEMA.schema)
|
).extend(OPTIONS_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
CONFIG_FLOW = {
|
||||||
"user": SchemaFlowFormStep(CONFIG_SCHEMA)
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA),
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
OPTIONS_FLOW = {
|
||||||
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@ from homeassistant.helpers.schema_config_entry_flow import (
|
|||||||
SchemaConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
SchemaFlowError,
|
SchemaFlowError,
|
||||||
SchemaFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
SchemaFlowMenuStep,
|
|
||||||
SchemaOptionsFlowHandler,
|
SchemaOptionsFlowHandler,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.selector import (
|
from homeassistant.helpers.selector import (
|
||||||
@ -141,7 +140,7 @@ def validate_sensor_setup(user_input: dict[str, Any]) -> dict[str, Any]:
|
|||||||
DATA_SCHEMA_RESOURCE = vol.Schema(RESOURCE_SETUP)
|
DATA_SCHEMA_RESOURCE = vol.Schema(RESOURCE_SETUP)
|
||||||
DATA_SCHEMA_SENSOR = vol.Schema(SENSOR_SETUP)
|
DATA_SCHEMA_SENSOR = vol.Schema(SENSOR_SETUP)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
CONFIG_FLOW = {
|
||||||
"user": SchemaFlowFormStep(
|
"user": SchemaFlowFormStep(
|
||||||
schema=DATA_SCHEMA_RESOURCE,
|
schema=DATA_SCHEMA_RESOURCE,
|
||||||
next_step="sensor",
|
next_step="sensor",
|
||||||
@ -152,7 +151,7 @@ CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
|||||||
validate_user_input=validate_sensor_setup,
|
validate_user_input=validate_sensor_setup,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
OPTIONS_FLOW = {
|
||||||
"init": SchemaFlowFormStep(DATA_SCHEMA_RESOURCE),
|
"init": SchemaFlowFormStep(DATA_SCHEMA_RESOURCE),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ from homeassistant.helpers import entity_registry as er, selector
|
|||||||
from homeassistant.helpers.schema_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
SchemaConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
SchemaFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
SchemaFlowMenuStep,
|
|
||||||
wrapped_entity_config_entry_title,
|
wrapped_entity_config_entry_title,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ TARGET_DOMAIN_OPTIONS = [
|
|||||||
selector.SelectOptionDict(value=Platform.SIREN, label="Siren"),
|
selector.SelectOptionDict(value=Platform.SIREN, label="Siren"),
|
||||||
]
|
]
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
CONFIG_FLOW = {
|
||||||
"user": SchemaFlowFormStep(
|
"user": SchemaFlowFormStep(
|
||||||
vol.Schema(
|
vol.Schema(
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,6 @@ from homeassistant.helpers.schema_config_entry_flow import (
|
|||||||
SchemaConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
SchemaFlowError,
|
SchemaFlowError,
|
||||||
SchemaFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
SchemaFlowMenuStep,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import CONF_HYSTERESIS, CONF_LOWER, CONF_UPPER, DEFAULT_HYSTERESIS, DOMAIN
|
from .const import CONF_HYSTERESIS, CONF_LOWER, CONF_UPPER, DEFAULT_HYSTERESIS, DOMAIN
|
||||||
@ -56,11 +55,11 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
}
|
}
|
||||||
).extend(OPTIONS_SCHEMA.schema)
|
).extend(OPTIONS_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
CONFIG_FLOW = {
|
||||||
"user": SchemaFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_mode)
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
OPTIONS_FLOW = {
|
||||||
"init": SchemaFlowFormStep(OPTIONS_SCHEMA, validate_user_input=_validate_mode)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA, validate_user_input=_validate_mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ from homeassistant.helpers import selector
|
|||||||
from homeassistant.helpers.schema_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
SchemaConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
SchemaFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
SchemaFlowMenuStep,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import CONF_AFTER_TIME, CONF_BEFORE_TIME, DOMAIN
|
from .const import CONF_AFTER_TIME, CONF_BEFORE_TIME, DOMAIN
|
||||||
@ -29,12 +28,12 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
}
|
}
|
||||||
).extend(OPTIONS_SCHEMA.schema)
|
).extend(OPTIONS_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
CONFIG_FLOW = {
|
||||||
"user": SchemaFlowFormStep(CONFIG_SCHEMA)
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA),
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
OPTIONS_FLOW = {
|
||||||
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ from homeassistant.helpers.schema_config_entry_flow import (
|
|||||||
SchemaConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
SchemaFlowError,
|
SchemaFlowError,
|
||||||
SchemaFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
SchemaFlowMenuStep,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -93,12 +92,12 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
CONFIG_FLOW = {
|
||||||
"user": SchemaFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_config)
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_config)
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
OPTIONS_FLOW = {
|
||||||
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,20 +22,27 @@ class SchemaFlowError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SchemaFlowFormStep:
|
class SchemaFlowStep:
|
||||||
"""Define a config or options flow step."""
|
"""Define a config or options flow step."""
|
||||||
|
|
||||||
# Optional voluptuous schema, or function which returns a schema or None, for
|
|
||||||
# requesting and validating user input.
|
@dataclass
|
||||||
# If a function is specified, the function will be passed the handler, which is
|
class SchemaFlowFormStep(SchemaFlowStep):
|
||||||
# either an instance of SchemaConfigFlowHandler or SchemaOptionsFlowHandler, and the
|
"""Define a config or options flow form step."""
|
||||||
# union of config entry options and user input from previous steps.
|
|
||||||
# If schema validation fails, the step will be retried. If the schema is None, no
|
|
||||||
# user input is requested.
|
|
||||||
schema: vol.Schema | Callable[
|
schema: vol.Schema | Callable[
|
||||||
[SchemaConfigFlowHandler | SchemaOptionsFlowHandler, dict[str, Any]],
|
[SchemaConfigFlowHandler | SchemaOptionsFlowHandler, dict[str, Any]],
|
||||||
vol.Schema | None,
|
vol.Schema | None,
|
||||||
] | None
|
] | None
|
||||||
|
"""Optional voluptuous schema, or function which returns a schema or None, for
|
||||||
|
requesting and validating user input.
|
||||||
|
|
||||||
|
- If a function is specified, the function will be passed the handler, which is
|
||||||
|
either an instance of SchemaConfigFlowHandler or SchemaOptionsFlowHandler, and the
|
||||||
|
union of config entry options and user input from previous steps.
|
||||||
|
- If schema validation fails, the step will be retried. If the schema is None, no
|
||||||
|
user input is requested.
|
||||||
|
"""
|
||||||
|
|
||||||
validate_user_input: Callable[[dict[str, Any]], dict[str, Any]] = lambda x: x
|
validate_user_input: Callable[[dict[str, Any]], dict[str, Any]] = lambda x: x
|
||||||
"""Optional function to validate user input.
|
"""Optional function to validate user input.
|
||||||
@ -56,7 +63,7 @@ class SchemaFlowFormStep:
|
|||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SchemaFlowMenuStep:
|
class SchemaFlowMenuStep(SchemaFlowStep):
|
||||||
"""Define a config or options flow menu step."""
|
"""Define a config or options flow menu step."""
|
||||||
|
|
||||||
# Menu options
|
# Menu options
|
||||||
@ -69,7 +76,7 @@ class SchemaCommonFlowHandler:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
handler: SchemaConfigFlowHandler | SchemaOptionsFlowHandler,
|
handler: SchemaConfigFlowHandler | SchemaOptionsFlowHandler,
|
||||||
flow: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep],
|
flow: Mapping[str, SchemaFlowStep],
|
||||||
options: dict[str, Any] | None,
|
options: dict[str, Any] | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize a common handler."""
|
"""Initialize a common handler."""
|
||||||
@ -210,8 +217,8 @@ class SchemaCommonFlowHandler:
|
|||||||
class SchemaConfigFlowHandler(config_entries.ConfigFlow):
|
class SchemaConfigFlowHandler(config_entries.ConfigFlow):
|
||||||
"""Handle a schema based config flow."""
|
"""Handle a schema based config flow."""
|
||||||
|
|
||||||
config_flow: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep]
|
config_flow: Mapping[str, SchemaFlowStep]
|
||||||
options_flow: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] | None = None
|
options_flow: Mapping[str, SchemaFlowStep] | None = None
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
@ -311,7 +318,7 @@ class SchemaOptionsFlowHandler(config_entries.OptionsFlowWithConfigEntry):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
config_entry: config_entries.ConfigEntry,
|
config_entry: config_entries.ConfigEntry,
|
||||||
options_flow: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep],
|
options_flow: Mapping[str, SchemaFlowStep],
|
||||||
async_options_flow_finished: Callable[[HomeAssistant, Mapping[str, Any]], None]
|
async_options_flow_finished: Callable[[HomeAssistant, Mapping[str, Any]], None]
|
||||||
| None = None,
|
| None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user