diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index b7b1a68e792b..5c9c0ff1ce4d 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -6,6 +6,7 @@ from collections.abc import Callable, Iterable, Mapping import copy from dataclasses import dataclass from enum import StrEnum +from functools import partial import logging from types import MappingProxyType from typing import Any, Required, TypedDict @@ -14,6 +15,11 @@ import voluptuous as vol from .core import HomeAssistant, callback from .exceptions import HomeAssistantError +from .helpers.deprecation import ( + DeprecatedConstantEnum, + check_if_deprecated_constant, + dir_with_deprecated_constants, +) from .helpers.frame import report from .util import uuid as uuid_util @@ -34,14 +40,28 @@ class FlowResultType(StrEnum): # RESULT_TYPE_* is deprecated, to be removed in 2022.9 -RESULT_TYPE_FORM = "form" -RESULT_TYPE_CREATE_ENTRY = "create_entry" -RESULT_TYPE_ABORT = "abort" -RESULT_TYPE_EXTERNAL_STEP = "external" -RESULT_TYPE_EXTERNAL_STEP_DONE = "external_done" -RESULT_TYPE_SHOW_PROGRESS = "progress" -RESULT_TYPE_SHOW_PROGRESS_DONE = "progress_done" -RESULT_TYPE_MENU = "menu" +_DEPRECATED_RESULT_TYPE_FORM = DeprecatedConstantEnum(FlowResultType.FORM, "2025.1") +_DEPRECATED_RESULT_TYPE_CREATE_ENTRY = DeprecatedConstantEnum( + FlowResultType.CREATE_ENTRY, "2025.1" +) +_DEPRECATED_RESULT_TYPE_ABORT = DeprecatedConstantEnum(FlowResultType.ABORT, "2025.1") +_DEPRECATED_RESULT_TYPE_EXTERNAL_STEP = DeprecatedConstantEnum( + FlowResultType.EXTERNAL_STEP, "2025.1" +) +_DEPRECATED_RESULT_TYPE_EXTERNAL_STEP_DONE = DeprecatedConstantEnum( + FlowResultType.EXTERNAL_STEP_DONE, "2025.1" +) +_DEPRECATED_RESULT_TYPE_SHOW_PROGRESS = DeprecatedConstantEnum( + FlowResultType.SHOW_PROGRESS, "2025.1" +) +_DEPRECATED_RESULT_TYPE_SHOW_PROGRESS_DONE = DeprecatedConstantEnum( + FlowResultType.SHOW_PROGRESS_DONE, "2025.1" +) +_DEPRECATED_RESULT_TYPE_MENU = DeprecatedConstantEnum(FlowResultType.MENU, "2025.1") + +# Both can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) # Event that is fired when a flow is progressed via external or progress source. EVENT_DATA_ENTRY_FLOW_PROGRESSED = "data_entry_flow_progressed" diff --git a/tests/components/osoenergy/test_config_flow.py b/tests/components/osoenergy/test_config_flow.py index d7250356ebe5..5c7e0b3442c0 100644 --- a/tests/components/osoenergy/test_config_flow.py +++ b/tests/components/osoenergy/test_config_flow.py @@ -22,7 +22,7 @@ async def test_user_flow(hass: HomeAssistant) -> None: DOMAIN, context={"source": config_entries.SOURCE_USER} ) - assert result["type"] == data_entry_flow.RESULT_TYPE_FORM + assert result["type"] == data_entry_flow.FlowResultType.FORM assert result["errors"] == {} with patch( @@ -37,7 +37,7 @@ async def test_user_flow(hass: HomeAssistant) -> None: ) await hass.async_block_till_done() - assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY + assert result2["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY assert result2["title"] == TEST_USER_EMAIL assert result2["data"] == { CONF_API_KEY: SUBSCRIPTION_KEY, @@ -70,7 +70,7 @@ async def test_reauth_flow(hass: HomeAssistant) -> None: data=mock_config.data, ) - assert result["type"] == data_entry_flow.RESULT_TYPE_FORM + assert result["type"] == data_entry_flow.FlowResultType.FORM assert result["errors"] == {"base": "invalid_auth"} with patch( @@ -86,7 +86,7 @@ async def test_reauth_flow(hass: HomeAssistant) -> None: await hass.async_block_till_done() assert mock_config.data.get(CONF_API_KEY) == SUBSCRIPTION_KEY - assert result2["type"] == data_entry_flow.RESULT_TYPE_ABORT + assert result2["type"] == data_entry_flow.FlowResultType.ABORT assert result2["reason"] == "reauth_successful" assert len(hass.config_entries.async_entries(DOMAIN)) == 1 @@ -112,7 +112,7 @@ async def test_abort_if_existing_entry(hass: HomeAssistant) -> None: }, ) - assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT + assert result["type"] == data_entry_flow.FlowResultType.ABORT assert result["reason"] == "already_configured" @@ -122,7 +122,7 @@ async def test_user_flow_invalid_subscription_key(hass: HomeAssistant) -> None: DOMAIN, context={"source": config_entries.SOURCE_USER} ) - assert result["type"] == data_entry_flow.RESULT_TYPE_FORM + assert result["type"] == data_entry_flow.FlowResultType.FORM assert result["errors"] == {} with patch( @@ -134,7 +134,7 @@ async def test_user_flow_invalid_subscription_key(hass: HomeAssistant) -> None: {CONF_API_KEY: SUBSCRIPTION_KEY}, ) - assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM + assert result2["type"] == data_entry_flow.FlowResultType.FORM assert result2["step_id"] == "user" assert result2["errors"] == {"base": "invalid_auth"} @@ -147,7 +147,7 @@ async def test_user_flow_exception_on_subscription_key_check( DOMAIN, context={"source": config_entries.SOURCE_USER} ) - assert result["type"] == data_entry_flow.RESULT_TYPE_FORM + assert result["type"] == data_entry_flow.FlowResultType.FORM assert result["errors"] == {} with patch( @@ -159,6 +159,6 @@ async def test_user_flow_exception_on_subscription_key_check( {CONF_API_KEY: SUBSCRIPTION_KEY}, ) - assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM + assert result2["type"] == data_entry_flow.FlowResultType.FORM assert result2["step_id"] == "user" assert result2["errors"] == {"base": "invalid_auth"} diff --git a/tests/test_data_entry_flow.py b/tests/test_data_entry_flow.py index 98380890e416..eb507febe8a1 100644 --- a/tests/test_data_entry_flow.py +++ b/tests/test_data_entry_flow.py @@ -10,7 +10,7 @@ from homeassistant import config_entries, data_entry_flow from homeassistant.core import HomeAssistant from homeassistant.util.decorator import Registry -from .common import async_capture_events +from .common import async_capture_events, import_and_test_deprecated_constant_enum @pytest.fixture @@ -802,3 +802,14 @@ async def test_find_flows_by_init_data_type( ) assert len(wifi_flows) == 0 assert len(manager.async_progress()) == 0 + + +@pytest.mark.parametrize(("enum"), list(data_entry_flow.FlowResultType)) +def test_deprecated_constants( + caplog: pytest.LogCaptureFixture, + enum: data_entry_flow.FlowResultType, +) -> None: + """Test deprecated constants.""" + import_and_test_deprecated_constant_enum( + caplog, data_entry_flow, enum, "RESULT_TYPE_", "2025.1" + )