Skip to content

Commit

Permalink
Deprecate deprecated lock constants (home-assistant#106113)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Dec 20, 2023
1 parent 9dd1b9e commit 491a50a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
11 changes: 10 additions & 1 deletion homeassistant/components/lock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
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
Expand Down Expand Up @@ -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}

Expand Down
12 changes: 12 additions & 0 deletions tests/components/lock/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest

from homeassistant.components import lock
from homeassistant.components.lock import (
ATTR_CODE,
CONF_DEFAULT_CODE,
Expand All @@ -25,6 +26,8 @@

from .conftest import MockLock

from tests.common import import_and_test_deprecated_constant_enum


async def help_test_async_lock_service(
hass: HomeAssistant,
Expand Down Expand Up @@ -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")
4 changes: 2 additions & 2 deletions tests/testing_config/custom_components/test/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(
Expand Down

0 comments on commit 491a50a

Please sign in to comment.