From 491a50a2f1091dc6f960a7bbb127368a34cdbef4 Mon Sep 17 00:00:00 2001 From: Robert Resch <robert@resch.dev> Date: Wed, 20 Dec 2023 18:07:17 +0100 Subject: [PATCH] Deprecate deprecated lock constants (#106113) --- homeassistant/components/lock/__init__.py | 11 ++++++++++- tests/components/lock/test_init.py | 12 ++++++++++++ tests/testing_config/custom_components/test/lock.py | 4 ++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/lock/__init__.py b/homeassistant/components/lock/__init__.py index b28aa9d0a1b..a9f31a3a410 100644 --- a/homeassistant/components/lock/__init__.py +++ b/homeassistant/components/lock/__init__.py @@ -30,6 +30,11 @@ from homeassistant.helpers.config_validation import ( # noqa: F401 PLATFORM_SCHEMA_BASE, make_entity_service_schema, ) +from homeassistant.helpers.deprecation import ( + DeprecatedConstantEnum, + check_if_deprecated_constant, + dir_with_deprecated_constants, +) from homeassistant.helpers.entity import Entity, EntityDescription from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.typing import ConfigType, StateType @@ -57,7 +62,11 @@ class LockEntityFeature(IntFlag): # The SUPPORT_OPEN constant is deprecated as of Home Assistant 2022.5. # Please use the LockEntityFeature enum instead. -SUPPORT_OPEN = 1 +_DEPRECATED_SUPPORT_OPEN = DeprecatedConstantEnum(LockEntityFeature.OPEN, "2025.1") + +# Both can be removed if no deprecated constant are in this module anymore +__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = ft.partial(dir_with_deprecated_constants, module_globals=globals()) PROP_TO_ATTR = {"changed_by": ATTR_CHANGED_BY, "code_format": ATTR_CODE_FORMAT} diff --git a/tests/components/lock/test_init.py b/tests/components/lock/test_init.py index d8589ea265e..a03d975ed8a 100644 --- a/tests/components/lock/test_init.py +++ b/tests/components/lock/test_init.py @@ -5,6 +5,7 @@ from typing import Any import pytest +from homeassistant.components import lock from homeassistant.components.lock import ( ATTR_CODE, CONF_DEFAULT_CODE, @@ -25,6 +26,8 @@ from homeassistant.helpers.typing import UNDEFINED, UndefinedType from .conftest import MockLock +from tests.common import import_and_test_deprecated_constant_enum + async def help_test_async_lock_service( hass: HomeAssistant, @@ -353,3 +356,12 @@ async def test_lock_with_illegal_default_code( await help_test_async_lock_service( hass, mock_lock_entity.entity_id, SERVICE_UNLOCK ) + + +@pytest.mark.parametrize(("enum"), list(LockEntityFeature)) +def test_deprecated_constants( + caplog: pytest.LogCaptureFixture, + enum: LockEntityFeature, +) -> None: + """Test deprecated constants.""" + import_and_test_deprecated_constant_enum(caplog, lock, enum, "SUPPORT_", "2025.1") diff --git a/tests/testing_config/custom_components/test/lock.py b/tests/testing_config/custom_components/test/lock.py index b48e8b1fad9..9cefa34363e 100644 --- a/tests/testing_config/custom_components/test/lock.py +++ b/tests/testing_config/custom_components/test/lock.py @@ -2,7 +2,7 @@ Call init before using it in your tests to ensure clean test data. """ -from homeassistant.components.lock import SUPPORT_OPEN, LockEntity +from homeassistant.components.lock import LockEntity, LockEntityFeature from tests.common import MockEntity @@ -20,7 +20,7 @@ def init(empty=False): "support_open": MockLock( name="Support open Lock", is_locked=True, - supported_features=SUPPORT_OPEN, + supported_features=LockEntityFeature.OPEN, unique_id="unique_support_open", ), "no_support_open": MockLock( -- GitLab