From c44d7205cf31d7699ee2b97aa391e07aa58d44b8 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 23 Mar 2022 22:43:11 +0100 Subject: [PATCH] Rename HelperFlowStep to HelperFlowFormStep (#68583) --- .../components/derivative/config_flow.py | 10 +++---- homeassistant/components/group/config_flow.py | 28 +++++++++---------- .../components/integration/config_flow.py | 10 +++---- .../components/switch_as_x/config_flow.py | 6 ++-- .../components/threshold/config_flow.py | 10 +++---- .../helpers/helper_config_entry_flow.py | 16 ++++++----- .../integration/config_flow.py | 10 +++---- 7 files changed, 46 insertions(+), 44 deletions(-) diff --git a/homeassistant/components/derivative/config_flow.py b/homeassistant/components/derivative/config_flow.py index 6d38a3cd4a2..1447f943a13 100644 --- a/homeassistant/components/derivative/config_flow.py +++ b/homeassistant/components/derivative/config_flow.py @@ -18,8 +18,8 @@ from homeassistant.const import ( from homeassistant.helpers import selector from homeassistant.helpers.helper_config_entry_flow import ( HelperConfigFlowHandler, + HelperFlowFormStep, HelperFlowMenuStep, - HelperFlowStep, ) from .const import ( @@ -78,12 +78,12 @@ CONFIG_SCHEMA = vol.Schema( } ).extend(OPTIONS_SCHEMA.schema) -CONFIG_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { - "user": HelperFlowStep(CONFIG_SCHEMA) +CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { + "user": HelperFlowFormStep(CONFIG_SCHEMA) } -OPTIONS_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { - "init": HelperFlowStep(OPTIONS_SCHEMA) +OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { + "init": HelperFlowFormStep(OPTIONS_SCHEMA) } diff --git a/homeassistant/components/group/config_flow.py b/homeassistant/components/group/config_flow.py index ca356ee70f3..8b4bf20b0e5 100644 --- a/homeassistant/components/group/config_flow.py +++ b/homeassistant/components/group/config_flow.py @@ -11,8 +11,8 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import entity_registry as er, selector from homeassistant.helpers.helper_config_entry_flow import ( HelperConfigFlowHandler, + HelperFlowFormStep, HelperFlowMenuStep, - HelperFlowStep, ) 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 -CONFIG_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { +CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { "user": HelperFlowMenuStep(GROUP_TYPES), - "binary_sensor": HelperFlowStep( + "binary_sensor": HelperFlowFormStep( BINARY_SENSOR_CONFIG_SCHEMA, set_group_type("binary_sensor") ), - "cover": HelperFlowStep( + "cover": HelperFlowFormStep( basic_group_config_schema("cover"), set_group_type("cover") ), - "fan": HelperFlowStep(basic_group_config_schema("fan"), set_group_type("fan")), - "light": HelperFlowStep(LIGHT_CONFIG_SCHEMA, set_group_type("light")), - "media_player": HelperFlowStep( + "fan": HelperFlowFormStep(basic_group_config_schema("fan"), set_group_type("fan")), + "light": HelperFlowFormStep(LIGHT_CONFIG_SCHEMA, set_group_type("light")), + "media_player": HelperFlowFormStep( basic_group_config_schema("media_player"), set_group_type("media_player") ), } -OPTIONS_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { - "init": HelperFlowStep(None, next_step=choose_options_step), - "binary_sensor": HelperFlowStep(BINARY_SENSOR_OPTIONS_SCHEMA), - "cover": HelperFlowStep(basic_group_options_schema("cover")), - "fan": HelperFlowStep(basic_group_options_schema("fan")), - "light": HelperFlowStep(LIGHT_OPTIONS_SCHEMA), - "media_player": HelperFlowStep(basic_group_options_schema("media_player")), +OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { + "init": HelperFlowFormStep(None, next_step=choose_options_step), + "binary_sensor": HelperFlowFormStep(BINARY_SENSOR_OPTIONS_SCHEMA), + "cover": HelperFlowFormStep(basic_group_options_schema("cover")), + "fan": HelperFlowFormStep(basic_group_options_schema("fan")), + "light": HelperFlowFormStep(LIGHT_OPTIONS_SCHEMA), + "media_player": HelperFlowFormStep(basic_group_options_schema("media_player")), } diff --git a/homeassistant/components/integration/config_flow.py b/homeassistant/components/integration/config_flow.py index bf9ad853205..c9e51fd4f9a 100644 --- a/homeassistant/components/integration/config_flow.py +++ b/homeassistant/components/integration/config_flow.py @@ -18,8 +18,8 @@ from homeassistant.const import ( from homeassistant.helpers import selector from homeassistant.helpers.helper_config_entry_flow import ( HelperConfigFlowHandler, + HelperFlowFormStep, HelperFlowMenuStep, - HelperFlowStep, ) from .const import ( @@ -88,12 +88,12 @@ CONFIG_SCHEMA = vol.Schema( } ) -CONFIG_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { - "user": HelperFlowStep(CONFIG_SCHEMA) +CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { + "user": HelperFlowFormStep(CONFIG_SCHEMA) } -OPTIONS_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { - "init": HelperFlowStep(OPTIONS_SCHEMA) +OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { + "init": HelperFlowFormStep(OPTIONS_SCHEMA) } diff --git a/homeassistant/components/switch_as_x/config_flow.py b/homeassistant/components/switch_as_x/config_flow.py index 6425d212f10..4cf7a001679 100644 --- a/homeassistant/components/switch_as_x/config_flow.py +++ b/homeassistant/components/switch_as_x/config_flow.py @@ -10,15 +10,15 @@ from homeassistant.const import CONF_ENTITY_ID, Platform from homeassistant.helpers import entity_registry as er, selector from homeassistant.helpers.helper_config_entry_flow import ( HelperConfigFlowHandler, + HelperFlowFormStep, HelperFlowMenuStep, - HelperFlowStep, wrapped_entity_config_entry_title, ) from .const import CONF_TARGET_DOMAIN, DOMAIN -CONFIG_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { - "user": HelperFlowStep( +CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { + "user": HelperFlowFormStep( vol.Schema( { vol.Required(CONF_ENTITY_ID): selector.selector( diff --git a/homeassistant/components/threshold/config_flow.py b/homeassistant/components/threshold/config_flow.py index 36d4c5e6239..35a32604334 100644 --- a/homeassistant/components/threshold/config_flow.py +++ b/homeassistant/components/threshold/config_flow.py @@ -11,8 +11,8 @@ from homeassistant.helpers import selector from homeassistant.helpers.helper_config_entry_flow import ( HelperConfigFlowHandler, HelperFlowError, + HelperFlowFormStep, HelperFlowMenuStep, - HelperFlowStep, ) from .const import CONF_HYSTERESIS, CONF_LOWER, CONF_UPPER, DEFAULT_HYSTERESIS, DOMAIN @@ -44,12 +44,12 @@ CONFIG_SCHEMA = vol.Schema( } ).extend(OPTIONS_SCHEMA.schema) -CONFIG_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { - "user": HelperFlowStep(CONFIG_SCHEMA, validate_user_input=_validate_mode) +CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { + "user": HelperFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_mode) } -OPTIONS_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { - "init": HelperFlowStep(OPTIONS_SCHEMA, validate_user_input=_validate_mode) +OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { + "init": HelperFlowFormStep(OPTIONS_SCHEMA, validate_user_input=_validate_mode) } diff --git a/homeassistant/helpers/helper_config_entry_flow.py b/homeassistant/helpers/helper_config_entry_flow.py index f64b2463bdd..87716dcbccf 100644 --- a/homeassistant/helpers/helper_config_entry_flow.py +++ b/homeassistant/helpers/helper_config_entry_flow.py @@ -22,7 +22,7 @@ class HelperFlowError(Exception): @dataclass -class HelperFlowStep: +class HelperFlowFormStep: """Define a helper config or options flow step.""" # Optional schema for requesting and validating user input. If schema validation @@ -57,7 +57,7 @@ class HelperCommonFlowHandler: def __init__( self, handler: HelperConfigFlowHandler | HelperOptionsFlowHandler, - flow: dict[str, HelperFlowStep | HelperFlowMenuStep], + flow: dict[str, HelperFlowFormStep | HelperFlowMenuStep], config_entry: config_entries.ConfigEntry | None, ) -> None: """Initialize a common handler.""" @@ -69,7 +69,7 @@ class HelperCommonFlowHandler: self, step_id: str, user_input: dict[str, Any] | None = None ) -> FlowResult: """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_menu_step(step_id, user_input) @@ -77,7 +77,7 @@ class HelperCommonFlowHandler: self, step_id: str, user_input: dict[str, Any] | None = None ) -> FlowResult: """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: # Do extra validation of user input @@ -109,7 +109,9 @@ class HelperCommonFlowHandler: user_input: dict[str, Any] | None = None, ) -> FlowResult: """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) if user_input: @@ -147,8 +149,8 @@ class HelperCommonFlowHandler: class HelperConfigFlowHandler(config_entries.ConfigFlow): """Handle a config flow for helper integrations.""" - config_flow: dict[str, HelperFlowStep | HelperFlowMenuStep] - options_flow: dict[str, HelperFlowStep | HelperFlowMenuStep] | None = None + config_flow: dict[str, HelperFlowFormStep | HelperFlowMenuStep] + options_flow: dict[str, HelperFlowFormStep | HelperFlowMenuStep] | None = None VERSION = 1 diff --git a/script/scaffold/templates/config_flow_helper/integration/config_flow.py b/script/scaffold/templates/config_flow_helper/integration/config_flow.py index 8f4db82c77c..cc81d0a22b1 100644 --- a/script/scaffold/templates/config_flow_helper/integration/config_flow.py +++ b/script/scaffold/templates/config_flow_helper/integration/config_flow.py @@ -10,8 +10,8 @@ from homeassistant.const import CONF_ENTITY_ID from homeassistant.helpers import selector from homeassistant.helpers.helper_config_entry_flow import ( HelperConfigFlowHandler, + HelperFlowFormStep, HelperFlowMenuStep, - HelperFlowStep, ) from .const import DOMAIN @@ -30,12 +30,12 @@ CONFIG_SCHEMA = vol.Schema( } ).extend(OPTIONS_SCHEMA.schema) -CONFIG_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { - "user": HelperFlowStep(CONFIG_SCHEMA) +CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { + "user": HelperFlowFormStep(CONFIG_SCHEMA) } -OPTIONS_FLOW: dict[str, HelperFlowStep | HelperFlowMenuStep] = { - "init": HelperFlowStep(OPTIONS_SCHEMA) +OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { + "init": HelperFlowFormStep(OPTIONS_SCHEMA) }