From f9f360c64ef1448827560472aa675fccbde04f4f Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 30 Mar 2022 23:36:47 +0200 Subject: [PATCH] Rename helper_config_entry_flow to schema_config_entry_flow (#68924) --- .../components/derivative/config_flow.py | 18 ++--- homeassistant/components/group/config_flow.py | 56 +++++++-------- .../components/integration/config_flow.py | 18 ++--- .../components/min_max/config_flow.py | 18 ++--- .../components/switch_as_x/config_flow.py | 14 ++-- .../components/threshold/config_flow.py | 22 +++--- homeassistant/components/tod/config_flow.py | 18 ++--- .../components/utility_meter/config_flow.py | 22 +++--- ...ry_flow.py => schema_config_entry_flow.py} | 68 +++++++++---------- .../integration/config_flow.py | 18 ++--- .../helpers/test_helper_config_entry_flow.py | 22 +++--- 11 files changed, 147 insertions(+), 147 deletions(-) rename homeassistant/helpers/{helper_config_entry_flow.py => schema_config_entry_flow.py} (86%) diff --git a/homeassistant/components/derivative/config_flow.py b/homeassistant/components/derivative/config_flow.py index 348158ce4e0..fe6b99c3eca 100644 --- a/homeassistant/components/derivative/config_flow.py +++ b/homeassistant/components/derivative/config_flow.py @@ -16,10 +16,10 @@ from homeassistant.const import ( TIME_SECONDS, ) from homeassistant.helpers import selector -from homeassistant.helpers.helper_config_entry_flow import ( - HelperConfigFlowHandler, - HelperFlowFormStep, - HelperFlowMenuStep, +from homeassistant.helpers.schema_config_entry_flow import ( + SchemaConfigFlowHandler, + SchemaFlowFormStep, + SchemaFlowMenuStep, ) from .const import ( @@ -78,16 +78,16 @@ CONFIG_SCHEMA = vol.Schema( } ).extend(OPTIONS_SCHEMA.schema) -CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "user": HelperFlowFormStep(CONFIG_SCHEMA) +CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "user": SchemaFlowFormStep(CONFIG_SCHEMA) } -OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "init": HelperFlowFormStep(OPTIONS_SCHEMA) +OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "init": SchemaFlowFormStep(OPTIONS_SCHEMA) } -class ConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN): +class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN): """Handle a config or options flow for Derivative.""" config_flow = CONFIG_FLOW diff --git a/homeassistant/components/group/config_flow.py b/homeassistant/components/group/config_flow.py index 0ba5885a3fd..8ddee492834 100644 --- a/homeassistant/components/group/config_flow.py +++ b/homeassistant/components/group/config_flow.py @@ -10,11 +10,11 @@ import voluptuous as vol from homeassistant.const import CONF_ENTITIES 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, - HelperOptionsFlowHandler, +from homeassistant.helpers.schema_config_entry_flow import ( + SchemaConfigFlowHandler, + SchemaFlowFormStep, + SchemaFlowMenuStep, + SchemaOptionsFlowHandler, entity_selector_without_own_entities, ) @@ -25,11 +25,11 @@ from .const import CONF_HIDE_MEMBERS def basic_group_options_schema( domain: str, - handler: HelperConfigFlowHandler | HelperOptionsFlowHandler, + handler: SchemaConfigFlowHandler | SchemaOptionsFlowHandler, options: dict[str, Any], ) -> vol.Schema: """Generate options schema.""" - handler = cast(HelperOptionsFlowHandler, handler) + handler = cast(SchemaOptionsFlowHandler, handler) return vol.Schema( { 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( - handler: HelperConfigFlowHandler | HelperOptionsFlowHandler, + handler: SchemaConfigFlowHandler | SchemaOptionsFlowHandler, options: dict[str, Any], ) -> vol.Schema: """Generate options schema.""" @@ -78,7 +78,7 @@ BINARY_SENSOR_CONFIG_SCHEMA = basic_group_config_schema("binary_sensor").extend( def light_switch_options_schema( domain: str, - handler: HelperConfigFlowHandler | HelperOptionsFlowHandler, + handler: SchemaConfigFlowHandler | SchemaOptionsFlowHandler, options: dict[str, Any], ) -> vol.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 -CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "user": HelperFlowMenuStep(GROUP_TYPES), - "binary_sensor": HelperFlowFormStep( +CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "user": SchemaFlowMenuStep(GROUP_TYPES), + "binary_sensor": SchemaFlowFormStep( BINARY_SENSOR_CONFIG_SCHEMA, set_group_type("binary_sensor") ), - "cover": HelperFlowFormStep( + "cover": SchemaFlowFormStep( basic_group_config_schema("cover"), set_group_type("cover") ), - "fan": HelperFlowFormStep(basic_group_config_schema("fan"), set_group_type("fan")), - "light": HelperFlowFormStep( + "fan": SchemaFlowFormStep(basic_group_config_schema("fan"), set_group_type("fan")), + "light": SchemaFlowFormStep( basic_group_config_schema("light"), set_group_type("light") ), - "lock": HelperFlowFormStep( + "lock": SchemaFlowFormStep( 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") ), - "switch": HelperFlowFormStep( + "switch": SchemaFlowFormStep( basic_group_config_schema("switch"), set_group_type("switch") ), } -OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "init": HelperFlowFormStep(None, next_step=choose_options_step), - "binary_sensor": HelperFlowFormStep(binary_sensor_options_schema), - "cover": HelperFlowFormStep(partial(basic_group_options_schema, "cover")), - "fan": HelperFlowFormStep(partial(basic_group_options_schema, "fan")), - "light": HelperFlowFormStep(partial(light_switch_options_schema, "light")), - "lock": HelperFlowFormStep(partial(basic_group_options_schema, "lock")), - "media_player": HelperFlowFormStep( +OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "init": SchemaFlowFormStep(None, next_step=choose_options_step), + "binary_sensor": SchemaFlowFormStep(binary_sensor_options_schema), + "cover": SchemaFlowFormStep(partial(basic_group_options_schema, "cover")), + "fan": SchemaFlowFormStep(partial(basic_group_options_schema, "fan")), + "light": SchemaFlowFormStep(partial(light_switch_options_schema, "light")), + "lock": SchemaFlowFormStep(partial(basic_group_options_schema, "lock")), + "media_player": SchemaFlowFormStep( 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.""" config_flow = CONFIG_FLOW diff --git a/homeassistant/components/integration/config_flow.py b/homeassistant/components/integration/config_flow.py index c9e51fd4f9a..c220327e983 100644 --- a/homeassistant/components/integration/config_flow.py +++ b/homeassistant/components/integration/config_flow.py @@ -16,10 +16,10 @@ from homeassistant.const import ( TIME_SECONDS, ) from homeassistant.helpers import selector -from homeassistant.helpers.helper_config_entry_flow import ( - HelperConfigFlowHandler, - HelperFlowFormStep, - HelperFlowMenuStep, +from homeassistant.helpers.schema_config_entry_flow import ( + SchemaConfigFlowHandler, + SchemaFlowFormStep, + SchemaFlowMenuStep, ) from .const import ( @@ -88,16 +88,16 @@ CONFIG_SCHEMA = vol.Schema( } ) -CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "user": HelperFlowFormStep(CONFIG_SCHEMA) +CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "user": SchemaFlowFormStep(CONFIG_SCHEMA) } -OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "init": HelperFlowFormStep(OPTIONS_SCHEMA) +OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "init": SchemaFlowFormStep(OPTIONS_SCHEMA) } -class ConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN): +class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN): """Handle a config or options flow for Integration.""" config_flow = CONFIG_FLOW diff --git a/homeassistant/components/min_max/config_flow.py b/homeassistant/components/min_max/config_flow.py index 353a90cbf6c..64d982dec92 100644 --- a/homeassistant/components/min_max/config_flow.py +++ b/homeassistant/components/min_max/config_flow.py @@ -8,10 +8,10 @@ import voluptuous as vol from homeassistant.const import CONF_TYPE from homeassistant.helpers import selector -from homeassistant.helpers.helper_config_entry_flow import ( - HelperConfigFlowHandler, - HelperFlowFormStep, - HelperFlowMenuStep, +from homeassistant.helpers.schema_config_entry_flow import ( + SchemaConfigFlowHandler, + SchemaFlowFormStep, + SchemaFlowMenuStep, ) from .const import CONF_ENTITY_IDS, CONF_ROUND_DIGITS, DOMAIN @@ -38,16 +38,16 @@ CONFIG_SCHEMA = vol.Schema( } ).extend(OPTIONS_SCHEMA.schema) -CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "user": HelperFlowFormStep(CONFIG_SCHEMA) +CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "user": SchemaFlowFormStep(CONFIG_SCHEMA) } -OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "init": HelperFlowFormStep(OPTIONS_SCHEMA) +OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "init": SchemaFlowFormStep(OPTIONS_SCHEMA) } -class ConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN): +class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN): """Handle a config or options flow for Min/Max.""" config_flow = CONFIG_FLOW diff --git a/homeassistant/components/switch_as_x/config_flow.py b/homeassistant/components/switch_as_x/config_flow.py index 4cf7a001679..a70e0a371e8 100644 --- a/homeassistant/components/switch_as_x/config_flow.py +++ b/homeassistant/components/switch_as_x/config_flow.py @@ -8,17 +8,17 @@ import voluptuous as vol 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, +from homeassistant.helpers.schema_config_entry_flow import ( + SchemaConfigFlowHandler, + SchemaFlowFormStep, + SchemaFlowMenuStep, wrapped_entity_config_entry_title, ) from .const import CONF_TARGET_DOMAIN, DOMAIN -CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "user": HelperFlowFormStep( +CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "user": SchemaFlowFormStep( vol.Schema( { 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.""" config_flow = CONFIG_FLOW diff --git a/homeassistant/components/threshold/config_flow.py b/homeassistant/components/threshold/config_flow.py index 35a32604334..c77d4b57115 100644 --- a/homeassistant/components/threshold/config_flow.py +++ b/homeassistant/components/threshold/config_flow.py @@ -8,11 +8,11 @@ import voluptuous as vol from homeassistant.const import CONF_ENTITY_ID, CONF_NAME from homeassistant.helpers import selector -from homeassistant.helpers.helper_config_entry_flow import ( - HelperConfigFlowHandler, - HelperFlowError, - HelperFlowFormStep, - HelperFlowMenuStep, +from homeassistant.helpers.schema_config_entry_flow import ( + SchemaConfigFlowHandler, + SchemaFlowError, + SchemaFlowFormStep, + SchemaFlowMenuStep, ) 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: """Validate the threshold mode, and set limits to None if not set.""" 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} @@ -44,16 +44,16 @@ CONFIG_SCHEMA = vol.Schema( } ).extend(OPTIONS_SCHEMA.schema) -CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "user": HelperFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_mode) +CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "user": SchemaFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_mode) } -OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "init": HelperFlowFormStep(OPTIONS_SCHEMA, validate_user_input=_validate_mode) +OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "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.""" config_flow = CONFIG_FLOW diff --git a/homeassistant/components/tod/config_flow.py b/homeassistant/components/tod/config_flow.py index e4927096b69..bd1712d1db5 100644 --- a/homeassistant/components/tod/config_flow.py +++ b/homeassistant/components/tod/config_flow.py @@ -8,10 +8,10 @@ import voluptuous as vol from homeassistant.const import CONF_NAME from homeassistant.helpers import selector -from homeassistant.helpers.helper_config_entry_flow import ( - HelperConfigFlowHandler, - HelperFlowFormStep, - HelperFlowMenuStep, +from homeassistant.helpers.schema_config_entry_flow import ( + SchemaConfigFlowHandler, + SchemaFlowFormStep, + SchemaFlowMenuStep, ) from .const import CONF_AFTER_TIME, CONF_BEFORE_TIME, DOMAIN @@ -29,16 +29,16 @@ CONFIG_SCHEMA = vol.Schema( } ).extend(OPTIONS_SCHEMA.schema) -CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "user": HelperFlowFormStep(CONFIG_SCHEMA) +CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "user": SchemaFlowFormStep(CONFIG_SCHEMA) } -OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "init": HelperFlowFormStep(OPTIONS_SCHEMA) +OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "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.""" config_flow = CONFIG_FLOW diff --git a/homeassistant/components/utility_meter/config_flow.py b/homeassistant/components/utility_meter/config_flow.py index caf7d3c8d00..555ae7eb46d 100644 --- a/homeassistant/components/utility_meter/config_flow.py +++ b/homeassistant/components/utility_meter/config_flow.py @@ -8,11 +8,11 @@ import voluptuous as vol from homeassistant.const import CONF_NAME, CONF_UNIT_OF_MEASUREMENT from homeassistant.helpers import selector -from homeassistant.helpers.helper_config_entry_flow import ( - HelperConfigFlowHandler, - HelperFlowError, - HelperFlowFormStep, - HelperFlowMenuStep, +from homeassistant.helpers.schema_config_entry_flow import ( + SchemaConfigFlowHandler, + SchemaFlowError, + SchemaFlowFormStep, + SchemaFlowMenuStep, ) from .const import ( @@ -56,7 +56,7 @@ def _validate_config(data: Any) -> Any: try: vol.Unique()(tariffs) except vol.Invalid as exc: - raise HelperFlowError("tariffs_not_unique") from exc + raise SchemaFlowError("tariffs_not_unique") from exc return data @@ -98,16 +98,16 @@ CONFIG_SCHEMA = vol.Schema( } ) -CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "user": HelperFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_config) +CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "user": SchemaFlowFormStep(CONFIG_SCHEMA, validate_user_input=_validate_config) } -OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "init": HelperFlowFormStep(OPTIONS_SCHEMA) +OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "init": SchemaFlowFormStep(OPTIONS_SCHEMA) } -class ConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN): +class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN): """Handle a config or options flow for Utility Meter.""" config_flow = CONFIG_FLOW diff --git a/homeassistant/helpers/helper_config_entry_flow.py b/homeassistant/helpers/schema_config_entry_flow.py similarity index 86% rename from homeassistant/helpers/helper_config_entry_flow.py rename to homeassistant/helpers/schema_config_entry_flow.py index 62c9da48547..341ae605025 100644 --- a/homeassistant/helpers/helper_config_entry_flow.py +++ b/homeassistant/helpers/schema_config_entry_flow.py @@ -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 abc import abstractmethod @@ -17,25 +17,25 @@ from homeassistant.data_entry_flow import FlowResult, UnknownHandler from . import entity_registry as er, selector -class HelperFlowError(Exception): +class SchemaFlowError(Exception): """Validation failed.""" @dataclass -class HelperFlowFormStep: - """Define a helper config or options flow step.""" +class SchemaFlowFormStep: + """Define a config or options flow step.""" # 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. schema: vol.Schema | Callable[ - [HelperConfigFlowHandler | HelperOptionsFlowHandler, dict[str, Any]], + [SchemaConfigFlowHandler | SchemaOptionsFlowHandler, dict[str, Any]], vol.Schema | None, ] | None # Optional function to validate user input. # 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 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 # Optional function to identify next step. @@ -48,11 +48,11 @@ class HelperFlowFormStep: # Optional function to allow amending a form schema. # 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 - # 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. update_form_schema: Callable[ [ - HelperConfigFlowHandler | HelperOptionsFlowHandler, + SchemaConfigFlowHandler | SchemaOptionsFlowHandler, vol.Schema, dict[str, Any], ], @@ -61,20 +61,20 @@ class HelperFlowFormStep: @dataclass -class HelperFlowMenuStep: - """Define a helper config or options flow menu step.""" +class SchemaFlowMenuStep: + """Define a config or options flow menu step.""" # Menu options options: list[str] | dict[str, str] -class HelperCommonFlowHandler: - """Handle a config or options flow for helper.""" +class SchemaCommonFlowHandler: + """Handle a schema based config or options flow.""" def __init__( self, - handler: HelperConfigFlowHandler | HelperOptionsFlowHandler, - flow: dict[str, HelperFlowFormStep | HelperFlowMenuStep], + handler: SchemaConfigFlowHandler | SchemaOptionsFlowHandler, + flow: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep], config_entry: config_entries.ConfigEntry | None, ) -> None: """Initialize a common handler.""" @@ -86,12 +86,12 @@ class HelperCommonFlowHandler: self, step_id: str, user_input: dict[str, Any] | None = None ) -> FlowResult: """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_menu_step(step_id, user_input) def _get_schema( - self, form_step: HelperFlowFormStep, options: dict[str, Any] + self, form_step: SchemaFlowFormStep, options: dict[str, Any] ) -> vol.Schema | None: if form_step.schema is None: return None @@ -103,7 +103,7 @@ class HelperCommonFlowHandler: self, step_id: str, user_input: dict[str, Any] | None = None ) -> FlowResult: """Handle a form step.""" - form_step: HelperFlowFormStep = cast(HelperFlowFormStep, self._flow[step_id]) + form_step: SchemaFlowFormStep = cast(SchemaFlowFormStep, self._flow[step_id]) if ( user_input is not None @@ -126,7 +126,7 @@ class HelperCommonFlowHandler: # Do extra validation of user input try: 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) if user_input is not None: @@ -148,12 +148,12 @@ class HelperCommonFlowHandler: def _show_next_step( self, next_step_id: str, - error: HelperFlowError | None = None, + error: SchemaFlowError | None = None, user_input: dict[str, Any] | None = None, ) -> FlowResult: """Show form for next step.""" - form_step: HelperFlowFormStep = cast( - HelperFlowFormStep, self._flow[next_step_id] + form_step: SchemaFlowFormStep = cast( + SchemaFlowFormStep, self._flow[next_step_id] ) options = dict(self._options) @@ -195,18 +195,18 @@ class HelperCommonFlowHandler: self, step_id: str, user_input: dict[str, Any] | None = None ) -> FlowResult: """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( step_id=step_id, menu_options=form_step.options, ) -class HelperConfigFlowHandler(config_entries.ConfigFlow): - """Handle a config flow for helper integrations.""" +class SchemaConfigFlowHandler(config_entries.ConfigFlow): + """Handle a schema based config flow.""" - config_flow: dict[str, HelperFlowFormStep | HelperFlowMenuStep] - options_flow: dict[str, HelperFlowFormStep | HelperFlowMenuStep] | None = None + config_flow: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] + options_flow: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] | None = None VERSION = 1 @@ -222,7 +222,7 @@ class HelperConfigFlowHandler(config_entries.ConfigFlow): if cls.options_flow is None: raise UnknownHandler - return HelperOptionsFlowHandler( + return SchemaOptionsFlowHandler( config_entry, cls.options_flow, cls.async_options_flow_finished ) @@ -235,7 +235,7 @@ class HelperConfigFlowHandler(config_entries.ConfigFlow): def __init__(self) -> None: """Initialize config flow.""" - self._common_handler = HelperCommonFlowHandler(self, self.config_flow, None) + self._common_handler = SchemaCommonFlowHandler(self, self.config_flow, None) @classmethod @callback @@ -250,7 +250,7 @@ class HelperConfigFlowHandler(config_entries.ConfigFlow): """Generate a step handler.""" async def _async_step( - self: HelperConfigFlowHandler, user_input: dict[str, Any] | None = None + self: SchemaConfigFlowHandler, user_input: dict[str, Any] | None = None ) -> FlowResult: """Handle a config flow step.""" # pylint: disable-next=protected-access @@ -300,8 +300,8 @@ class HelperConfigFlowHandler(config_entries.ConfigFlow): ) -class HelperOptionsFlowHandler(config_entries.OptionsFlow): - """Handle an options flow for helper integrations.""" +class SchemaOptionsFlowHandler(config_entries.OptionsFlow): + """Handle a schema based options flow.""" def __init__( self, @@ -310,7 +310,7 @@ class HelperOptionsFlowHandler(config_entries.OptionsFlow): async_options_flow_finished: Callable[[HomeAssistant, Mapping[str, Any]], None], ) -> None: """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._async_options_flow_finished = async_options_flow_finished @@ -326,7 +326,7 @@ class HelperOptionsFlowHandler(config_entries.OptionsFlow): """Generate a step handler.""" async def _async_step( - self: HelperConfigFlowHandler, user_input: dict[str, Any] | None = None + self: SchemaConfigFlowHandler, user_input: dict[str, Any] | None = None ) -> FlowResult: """Handle an options flow step.""" # pylint: disable-next=protected-access @@ -370,7 +370,7 @@ def wrapped_entity_config_entry_title( @callback def entity_selector_without_own_entities( - handler: HelperOptionsFlowHandler, + handler: SchemaOptionsFlowHandler, entity_selector_config: dict[str, Any], ) -> vol.Schema: """Return an entity selector which excludes own entities.""" 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 cc81d0a22b1..b8a048e9dba 100644 --- a/script/scaffold/templates/config_flow_helper/integration/config_flow.py +++ b/script/scaffold/templates/config_flow_helper/integration/config_flow.py @@ -8,10 +8,10 @@ import voluptuous as vol from homeassistant.const import CONF_ENTITY_ID from homeassistant.helpers import selector -from homeassistant.helpers.helper_config_entry_flow import ( - HelperConfigFlowHandler, - HelperFlowFormStep, - HelperFlowMenuStep, +from homeassistant.helpers.schema_config_entry_flow import ( + SchemaConfigFlowHandler, + SchemaFlowFormStep, + SchemaFlowMenuStep, ) from .const import DOMAIN @@ -30,16 +30,16 @@ CONFIG_SCHEMA = vol.Schema( } ).extend(OPTIONS_SCHEMA.schema) -CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "user": HelperFlowFormStep(CONFIG_SCHEMA) +CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "user": SchemaFlowFormStep(CONFIG_SCHEMA) } -OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "init": HelperFlowFormStep(OPTIONS_SCHEMA) +OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "init": SchemaFlowFormStep(OPTIONS_SCHEMA) } -class ConfigFlowHandler(HelperConfigFlowHandler, domain=DOMAIN): +class ConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN): """Handle a config or options flow for NEW_NAME.""" config_flow = CONFIG_FLOW diff --git a/tests/helpers/test_helper_config_entry_flow.py b/tests/helpers/test_helper_config_entry_flow.py index dece7ace37c..46e8998c738 100644 --- a/tests/helpers/test_helper_config_entry_flow.py +++ b/tests/helpers/test_helper_config_entry_flow.py @@ -1,14 +1,14 @@ -"""Test helper_config_entry_flow.""" +"""Test schema_config_entry_flow.""" import pytest import voluptuous as vol from homeassistant import data_entry_flow from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er -from homeassistant.helpers.helper_config_entry_flow import ( - HelperConfigFlowHandler, - HelperFlowFormStep, - HelperFlowMenuStep, +from homeassistant.helpers.schema_config_entry_flow import ( + SchemaConfigFlowHandler, + SchemaFlowFormStep, + SchemaFlowMenuStep, wrapped_entity_config_entry_title, ) from homeassistant.util.decorator import Registry @@ -100,12 +100,12 @@ async def test_config_flow_advanced_option( } ) - CONFIG_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "init": HelperFlowFormStep(CONFIG_SCHEMA) + CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "init": SchemaFlowFormStep(CONFIG_SCHEMA) } @manager.mock_reg_handler("test") - class TestFlow(HelperConfigFlowHandler): + class TestFlow(SchemaConfigFlowHandler): config_flow = CONFIG_FLOW # Start flow in basic mode @@ -195,11 +195,11 @@ async def test_options_flow_advanced_option( } ) - OPTIONS_FLOW: dict[str, HelperFlowFormStep | HelperFlowMenuStep] = { - "init": HelperFlowFormStep(OPTIONS_SCHEMA) + OPTIONS_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = { + "init": SchemaFlowFormStep(OPTIONS_SCHEMA) } - class TestFlow(HelperConfigFlowHandler, domain="test"): + class TestFlow(SchemaConfigFlowHandler, domain="test"): config_flow = {} options_flow = OPTIONS_FLOW