Deprecate deprecated remote constants (#106116)

This commit is contained in:
Robert Resch 2023-12-20 17:20:50 +01:00 committed by GitHub
parent 93c800c4e8
commit 58759ff6b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 4 deletions

View file

@ -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}

View file

@ -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")