mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Deprecate deprecated data entry flow constants (#106229)
This commit is contained in:
parent
859e7972ac
commit
060172fc24
@ -6,6 +6,7 @@ from collections.abc import Callable, Iterable, Mapping
|
|||||||
import copy
|
import copy
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
|
from functools import partial
|
||||||
import logging
|
import logging
|
||||||
from types import MappingProxyType
|
from types import MappingProxyType
|
||||||
from typing import Any, Required, TypedDict
|
from typing import Any, Required, TypedDict
|
||||||
@ -14,6 +15,11 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from .core import HomeAssistant, callback
|
from .core import HomeAssistant, callback
|
||||||
from .exceptions import HomeAssistantError
|
from .exceptions import HomeAssistantError
|
||||||
|
from .helpers.deprecation import (
|
||||||
|
DeprecatedConstantEnum,
|
||||||
|
check_if_deprecated_constant,
|
||||||
|
dir_with_deprecated_constants,
|
||||||
|
)
|
||||||
from .helpers.frame import report
|
from .helpers.frame import report
|
||||||
from .util import uuid as uuid_util
|
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_* is deprecated, to be removed in 2022.9
|
||||||
RESULT_TYPE_FORM = "form"
|
_DEPRECATED_RESULT_TYPE_FORM = DeprecatedConstantEnum(FlowResultType.FORM, "2025.1")
|
||||||
RESULT_TYPE_CREATE_ENTRY = "create_entry"
|
_DEPRECATED_RESULT_TYPE_CREATE_ENTRY = DeprecatedConstantEnum(
|
||||||
RESULT_TYPE_ABORT = "abort"
|
FlowResultType.CREATE_ENTRY, "2025.1"
|
||||||
RESULT_TYPE_EXTERNAL_STEP = "external"
|
)
|
||||||
RESULT_TYPE_EXTERNAL_STEP_DONE = "external_done"
|
_DEPRECATED_RESULT_TYPE_ABORT = DeprecatedConstantEnum(FlowResultType.ABORT, "2025.1")
|
||||||
RESULT_TYPE_SHOW_PROGRESS = "progress"
|
_DEPRECATED_RESULT_TYPE_EXTERNAL_STEP = DeprecatedConstantEnum(
|
||||||
RESULT_TYPE_SHOW_PROGRESS_DONE = "progress_done"
|
FlowResultType.EXTERNAL_STEP, "2025.1"
|
||||||
RESULT_TYPE_MENU = "menu"
|
)
|
||||||
|
_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 that is fired when a flow is progressed via external or progress source.
|
||||||
EVENT_DATA_ENTRY_FLOW_PROGRESSED = "data_entry_flow_progressed"
|
EVENT_DATA_ENTRY_FLOW_PROGRESSED = "data_entry_flow_progressed"
|
||||||
|
@ -22,7 +22,7 @@ async def test_user_flow(hass: HomeAssistant) -> None:
|
|||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
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"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
@ -37,7 +37,7 @@ async def test_user_flow(hass: HomeAssistant) -> None:
|
|||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
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["title"] == TEST_USER_EMAIL
|
||||||
assert result2["data"] == {
|
assert result2["data"] == {
|
||||||
CONF_API_KEY: SUBSCRIPTION_KEY,
|
CONF_API_KEY: SUBSCRIPTION_KEY,
|
||||||
@ -70,7 +70,7 @@ async def test_reauth_flow(hass: HomeAssistant) -> None:
|
|||||||
data=mock_config.data,
|
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"}
|
assert result["errors"] == {"base": "invalid_auth"}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
@ -86,7 +86,7 @@ async def test_reauth_flow(hass: HomeAssistant) -> None:
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert mock_config.data.get(CONF_API_KEY) == SUBSCRIPTION_KEY
|
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 result2["reason"] == "reauth_successful"
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
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"
|
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}
|
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"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
@ -134,7 +134,7 @@ async def test_user_flow_invalid_subscription_key(hass: HomeAssistant) -> None:
|
|||||||
{CONF_API_KEY: SUBSCRIPTION_KEY},
|
{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["step_id"] == "user"
|
||||||
assert result2["errors"] == {"base": "invalid_auth"}
|
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}
|
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"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
@ -159,6 +159,6 @@ async def test_user_flow_exception_on_subscription_key_check(
|
|||||||
{CONF_API_KEY: SUBSCRIPTION_KEY},
|
{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["step_id"] == "user"
|
||||||
assert result2["errors"] == {"base": "invalid_auth"}
|
assert result2["errors"] == {"base": "invalid_auth"}
|
||||||
|
@ -10,7 +10,7 @@ from homeassistant import config_entries, data_entry_flow
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.util.decorator import Registry
|
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
|
@pytest.fixture
|
||||||
@ -802,3 +802,14 @@ async def test_find_flows_by_init_data_type(
|
|||||||
)
|
)
|
||||||
assert len(wifi_flows) == 0
|
assert len(wifi_flows) == 0
|
||||||
assert len(manager.async_progress()) == 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"
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user