Rename helper_config_entry_flow to schema_config_entry_flow (#68924)
This commit is contained in:
parent
475b9e212d
commit
d38382fbe3
11 changed files with 147 additions and 147 deletions
|
@ -16,10 +16,10 @@ from homeassistant.const import (
|
||||||
TIME_SECONDS,
|
TIME_SECONDS,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers import selector
|
from homeassistant.helpers import selector
|
||||||
from homeassistant.helpers.helper_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
HelperConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
HelperFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
HelperFlowMenuStep,
|
SchemaFlowMenuStep,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
@ -78,16 +78,16 @@ CONFIG_SCHEMA = vol.Schema(
|
||||||
}
|
}
|
||||||
).extend(OPTIONS_SCHEMA.schema)
|
).extend(OPTIONS_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"user": HelperFlowFormStep(CONFIG_SCHEMA)
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"init": HelperFlowFormStep(OPTIONS_SCHEMA)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN):
|
class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN):
|
||||||
"""Handle a config or options flow for Derivative."""
|
"""Handle a config or options flow for Derivative."""
|
||||||
|
|
||||||
config_flow = CONFIG_FLOW
|
config_flow = CONFIG_FLOW
|
||||||
|
|
|
@ -10,11 +10,11 @@ import voluptuous as vol
|
||||||
from homeassistant.const import CONF_ENTITIES
|
from homeassistant.const import CONF_ENTITIES
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import entity_registry as er, selector
|
from homeassistant.helpers import entity_registry as er, selector
|
||||||
from homeassistant.helpers.helper_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
HelperConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
HelperFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
HelperFlowMenuStep,
|
SchemaFlowMenuStep,
|
||||||
HelperOptionsFlowHandler,
|
SchemaOptionsFlowHandler,
|
||||||
entity_selector_without_own_entities,
|
entity_selector_without_own_entities,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,11 +25,11 @@ from .const import CONF_HIDE_MEMBERS
|
||||||
|
|
||||||
def basic_group_options_schema(
|
def basic_group_options_schema(
|
||||||
domain: str,
|
domain: str,
|
||||||
handler: HelperConfigFlowHandler | HelperOptionsFlowHandler,
|
handler: SchemaConfigFlowHandler | SchemaOptionsFlowHandler,
|
||||||
options: dict[str, Any],
|
options: dict[str, Any],
|
||||||
) -> vol.Schema:
|
) -> vol.Schema:
|
||||||
"""Generate options schema."""
|
"""Generate options schema."""
|
||||||
handler = cast(HelperOptionsFlowHandler, handler)
|
handler = cast(SchemaOptionsFlowHandler, handler)
|
||||||
return vol.Schema(
|
return vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_ENTITIES): entity_selector_without_own_entities(
|
vol.Required(CONF_ENTITIES): entity_selector_without_own_entities(
|
||||||
|
@ -58,7 +58,7 @@ def basic_group_config_schema(domain: str) -> vol.Schema:
|
||||||
|
|
||||||
|
|
||||||
def binary_sensor_options_schema(
|
def binary_sensor_options_schema(
|
||||||
handler: HelperConfigFlowHandler | HelperOptionsFlowHandler,
|
handler: SchemaConfigFlowHandler | SchemaOptionsFlowHandler,
|
||||||
options: dict[str, Any],
|
options: dict[str, Any],
|
||||||
) -> vol.Schema:
|
) -> vol.Schema:
|
||||||
"""Generate options schema."""
|
"""Generate options schema."""
|
||||||
|
@ -78,7 +78,7 @@ BINARY_SENSOR_CONFIG_SCHEMA = basic_group_config_schema("binary_sensor").extend(
|
||||||
|
|
||||||
def light_switch_options_schema(
|
def light_switch_options_schema(
|
||||||
domain: str,
|
domain: str,
|
||||||
handler: HelperConfigFlowHandler | HelperOptionsFlowHandler,
|
handler: SchemaConfigFlowHandler | SchemaOptionsFlowHandler,
|
||||||
options: dict[str, Any],
|
options: dict[str, Any],
|
||||||
) -> vol.Schema:
|
) -> vol.Schema:
|
||||||
"""Generate options schema."""
|
"""Generate options schema."""
|
||||||
|
@ -119,45 +119,45 @@ 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, HelperFlowFormStep | HelperFlowMenuStep] = {
|
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"user": HelperFlowMenuStep(GROUP_TYPES),
|
"user": SchemaFlowMenuStep(GROUP_TYPES),
|
||||||
"binary_sensor": HelperFlowFormStep(
|
"binary_sensor": SchemaFlowFormStep(
|
||||||
BINARY_SENSOR_CONFIG_SCHEMA, set_group_type("binary_sensor")
|
BINARY_SENSOR_CONFIG_SCHEMA, set_group_type("binary_sensor")
|
||||||
),
|
),
|
||||||
"cover": HelperFlowFormStep(
|
"cover": SchemaFlowFormStep(
|
||||||
basic_group_config_schema("cover"), set_group_type("cover")
|
basic_group_config_schema("cover"), set_group_type("cover")
|
||||||
),
|
),
|
||||||
"fan": HelperFlowFormStep(basic_group_config_schema("fan"), set_group_type("fan")),
|
"fan": SchemaFlowFormStep(basic_group_config_schema("fan"), set_group_type("fan")),
|
||||||
"light": HelperFlowFormStep(
|
"light": SchemaFlowFormStep(
|
||||||
basic_group_config_schema("light"), set_group_type("light")
|
basic_group_config_schema("light"), set_group_type("light")
|
||||||
),
|
),
|
||||||
"lock": HelperFlowFormStep(
|
"lock": SchemaFlowFormStep(
|
||||||
basic_group_config_schema("lock"), set_group_type("lock")
|
basic_group_config_schema("lock"), set_group_type("lock")
|
||||||
),
|
),
|
||||||
"media_player": HelperFlowFormStep(
|
"media_player": SchemaFlowFormStep(
|
||||||
basic_group_config_schema("media_player"), set_group_type("media_player")
|
basic_group_config_schema("media_player"), set_group_type("media_player")
|
||||||
),
|
),
|
||||||
"switch": HelperFlowFormStep(
|
"switch": SchemaFlowFormStep(
|
||||||
basic_group_config_schema("switch"), set_group_type("switch")
|
basic_group_config_schema("switch"), set_group_type("switch")
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"init": HelperFlowFormStep(None, next_step=choose_options_step),
|
"init": SchemaFlowFormStep(None, next_step=choose_options_step),
|
||||||
"binary_sensor": HelperFlowFormStep(binary_sensor_options_schema),
|
"binary_sensor": SchemaFlowFormStep(binary_sensor_options_schema),
|
||||||
"cover": HelperFlowFormStep(partial(basic_group_options_schema, "cover")),
|
"cover": SchemaFlowFormStep(partial(basic_group_options_schema, "cover")),
|
||||||
"fan": HelperFlowFormStep(partial(basic_group_options_schema, "fan")),
|
"fan": SchemaFlowFormStep(partial(basic_group_options_schema, "fan")),
|
||||||
"light": HelperFlowFormStep(partial(light_switch_options_schema, "light")),
|
"light": SchemaFlowFormStep(partial(light_switch_options_schema, "light")),
|
||||||
"lock": HelperFlowFormStep(partial(basic_group_options_schema, "lock")),
|
"lock": SchemaFlowFormStep(partial(basic_group_options_schema, "lock")),
|
||||||
"media_player": HelperFlowFormStep(
|
"media_player": SchemaFlowFormStep(
|
||||||
partial(basic_group_options_schema, "media_player")
|
partial(basic_group_options_schema, "media_player")
|
||||||
),
|
),
|
||||||
"switch": HelperFlowFormStep(partial(light_switch_options_schema, "switch")),
|
"switch": SchemaFlowFormStep(partial(light_switch_options_schema, "switch")),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class GroupConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN):
|
class GroupConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN):
|
||||||
"""Handle a config or options flow for groups."""
|
"""Handle a config or options flow for groups."""
|
||||||
|
|
||||||
config_flow = CONFIG_FLOW
|
config_flow = CONFIG_FLOW
|
||||||
|
|
|
@ -16,10 +16,10 @@ from homeassistant.const import (
|
||||||
TIME_SECONDS,
|
TIME_SECONDS,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers import selector
|
from homeassistant.helpers import selector
|
||||||
from homeassistant.helpers.helper_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
HelperConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
HelperFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
HelperFlowMenuStep,
|
SchemaFlowMenuStep,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
@ -88,16 +88,16 @@ CONFIG_SCHEMA = vol.Schema(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"user": HelperFlowFormStep(CONFIG_SCHEMA)
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"init": HelperFlowFormStep(OPTIONS_SCHEMA)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN):
|
class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN):
|
||||||
"""Handle a config or options flow for Integration."""
|
"""Handle a config or options flow for Integration."""
|
||||||
|
|
||||||
config_flow = CONFIG_FLOW
|
config_flow = CONFIG_FLOW
|
||||||
|
|
|
@ -8,10 +8,10 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_TYPE
|
from homeassistant.const import CONF_TYPE
|
||||||
from homeassistant.helpers import selector
|
from homeassistant.helpers import selector
|
||||||
from homeassistant.helpers.helper_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
HelperConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
HelperFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
HelperFlowMenuStep,
|
SchemaFlowMenuStep,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import CONF_ENTITY_IDS, CONF_ROUND_DIGITS, DOMAIN
|
from .const import CONF_ENTITY_IDS, CONF_ROUND_DIGITS, DOMAIN
|
||||||
|
@ -38,16 +38,16 @@ CONFIG_SCHEMA = vol.Schema(
|
||||||
}
|
}
|
||||||
).extend(OPTIONS_SCHEMA.schema)
|
).extend(OPTIONS_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"user": HelperFlowFormStep(CONFIG_SCHEMA)
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"init": HelperFlowFormStep(OPTIONS_SCHEMA)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN):
|
class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN):
|
||||||
"""Handle a config or options flow for Min/Max."""
|
"""Handle a config or options flow for Min/Max."""
|
||||||
|
|
||||||
config_flow = CONFIG_FLOW
|
config_flow = CONFIG_FLOW
|
||||||
|
|
|
@ -8,17 +8,17 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_ENTITY_ID, Platform
|
from homeassistant.const import CONF_ENTITY_ID, Platform
|
||||||
from homeassistant.helpers import entity_registry as er, selector
|
from homeassistant.helpers import entity_registry as er, selector
|
||||||
from homeassistant.helpers.helper_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
HelperConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
HelperFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
HelperFlowMenuStep,
|
SchemaFlowMenuStep,
|
||||||
wrapped_entity_config_entry_title,
|
wrapped_entity_config_entry_title,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import CONF_TARGET_DOMAIN, DOMAIN
|
from .const import CONF_TARGET_DOMAIN, DOMAIN
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"user": HelperFlowFormStep(
|
"user": SchemaFlowFormStep(
|
||||||
vol.Schema(
|
vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_ENTITY_ID): selector.selector(
|
vol.Required(CONF_ENTITY_ID): selector.selector(
|
||||||
|
@ -43,7 +43,7 @@ CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class SwitchAsXConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN):
|
class SwitchAsXConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN):
|
||||||
"""Handle a config flow for Switch as X."""
|
"""Handle a config flow for Switch as X."""
|
||||||
|
|
||||||
config_flow = CONFIG_FLOW
|
config_flow = CONFIG_FLOW
|
||||||
|
|
|
@ -8,11 +8,11 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_ENTITY_ID, CONF_NAME
|
from homeassistant.const import CONF_ENTITY_ID, CONF_NAME
|
||||||
from homeassistant.helpers import selector
|
from homeassistant.helpers import selector
|
||||||
from homeassistant.helpers.helper_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
HelperConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
HelperFlowError,
|
SchemaFlowError,
|
||||||
HelperFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
HelperFlowMenuStep,
|
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
|
||||||
|
@ -21,7 +21,7 @@ from .const import CONF_HYSTERESIS, CONF_LOWER, CONF_UPPER, DEFAULT_HYSTERESIS,
|
||||||
def _validate_mode(data: Any) -> Any:
|
def _validate_mode(data: Any) -> Any:
|
||||||
"""Validate the threshold mode, and set limits to None if not set."""
|
"""Validate the threshold mode, and set limits to None if not set."""
|
||||||
if CONF_LOWER not in data and CONF_UPPER not in data:
|
if CONF_LOWER not in data and CONF_UPPER not in data:
|
||||||
raise HelperFlowError("need_lower_upper")
|
raise SchemaFlowError("need_lower_upper")
|
||||||
return {CONF_LOWER: None, CONF_UPPER: None, **data}
|
return {CONF_LOWER: None, CONF_UPPER: None, **data}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,16 +44,16 @@ CONFIG_SCHEMA = vol.Schema(
|
||||||
}
|
}
|
||||||
).extend(OPTIONS_SCHEMA.schema)
|
).extend(OPTIONS_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"user": HelperFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_mode)
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"init": HelperFlowFormStep(OPTIONS_SCHEMA, validate_user_input=_validate_mode)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA, validate_user_input=_validate_mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN):
|
class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN):
|
||||||
"""Handle a config or options flow for Threshold."""
|
"""Handle a config or options flow for Threshold."""
|
||||||
|
|
||||||
config_flow = CONFIG_FLOW
|
config_flow = CONFIG_FLOW
|
||||||
|
|
|
@ -8,10 +8,10 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import CONF_NAME
|
||||||
from homeassistant.helpers import selector
|
from homeassistant.helpers import selector
|
||||||
from homeassistant.helpers.helper_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
HelperConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
HelperFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
HelperFlowMenuStep,
|
SchemaFlowMenuStep,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import CONF_AFTER_TIME, CONF_BEFORE_TIME, DOMAIN
|
from .const import CONF_AFTER_TIME, CONF_BEFORE_TIME, DOMAIN
|
||||||
|
@ -29,16 +29,16 @@ CONFIG_SCHEMA = vol.Schema(
|
||||||
}
|
}
|
||||||
).extend(OPTIONS_SCHEMA.schema)
|
).extend(OPTIONS_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"user": HelperFlowFormStep(CONFIG_SCHEMA)
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"init": HelperFlowFormStep(OPTIONS_SCHEMA)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN):
|
class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN):
|
||||||
"""Handle a config or options flow for Times of the Day."""
|
"""Handle a config or options flow for Times of the Day."""
|
||||||
|
|
||||||
config_flow = CONFIG_FLOW
|
config_flow = CONFIG_FLOW
|
||||||
|
|
|
@ -8,11 +8,11 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_NAME, CONF_UNIT_OF_MEASUREMENT
|
from homeassistant.const import CONF_NAME, CONF_UNIT_OF_MEASUREMENT
|
||||||
from homeassistant.helpers import selector
|
from homeassistant.helpers import selector
|
||||||
from homeassistant.helpers.helper_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
HelperConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
HelperFlowError,
|
SchemaFlowError,
|
||||||
HelperFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
HelperFlowMenuStep,
|
SchemaFlowMenuStep,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
@ -56,7 +56,7 @@ def _validate_config(data: Any) -> Any:
|
||||||
try:
|
try:
|
||||||
vol.Unique()(tariffs)
|
vol.Unique()(tariffs)
|
||||||
except vol.Invalid as exc:
|
except vol.Invalid as exc:
|
||||||
raise HelperFlowError("tariffs_not_unique") from exc
|
raise SchemaFlowError("tariffs_not_unique") from exc
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -98,16 +98,16 @@ CONFIG_SCHEMA = vol.Schema(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"user": HelperFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_config)
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_config)
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"init": HelperFlowFormStep(OPTIONS_SCHEMA)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN):
|
class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN):
|
||||||
"""Handle a config or options flow for Utility Meter."""
|
"""Handle a config or options flow for Utility Meter."""
|
||||||
|
|
||||||
config_flow = CONFIG_FLOW
|
config_flow = CONFIG_FLOW
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"""Helpers for data entry flows for helper config entries."""
|
"""Helpers for creating schema based data entry flows."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
|
@ -17,25 +17,25 @@ from homeassistant.data_entry_flow import FlowResult, UnknownHandler
|
||||||
from . import entity_registry as er, selector
|
from . import entity_registry as er, selector
|
||||||
|
|
||||||
|
|
||||||
class HelperFlowError(Exception):
|
class SchemaFlowError(Exception):
|
||||||
"""Validation failed."""
|
"""Validation failed."""
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class HelperFlowFormStep:
|
class SchemaFlowFormStep:
|
||||||
"""Define a helper config or options flow step."""
|
"""Define a config or options flow step."""
|
||||||
|
|
||||||
# Optional schema for requesting and validating user input. If schema validation
|
# Optional schema for requesting and validating user input. If schema validation
|
||||||
# fails, the step will be retried. If the schema is None, no user input is requested.
|
# fails, the step will be retried. If the schema is None, no user input is requested.
|
||||||
schema: vol.Schema | Callable[
|
schema: vol.Schema | Callable[
|
||||||
[HelperConfigFlowHandler | HelperOptionsFlowHandler, dict[str, Any]],
|
[SchemaConfigFlowHandler | SchemaOptionsFlowHandler, dict[str, Any]],
|
||||||
vol.Schema | None,
|
vol.Schema | None,
|
||||||
] | None
|
] | None
|
||||||
|
|
||||||
# Optional function to validate user input.
|
# Optional function to validate user input.
|
||||||
# The validate_user_input function is called if the schema validates successfully.
|
# The validate_user_input function is called if the schema validates successfully.
|
||||||
# The validate_user_input function is passed the user input from the current step.
|
# The validate_user_input function is passed the user input from the current step.
|
||||||
# The validate_user_input should raise HelperFlowError is user input is invalid.
|
# The validate_user_input should raise SchemaFlowError is user input is invalid.
|
||||||
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 identify next step.
|
# Optional function to identify next step.
|
||||||
|
@ -48,11 +48,11 @@ class HelperFlowFormStep:
|
||||||
# Optional function to allow amending a form schema.
|
# Optional function to allow amending a form schema.
|
||||||
# The update_form_schema function is called before async_show_form is called. The
|
# The update_form_schema function is called before async_show_form is called. The
|
||||||
# update_form_schema function is passed the handler, which is either an instance of
|
# update_form_schema function is passed the handler, which is either an instance of
|
||||||
# HelperConfigFlowHandler or HelperOptionsFlowHandler, the schema, and the union of
|
# SchemaConfigFlowHandler or SchemaOptionsFlowHandler, the schema, and the union of
|
||||||
# config entry options and user input from previous steps.
|
# config entry options and user input from previous steps.
|
||||||
update_form_schema: Callable[
|
update_form_schema: Callable[
|
||||||
[
|
[
|
||||||
HelperConfigFlowHandler | HelperOptionsFlowHandler,
|
SchemaConfigFlowHandler | SchemaOptionsFlowHandler,
|
||||||
vol.Schema,
|
vol.Schema,
|
||||||
dict[str, Any],
|
dict[str, Any],
|
||||||
],
|
],
|
||||||
|
@ -61,20 +61,20 @@ class HelperFlowFormStep:
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class HelperFlowMenuStep:
|
class SchemaFlowMenuStep:
|
||||||
"""Define a helper config or options flow menu step."""
|
"""Define a config or options flow menu step."""
|
||||||
|
|
||||||
# Menu options
|
# Menu options
|
||||||
options: list[str] | dict[str, str]
|
options: list[str] | dict[str, str]
|
||||||
|
|
||||||
|
|
||||||
class HelperCommonFlowHandler:
|
class SchemaCommonFlowHandler:
|
||||||
"""Handle a config or options flow for helper."""
|
"""Handle a schema based config or options flow."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
handler: HelperConfigFlowHandler | HelperOptionsFlowHandler,
|
handler: SchemaConfigFlowHandler | SchemaOptionsFlowHandler,
|
||||||
flow: dict[str, HelperFlowFormStep | HelperFlowMenuStep],
|
flow: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep],
|
||||||
config_entry: config_entries.ConfigEntry | None,
|
config_entry: config_entries.ConfigEntry | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize a common handler."""
|
"""Initialize a common handler."""
|
||||||
|
@ -86,12 +86,12 @@ class HelperCommonFlowHandler:
|
||||||
self, step_id: str, user_input: dict[str, Any] | None = None
|
self, step_id: str, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle a step."""
|
"""Handle a step."""
|
||||||
if isinstance(self._flow[step_id], HelperFlowFormStep):
|
if isinstance(self._flow[step_id], SchemaFlowFormStep):
|
||||||
return await self._async_form_step(step_id, user_input)
|
return await self._async_form_step(step_id, user_input)
|
||||||
return await self._async_menu_step(step_id, user_input)
|
return await self._async_menu_step(step_id, user_input)
|
||||||
|
|
||||||
def _get_schema(
|
def _get_schema(
|
||||||
self, form_step: HelperFlowFormStep, options: dict[str, Any]
|
self, form_step: SchemaFlowFormStep, options: dict[str, Any]
|
||||||
) -> vol.Schema | None:
|
) -> vol.Schema | None:
|
||||||
if form_step.schema is None:
|
if form_step.schema is None:
|
||||||
return None
|
return None
|
||||||
|
@ -103,7 +103,7 @@ class HelperCommonFlowHandler:
|
||||||
self, step_id: str, user_input: dict[str, Any] | None = None
|
self, step_id: str, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle a form step."""
|
"""Handle a form step."""
|
||||||
form_step: HelperFlowFormStep = cast(HelperFlowFormStep, self._flow[step_id])
|
form_step: SchemaFlowFormStep = cast(SchemaFlowFormStep, self._flow[step_id])
|
||||||
|
|
||||||
if (
|
if (
|
||||||
user_input is not None
|
user_input is not None
|
||||||
|
@ -126,7 +126,7 @@ class HelperCommonFlowHandler:
|
||||||
# Do extra validation of user input
|
# Do extra validation of user input
|
||||||
try:
|
try:
|
||||||
user_input = form_step.validate_user_input(user_input)
|
user_input = form_step.validate_user_input(user_input)
|
||||||
except HelperFlowError as exc:
|
except SchemaFlowError as exc:
|
||||||
return self._show_next_step(step_id, exc, user_input)
|
return self._show_next_step(step_id, exc, user_input)
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
|
@ -148,12 +148,12 @@ class HelperCommonFlowHandler:
|
||||||
def _show_next_step(
|
def _show_next_step(
|
||||||
self,
|
self,
|
||||||
next_step_id: str,
|
next_step_id: str,
|
||||||
error: HelperFlowError | None = None,
|
error: SchemaFlowError | None = None,
|
||||||
user_input: dict[str, Any] | None = None,
|
user_input: dict[str, Any] | None = None,
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Show form for next step."""
|
"""Show form for next step."""
|
||||||
form_step: HelperFlowFormStep = cast(
|
form_step: SchemaFlowFormStep = cast(
|
||||||
HelperFlowFormStep, self._flow[next_step_id]
|
SchemaFlowFormStep, self._flow[next_step_id]
|
||||||
)
|
)
|
||||||
|
|
||||||
options = dict(self._options)
|
options = dict(self._options)
|
||||||
|
@ -195,18 +195,18 @@ class HelperCommonFlowHandler:
|
||||||
self, step_id: str, user_input: dict[str, Any] | None = None
|
self, step_id: str, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle a menu step."""
|
"""Handle a menu step."""
|
||||||
form_step: HelperFlowMenuStep = cast(HelperFlowMenuStep, self._flow[step_id])
|
form_step: SchemaFlowMenuStep = cast(SchemaFlowMenuStep, self._flow[step_id])
|
||||||
return self._handler.async_show_menu(
|
return self._handler.async_show_menu(
|
||||||
step_id=step_id,
|
step_id=step_id,
|
||||||
menu_options=form_step.options,
|
menu_options=form_step.options,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class HelperConfigFlowHandler(config_entries.ConfigFlow):
|
class SchemaConfigFlowHandler(config_entries.ConfigFlow):
|
||||||
"""Handle a config flow for helper integrations."""
|
"""Handle a schema based config flow."""
|
||||||
|
|
||||||
config_flow: dict[str, HelperFlowFormStep | HelperFlowMenuStep]
|
config_flow: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep]
|
||||||
options_flow: dict[str, HelperFlowFormStep | HelperFlowMenuStep] | None = None
|
options_flow: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] | None = None
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ class HelperConfigFlowHandler(config_entries.ConfigFlow):
|
||||||
if cls.options_flow is None:
|
if cls.options_flow is None:
|
||||||
raise UnknownHandler
|
raise UnknownHandler
|
||||||
|
|
||||||
return HelperOptionsFlowHandler(
|
return SchemaOptionsFlowHandler(
|
||||||
config_entry, cls.options_flow, cls.async_options_flow_finished
|
config_entry, cls.options_flow, cls.async_options_flow_finished
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ class HelperConfigFlowHandler(config_entries.ConfigFlow):
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize config flow."""
|
"""Initialize config flow."""
|
||||||
self._common_handler = HelperCommonFlowHandler(self, self.config_flow, None)
|
self._common_handler = SchemaCommonFlowHandler(self, self.config_flow, None)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@callback
|
@callback
|
||||||
|
@ -250,7 +250,7 @@ class HelperConfigFlowHandler(config_entries.ConfigFlow):
|
||||||
"""Generate a step handler."""
|
"""Generate a step handler."""
|
||||||
|
|
||||||
async def _async_step(
|
async def _async_step(
|
||||||
self: HelperConfigFlowHandler, user_input: dict[str, Any] | None = None
|
self: SchemaConfigFlowHandler, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle a config flow step."""
|
"""Handle a config flow step."""
|
||||||
# pylint: disable-next=protected-access
|
# pylint: disable-next=protected-access
|
||||||
|
@ -300,8 +300,8 @@ class HelperConfigFlowHandler(config_entries.ConfigFlow):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class HelperOptionsFlowHandler(config_entries.OptionsFlow):
|
class SchemaOptionsFlowHandler(config_entries.OptionsFlow):
|
||||||
"""Handle an options flow for helper integrations."""
|
"""Handle a schema based options flow."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -310,7 +310,7 @@ class HelperOptionsFlowHandler(config_entries.OptionsFlow):
|
||||||
async_options_flow_finished: Callable[[HomeAssistant, Mapping[str, Any]], None],
|
async_options_flow_finished: Callable[[HomeAssistant, Mapping[str, Any]], None],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize options flow."""
|
"""Initialize options flow."""
|
||||||
self._common_handler = HelperCommonFlowHandler(self, options_flow, config_entry)
|
self._common_handler = SchemaCommonFlowHandler(self, options_flow, config_entry)
|
||||||
self.config_entry = config_entry
|
self.config_entry = config_entry
|
||||||
self._async_options_flow_finished = async_options_flow_finished
|
self._async_options_flow_finished = async_options_flow_finished
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ class HelperOptionsFlowHandler(config_entries.OptionsFlow):
|
||||||
"""Generate a step handler."""
|
"""Generate a step handler."""
|
||||||
|
|
||||||
async def _async_step(
|
async def _async_step(
|
||||||
self: HelperConfigFlowHandler, user_input: dict[str, Any] | None = None
|
self: SchemaConfigFlowHandler, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Handle an options flow step."""
|
"""Handle an options flow step."""
|
||||||
# pylint: disable-next=protected-access
|
# pylint: disable-next=protected-access
|
||||||
|
@ -370,7 +370,7 @@ def wrapped_entity_config_entry_title(
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def entity_selector_without_own_entities(
|
def entity_selector_without_own_entities(
|
||||||
handler: HelperOptionsFlowHandler,
|
handler: SchemaOptionsFlowHandler,
|
||||||
entity_selector_config: dict[str, Any],
|
entity_selector_config: dict[str, Any],
|
||||||
) -> vol.Schema:
|
) -> vol.Schema:
|
||||||
"""Return an entity selector which excludes own entities."""
|
"""Return an entity selector which excludes own entities."""
|
|
@ -8,10 +8,10 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_ENTITY_ID
|
from homeassistant.const import CONF_ENTITY_ID
|
||||||
from homeassistant.helpers import selector
|
from homeassistant.helpers import selector
|
||||||
from homeassistant.helpers.helper_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
HelperConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
HelperFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
HelperFlowMenuStep,
|
SchemaFlowMenuStep,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
@ -30,16 +30,16 @@ CONFIG_SCHEMA = vol.Schema(
|
||||||
}
|
}
|
||||||
).extend(OPTIONS_SCHEMA.schema)
|
).extend(OPTIONS_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"user": HelperFlowFormStep(CONFIG_SCHEMA)
|
"user": SchemaFlowFormStep(CONFIG_SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"init": HelperFlowFormStep(OPTIONS_SCHEMA)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN):
|
class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN):
|
||||||
"""Handle a config or options flow for NEW_NAME."""
|
"""Handle a config or options flow for NEW_NAME."""
|
||||||
|
|
||||||
config_flow = CONFIG_FLOW
|
config_flow = CONFIG_FLOW
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
"""Test helper_config_entry_flow."""
|
"""Test schema_config_entry_flow."""
|
||||||
import pytest
|
import pytest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.helper_config_entry_flow import (
|
from homeassistant.helpers.schema_config_entry_flow import (
|
||||||
HelperConfigFlowHandler,
|
SchemaConfigFlowHandler,
|
||||||
HelperFlowFormStep,
|
SchemaFlowFormStep,
|
||||||
HelperFlowMenuStep,
|
SchemaFlowMenuStep,
|
||||||
wrapped_entity_config_entry_title,
|
wrapped_entity_config_entry_title,
|
||||||
)
|
)
|
||||||
from homeassistant.util.decorator import Registry
|
from homeassistant.util.decorator import Registry
|
||||||
|
@ -100,12 +100,12 @@ async def test_config_flow_advanced_option(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"init": HelperFlowFormStep(CONFIG_SCHEMA)
|
"init": SchemaFlowFormStep(CONFIG_SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
@manager.mock_reg_handler("test")
|
@manager.mock_reg_handler("test")
|
||||||
class TestFlow(HelperConfigFlowHandler):
|
class TestFlow(SchemaConfigFlowHandler):
|
||||||
config_flow = CONFIG_FLOW
|
config_flow = CONFIG_FLOW
|
||||||
|
|
||||||
# Start flow in basic mode
|
# Start flow in basic mode
|
||||||
|
@ -195,11 +195,11 @@ async def test_options_flow_advanced_option(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
|
OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
|
||||||
"init": HelperFlowFormStep(OPTIONS_SCHEMA)
|
"init": SchemaFlowFormStep(OPTIONS_SCHEMA)
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestFlow(HelperConfigFlowHandler, domain="test"):
|
class TestFlow(SchemaConfigFlowHandler, domain="test"):
|
||||||
config_flow = {}
|
config_flow = {}
|
||||||
options_flow = OPTIONS_FLOW
|
options_flow = OPTIONS_FLOW
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue