From 58759ff6b7d748e59e9bc976ca37ab385e5f85e2 Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Wed, 20 Dec 2023 17:20:50 +0100 Subject: [PATCH] Deprecate deprecated remote constants (#106116) --- homeassistant/components/remote/__init__.py | 22 ++++++++++++++++++--- tests/components/remote/test_init.py | 13 +++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/remote/__init__.py b/homeassistant/components/remote/__init__.py index 2901c14c455..a85784a33a7 100644 --- a/homeassistant/components/remote/__init__.py +++ b/homeassistant/components/remote/__init__.py @@ -25,6 +25,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 ToggleEntity, ToggleEntityDescription from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.typing import ConfigType @@ -70,9 +75,20 @@ class RemoteEntityFeature(IntFlag): # These SUPPORT_* constants are deprecated as of Home Assistant 2022.5. # Please use the RemoteEntityFeature enum instead. -SUPPORT_LEARN_COMMAND = 1 -SUPPORT_DELETE_COMMAND = 2 -SUPPORT_ACTIVITY = 4 +_DEPRECATED_SUPPORT_LEARN_COMMAND = DeprecatedConstantEnum( + RemoteEntityFeature.LEARN_COMMAND, "2025.1" +) +_DEPRECATED_SUPPORT_DELETE_COMMAND = DeprecatedConstantEnum( + RemoteEntityFeature.DELETE_COMMAND, "2025.1" +) +_DEPRECATED_SUPPORT_ACTIVITY = DeprecatedConstantEnum( + RemoteEntityFeature.ACTIVITY, "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()) REMOTE_SERVICE_ACTIVITY_SCHEMA = make_entity_service_schema( {vol.Optional(ATTR_ACTIVITY): cv.string} diff --git a/tests/components/remote/test_init.py b/tests/components/remote/test_init.py index 6219943693b..b185b229cd2 100644 --- a/tests/components/remote/test_init.py +++ b/tests/components/remote/test_init.py @@ -1,4 +1,6 @@ """The tests for the Remote component, adapted from Light Test.""" +import pytest + import homeassistant.components.remote as remote from homeassistant.components.remote import ( ATTR_ALTERNATIVE, @@ -20,7 +22,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant -from tests.common import async_mock_service +from tests.common import async_mock_service, import_and_test_deprecated_constant_enum TEST_PLATFORM = {DOMAIN: {CONF_PLATFORM: "test"}} SERVICE_SEND_COMMAND = "send_command" @@ -139,3 +141,12 @@ async def test_delete_command(hass: HomeAssistant) -> None: assert call.domain == remote.DOMAIN assert call.service == SERVICE_DELETE_COMMAND assert call.data[ATTR_ENTITY_ID] == ENTITY_ID + + +@pytest.mark.parametrize(("enum"), list(remote.RemoteEntityFeature)) +def test_deprecated_constants( + caplog: pytest.LogCaptureFixture, + enum: remote.RemoteEntityFeature, +) -> None: + """Test deprecated constants.""" + import_and_test_deprecated_constant_enum(caplog, remote, enum, "SUPPORT_", "2025.1")