Make SchemaFlowFormStep functions async (#82962)

* Make validate async in SchemaOptionsFlowHandler

* Adjust group

* Adjust tests

* Move all to async

* Adjust integrations

* Missed an integration

* Missed one

* Rebase to fix conflict
This commit is contained in:
epenet 2022-11-30 12:26:52 +01:00 committed by GitHub
parent 490aec0b11
commit 98f263c289
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 80 additions and 54 deletions

View file

@ -1,7 +1,7 @@
"""Config flow for Group integration."""
from __future__ import annotations
from collections.abc import Callable, Mapping
from collections.abc import Callable, Coroutine, Mapping
from functools import partial
from typing import Any, cast
@ -24,7 +24,7 @@ from .binary_sensor import CONF_ALL
from .const import CONF_HIDE_MEMBERS
def basic_group_options_schema(
async def basic_group_options_schema(
domain: str, handler: SchemaCommonFlowHandler
) -> vol.Schema:
"""Generate options schema."""
@ -52,9 +52,9 @@ def basic_group_config_schema(domain: str) -> vol.Schema:
)
def binary_sensor_options_schema(handler: SchemaCommonFlowHandler) -> vol.Schema:
async def binary_sensor_options_schema(handler: SchemaCommonFlowHandler) -> vol.Schema:
"""Generate options schema."""
return basic_group_options_schema("binary_sensor", handler).extend(
return (await basic_group_options_schema("binary_sensor", handler)).extend(
{
vol.Required(CONF_ALL, default=False): selector.BooleanSelector(),
}
@ -68,11 +68,11 @@ BINARY_SENSOR_CONFIG_SCHEMA = basic_group_config_schema("binary_sensor").extend(
)
def light_switch_options_schema(
async def light_switch_options_schema(
domain: str, handler: SchemaCommonFlowHandler
) -> vol.Schema:
"""Generate options schema."""
return basic_group_options_schema(domain, handler).extend(
return (await basic_group_options_schema(domain, handler)).extend(
{
vol.Required(
CONF_ALL, default=False, description={"advanced": True}
@ -92,19 +92,19 @@ GROUP_TYPES = [
]
@callback
def choose_options_step(options: dict[str, Any]) -> str:
async def choose_options_step(options: dict[str, Any]) -> str:
"""Return next step_id for options flow according to group_type."""
return cast(str, options["group_type"])
def set_group_type(
group_type: str,
) -> Callable[[SchemaCommonFlowHandler, dict[str, Any]], dict[str, Any]]:
) -> Callable[
[SchemaCommonFlowHandler, dict[str, Any]], Coroutine[Any, Any, dict[str, Any]]
]:
"""Set group type."""
@callback
def _set_group_type(
async def _set_group_type(
handler: SchemaCommonFlowHandler, user_input: dict[str, Any]
) -> dict[str, Any]:
"""Add group type to user input."""
@ -116,23 +116,32 @@ def set_group_type(
CONFIG_FLOW = {
"user": SchemaFlowMenuStep(GROUP_TYPES),
"binary_sensor": SchemaFlowFormStep(
BINARY_SENSOR_CONFIG_SCHEMA, set_group_type("binary_sensor")
BINARY_SENSOR_CONFIG_SCHEMA,
validate_user_input=set_group_type("binary_sensor"),
),
"cover": SchemaFlowFormStep(
basic_group_config_schema("cover"), set_group_type("cover")
basic_group_config_schema("cover"),
validate_user_input=set_group_type("cover"),
),
"fan": SchemaFlowFormStep(
basic_group_config_schema("fan"),
validate_user_input=set_group_type("fan"),
),
"fan": SchemaFlowFormStep(basic_group_config_schema("fan"), set_group_type("fan")),
"light": SchemaFlowFormStep(
basic_group_config_schema("light"), set_group_type("light")
basic_group_config_schema("light"),
validate_user_input=set_group_type("light"),
),
"lock": SchemaFlowFormStep(
basic_group_config_schema("lock"), set_group_type("lock")
basic_group_config_schema("lock"),
validate_user_input=set_group_type("lock"),
),
"media_player": SchemaFlowFormStep(
basic_group_config_schema("media_player"), set_group_type("media_player")
basic_group_config_schema("media_player"),
validate_user_input=set_group_type("media_player"),
),
"switch": SchemaFlowFormStep(
basic_group_config_schema("switch"), set_group_type("switch")
basic_group_config_schema("switch"),
validate_user_input=set_group_type("switch"),
),
}