Rename HelperFlowStep to HelperFlowFormStep (#68583)

This commit is contained in:
Erik Montnemery 2022-03-23 22:43:11 +01:00 committed by GitHub
parent 29a43cef0b
commit c44d7205cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 44 deletions

View file

@ -18,8 +18,8 @@ from homeassistant.const import (
from homeassistant.helpers import selector from homeassistant.helpers import selector
from homeassistant.helpers.helper_config_entry_flow import ( from homeassistant.helpers.helper_config_entry_flow import (
HelperConfigFlowHandler, HelperConfigFlowHandler,
HelperFlowFormStep,
HelperFlowMenuStep, HelperFlowMenuStep,
HelperFlowStep,
) )
from .const import ( from .const import (
@ -78,12 +78,12 @@ CONFIG_SCHEMA = vol.Schema(
} }
).extend(OPTIONS_SCHEMA.schema) ).extend(OPTIONS_SCHEMA.schema)
CONFIG_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
"user": HelperFlowStep(CONFIG_SCHEMA) "user": HelperFlowFormStep(CONFIG_SCHEMA)
} }
OPTIONS_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
"init": HelperFlowStep(OPTIONS_SCHEMA) "init": HelperFlowFormStep(OPTIONS_SCHEMA)
} }

View file

@ -11,8 +11,8 @@ 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.helper_config_entry_flow import (
HelperConfigFlowHandler, HelperConfigFlowHandler,
HelperFlowFormStep,
HelperFlowMenuStep, HelperFlowMenuStep,
HelperFlowStep,
) )
from . import DOMAIN from . import DOMAIN
@ -82,29 +82,29 @@ 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, HelperFlowStep | HelperFlowMenuStep] = { CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
"user": HelperFlowMenuStep(GROUP_TYPES), "user": HelperFlowMenuStep(GROUP_TYPES),
"binary_sensor": HelperFlowStep( "binary_sensor": HelperFlowFormStep(
BINARY_SENSOR_CONFIG_SCHEMA, set_group_type("binary_sensor") BINARY_SENSOR_CONFIG_SCHEMA, set_group_type("binary_sensor")
), ),
"cover": HelperFlowStep( "cover": HelperFlowFormStep(
basic_group_config_schema("cover"), set_group_type("cover") basic_group_config_schema("cover"), set_group_type("cover")
), ),
"fan": HelperFlowStep(basic_group_config_schema("fan"), set_group_type("fan")), "fan": HelperFlowFormStep(basic_group_config_schema("fan"), set_group_type("fan")),
"light": HelperFlowStep(LIGHT_CONFIG_SCHEMA, set_group_type("light")), "light": HelperFlowFormStep(LIGHT_CONFIG_SCHEMA, set_group_type("light")),
"media_player": HelperFlowStep( "media_player": HelperFlowFormStep(
basic_group_config_schema("media_player"), set_group_type("media_player") basic_group_config_schema("media_player"), set_group_type("media_player")
), ),
} }
OPTIONS_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
"init": HelperFlowStep(None, next_step=choose_options_step), "init": HelperFlowFormStep(None, next_step=choose_options_step),
"binary_sensor": HelperFlowStep(BINARY_SENSOR_OPTIONS_SCHEMA), "binary_sensor": HelperFlowFormStep(BINARY_SENSOR_OPTIONS_SCHEMA),
"cover": HelperFlowStep(basic_group_options_schema("cover")), "cover": HelperFlowFormStep(basic_group_options_schema("cover")),
"fan": HelperFlowStep(basic_group_options_schema("fan")), "fan": HelperFlowFormStep(basic_group_options_schema("fan")),
"light": HelperFlowStep(LIGHT_OPTIONS_SCHEMA), "light": HelperFlowFormStep(LIGHT_OPTIONS_SCHEMA),
"media_player": HelperFlowStep(basic_group_options_schema("media_player")), "media_player": HelperFlowFormStep(basic_group_options_schema("media_player")),
} }

View file

@ -18,8 +18,8 @@ from homeassistant.const import (
from homeassistant.helpers import selector from homeassistant.helpers import selector
from homeassistant.helpers.helper_config_entry_flow import ( from homeassistant.helpers.helper_config_entry_flow import (
HelperConfigFlowHandler, HelperConfigFlowHandler,
HelperFlowFormStep,
HelperFlowMenuStep, HelperFlowMenuStep,
HelperFlowStep,
) )
from .const import ( from .const import (
@ -88,12 +88,12 @@ CONFIG_SCHEMA = vol.Schema(
} }
) )
CONFIG_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
"user": HelperFlowStep(CONFIG_SCHEMA) "user": HelperFlowFormStep(CONFIG_SCHEMA)
} }
OPTIONS_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
"init": HelperFlowStep(OPTIONS_SCHEMA) "init": HelperFlowFormStep(OPTIONS_SCHEMA)
} }

View file

