mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
Remove deprecated state constants from lock (#153367)
This commit is contained in:
@@ -13,28 +13,16 @@ from propcache.api import cached_property
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ( # noqa: F401
|
||||
_DEPRECATED_STATE_JAMMED,
|
||||
_DEPRECATED_STATE_LOCKED,
|
||||
_DEPRECATED_STATE_LOCKING,
|
||||
_DEPRECATED_STATE_UNLOCKED,
|
||||
_DEPRECATED_STATE_UNLOCKING,
|
||||
from homeassistant.const import (
|
||||
ATTR_CODE,
|
||||
ATTR_CODE_FORMAT,
|
||||
SERVICE_LOCK,
|
||||
SERVICE_OPEN,
|
||||
SERVICE_UNLOCK,
|
||||
STATE_OPEN,
|
||||
STATE_OPENING,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.deprecation import (
|
||||
all_with_deprecated_constants,
|
||||
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
|
||||
@@ -317,11 +305,3 @@ class LockEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
||||
return
|
||||
|
||||
self._lock_option_default_code = ""
|
||||
|
||||
|
||||
# These 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_keys=[*globals().keys()]
|
||||
)
|
||||
__all__ = all_with_deprecated_constants(globals())
|
||||
|
||||
@@ -315,34 +315,6 @@ STATE_UNAVAILABLE: Final = "unavailable"
|
||||
STATE_OK: Final = "ok"
|
||||
STATE_PROBLEM: Final = "problem"
|
||||
|
||||
# #### LOCK STATES ####
|
||||
# STATE_* below are deprecated as of 2024.10
|
||||
# use the LockState enum instead.
|
||||
_DEPRECATED_STATE_LOCKED: Final = DeprecatedConstant(
|
||||
"locked",
|
||||
"LockState.LOCKED",
|
||||
"2025.10",
|
||||
)
|
||||
_DEPRECATED_STATE_UNLOCKED: Final = DeprecatedConstant(
|
||||
"unlocked",
|
||||
"LockState.UNLOCKED",
|
||||
"2025.10",
|
||||
)
|
||||
_DEPRECATED_STATE_LOCKING: Final = DeprecatedConstant(
|
||||
"locking",
|
||||
"LockState.LOCKING",
|
||||
"2025.10",
|
||||
)
|
||||
_DEPRECATED_STATE_UNLOCKING: Final = DeprecatedConstant(
|
||||
"unlocking",
|
||||
"LockState.UNLOCKING",
|
||||
"2025.10",
|
||||
)
|
||||
_DEPRECATED_STATE_JAMMED: Final = DeprecatedConstant(
|
||||
"jammed",
|
||||
"LockState.JAMMED",
|
||||
"2025.10",
|
||||
)
|
||||
|
||||
# #### ALARM CONTROL PANEL STATES ####
|
||||
# STATE_ALARM_* below are deprecated as of 2024.11
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import Enum
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import lock
|
||||
from homeassistant.components.lock import (
|
||||
ATTR_CODE,
|
||||
CONF_DEFAULT_CODE,
|
||||
@@ -26,8 +24,6 @@ from homeassistant.helpers.typing import UNDEFINED, UndefinedType
|
||||
|
||||
from .conftest import MockLock
|
||||
|
||||
from tests.common import help_test_all, import_and_test_deprecated_constant_enum
|
||||
|
||||
|
||||
async def help_test_async_lock_service(
|
||||
hass: HomeAssistant,
|
||||
@@ -382,38 +378,3 @@ async def test_lock_with_illegal_default_code(
|
||||
== rf"The code for lock.test_lock doesn't match pattern ^\d{{{4}}}$"
|
||||
)
|
||||
assert exc.value.translation_key == "add_default_code"
|
||||
|
||||
|
||||
def test_all() -> None:
|
||||
"""Test module.__all__ is correctly set."""
|
||||
help_test_all(lock)
|
||||
|
||||
|
||||
def _create_tuples(
|
||||
enum: type[Enum], constant_prefix: str, remove_in_version: str
|
||||
) -> list[tuple[Enum, str]]:
|
||||
return [
|
||||
(enum_field, constant_prefix, remove_in_version)
|
||||
for enum_field in enum
|
||||
if enum_field
|
||||
not in [
|
||||
lock.LockState.OPEN,
|
||||
lock.LockState.OPENING,
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("enum", "constant_prefix", "remove_in_version"),
|
||||
_create_tuples(lock.LockState, "STATE_", "2025.10"),
|
||||
)
|
||||
def test_deprecated_constants(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
enum: Enum,
|
||||
constant_prefix: str,
|
||||
remove_in_version: str,
|
||||
) -> None:
|
||||
"""Test deprecated constants."""
|
||||
import_and_test_deprecated_constant_enum(
|
||||
caplog, lock, enum, constant_prefix, remove_in_version
|
||||
)
|
||||
|
||||
@@ -8,7 +8,7 @@ from unittest.mock import Mock, patch
|
||||
import pytest
|
||||
|
||||
from homeassistant import const
|
||||
from homeassistant.components import alarm_control_panel, lock
|
||||
from homeassistant.components import alarm_control_panel
|
||||
|
||||
from .common import (
|
||||
extract_stack_to_frame,
|
||||
@@ -52,53 +52,15 @@ def test_deprecated_constant_name_changes(
|
||||
)
|
||||
|
||||
|
||||
def _create_tuples_lock_states(
|
||||
enum: type[Enum], constant_prefix: str, remove_in_version: str
|
||||
) -> list[tuple[Enum, str]]:
|
||||
return [
|
||||
(enum_field, constant_prefix, remove_in_version)
|
||||
for enum_field in enum
|
||||
if enum_field
|
||||
not in [
|
||||
lock.LockState.OPEN,
|
||||
lock.LockState.OPENING,
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("enum", "constant_prefix", "remove_in_version"),
|
||||
_create_tuples_lock_states(lock.LockState, "STATE_", "2025.10"),
|
||||
)
|
||||
def test_deprecated_constants_lock(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
enum: Enum,
|
||||
constant_prefix: str,
|
||||
remove_in_version: str,
|
||||
) -> None:
|
||||
"""Test deprecated constants."""
|
||||
import_and_test_deprecated_constant_enum(
|
||||
caplog, const, enum, constant_prefix, remove_in_version
|
||||
)
|
||||
|
||||
|
||||
def _create_tuples_alarm_states(
|
||||
enum: type[Enum], constant_prefix: str, remove_in_version: str
|
||||
) -> list[tuple[Enum, str]]:
|
||||
return [
|
||||
(enum_field, constant_prefix, remove_in_version)
|
||||
for enum_field in enum
|
||||
if enum_field
|
||||
not in [
|
||||
lock.LockState.OPEN,
|
||||
lock.LockState.OPENING,
|
||||
]
|
||||
]
|
||||
return [(enum_field, constant_prefix, remove_in_version) for enum_field in enum]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("enum", "constant_prefix", "remove_in_version"),
|
||||
_create_tuples_lock_states(
|
||||
_create_tuples_alarm_states(
|
||||
alarm_control_panel.AlarmControlPanelState, "STATE_ALARM_", "2025.11"
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user