@ -10,15 +10,15 @@ 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.helper_config_entry_flow import (
HelperConfigFlowHandler, HelperConfigFlowHandler,
HelperFlowFormStep,
HelperFlowMenuStep, HelperFlowMenuStep,
HelperFlowStep,
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, HelperFlowStep | HelperFlowMenuStep] = { CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
"user": HelperFlowStep( "user": HelperFlowFormStep(
vol.Schema( vol.Schema(
{ {
vol.Required(CONF_ENTITY_ID): selector.selector( vol.Required(CONF_ENTITY_ID): selector.selector(

View file

@ -11,8 +11,8 @@ from homeassistant.helpers import selector
from homeassistant.helpers.helper_config_entry_flow import ( from homeassistant.helpers.helper_config_entry_flow import (
HelperConfigFlowHandler, HelperConfigFlowHandler,
HelperFlowError, HelperFlowError,
HelperFlowFormStep,
HelperFlowMenuStep, HelperFlowMenuStep,
HelperFlowStep,
) )
from .const import CONF_HYSTERESIS, CONF_LOWER, CONF_UPPER, DEFAULT_HYSTERESIS, DOMAIN from .const import CONF_HYSTERESIS, CONF_LOWER, CONF_UPPER, DEFAULT_HYSTERESIS, DOMAIN
@ -44,12 +44,12 @@ CONFIG_SCHEMA = vol.Schema(
} }
).extend(OPTIONS_SCHEMA.schema) ).extend(OPTIONS_SCHEMA.schema)
CONFIG_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
"user": HelperFlowStep(CONFIG_SCHEMA, validate_user_input=_validate_mode) "user": HelperFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_mode)
} }
OPTIONS_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
"init": HelperFlowStep(OPTIONS_SCHEMA, validate_user_input=_validate_mode) "init": HelperFlowFormStep(OPTIONS_SCHEMA, validate_user_input=_validate_mode)
} }

View file

@ -22,7 +22,7 @@ class HelperFlowError(Exception):
@dataclass @dataclass
class HelperFlowStep: class HelperFlowFormStep:
"""Define a helper config or options flow step.""" """Define a helper 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
@ -57,7 +57,7 @@ class HelperCommonFlowHandler:
def __init__( def __init__(
self, self,
handler: HelperConfigFlowHandler | HelperOptionsFlowHandler, handler: HelperConfigFlowHandler | HelperOptionsFlowHandler,
flow: dict[str, HelperFlowStep | HelperFlowMenuStep], flow: dict[str, HelperFlowFormStep | HelperFlowMenuStep],
config_entry: config_entries.ConfigEntry | None, config_entry: config_entries.ConfigEntry | None,
) -> None: ) -> None:
"""Initialize a common handler.""" """Initialize a common handler."""
@ -69,7 +69,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 step.""" """Handle a step."""
if isinstance(self._flow[step_id], HelperFlowStep): if isinstance(self._flow[step_id], HelperFlowFormStep):
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)
@ -77,7 +77,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: HelperFlowStep = cast(HelperFlowStep, self._flow[step_id]) form_step: HelperFlowFormStep = cast(HelperFlowFormStep, self._flow[step_id])
if user_input is not None and form_step.schema is not None: if user_input is not None and form_step.schema is not None:
# Do extra validation of user input # Do extra validation of user input
@ -109,7 +109,9 @@ class HelperCommonFlowHandler:
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: HelperFlowStep = cast(HelperFlowStep, self._flow[next_step_id]) form_step: HelperFlowFormStep = cast(
HelperFlowFormStep, self._flow[next_step_id]
)
options = dict(self._options) options = dict(self._options)
if user_input: if user_input:
@ -147,8 +149,8 @@ class HelperCommonFlowHandler:
class HelperConfigFlowHandler(config_entries.ConfigFlow): class HelperConfigFlowHandler(config_entries.ConfigFlow):
"""Handle a config flow for helper integrations.""" """Handle a config flow for helper integrations."""
config_flow: dict[str, HelperFlowStep | HelperFlowMenuStep] config_flow: dict[str, HelperFlowFormStep | HelperFlowMenuStep]
options_flow: dict[str, HelperFlowStep | HelperFlowMenuStep] | None = None options_flow: dict[str, HelperFlowFormStep | HelperFlowMenuStep] | None = None
VERSION = 1 VERSION = 1

View file

@ -10,8 +10,8 @@ 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.helper_config_entry_flow import (
HelperConfigFlowHandler, HelperConfigFlowHandler,
HelperFlowFormStep,
HelperFlowMenuStep, HelperFlowMenuStep,
HelperFlowStep,
) )
from .const import DOMAIN from .const import DOMAIN
@ -30,12 +30,12 @@ CONFIG_SCHEMA = vol.Schema(
} }
).extend(OPTIONS_SCHEMA.schema) ).extend(OPTIONS_SCHEMA.schema)
CONFIG_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
"user": HelperFlowStep(CONFIG_SCHEMA) "user": HelperFlowFormStep(CONFIG_SCHEMA)
} }
OPTIONS_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = {
"init": HelperFlowStep(OPTIONS_SCHEMA) "init": HelperFlowFormStep(OPTIONS_SCHEMA)
} }