From e18d2b887337696cf6f067eba0091f5e6ecbd4d3 Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Fri, 22 Dec 2023 11:21:45 +0100 Subject: [PATCH] Deprecate deprecated device_registry helper constants (#106227) --- homeassistant/helpers/device_registry.py | 20 +++++++++++++++++--- tests/helpers/test_device_registry.py | 15 ++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/device_registry.py b/homeassistant/helpers/device_registry.py index 9a26821faaf..bd509cb47ec 100644 --- a/homeassistant/helpers/device_registry.py +++ b/homeassistant/helpers/device_registry.py @@ -4,6 +4,7 @@ from __future__ import annotations from collections import UserDict from collections.abc import Coroutine, ValuesView from enum import StrEnum +from functools import partial import logging import time from typing import TYPE_CHECKING, Any, Literal, TypedDict, TypeVar, cast @@ -21,6 +22,11 @@ import homeassistant.util.uuid as uuid_util from . import storage from .debounce import Debouncer +from .deprecation import ( + DeprecatedConstantEnum, + check_if_deprecated_constant, + dir_with_deprecated_constants, +) from .frame import report from .json import JSON_DUMP, find_paths_unserializable_data from .typing import UNDEFINED, UndefinedType @@ -61,9 +67,17 @@ class DeviceEntryDisabler(StrEnum): # DISABLED_* are deprecated, to be removed in 2022.3 -DISABLED_CONFIG_ENTRY = DeviceEntryDisabler.CONFIG_ENTRY.value -DISABLED_INTEGRATION = DeviceEntryDisabler.INTEGRATION.value -DISABLED_USER = DeviceEntryDisabler.USER.value +_DEPRECATED_DISABLED_CONFIG_ENTRY = DeprecatedConstantEnum( + DeviceEntryDisabler.CONFIG_ENTRY, "2025.1" +) +_DEPRECATED_DISABLED_INTEGRATION = DeprecatedConstantEnum( + DeviceEntryDisabler.INTEGRATION, "2025.1" +) +_DEPRECATED_DISABLED_USER = DeprecatedConstantEnum(DeviceEntryDisabler.USER, "2025.1") + +# Both can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) class DeviceInfo(TypedDict, total=False): diff --git a/tests/helpers/test_device_registry.py b/tests/helpers/test_device_registry.py index 657d8871e66..43540a52f7d 100644 --- a/tests/helpers/test_device_registry.py +++ b/tests/helpers/test_device_registry.py @@ -17,7 +17,11 @@ from homeassistant.helpers import ( entity_registry as er, ) -from tests.common import MockConfigEntry, flush_store +from tests.common import ( + MockConfigEntry, + flush_store, + import_and_test_deprecated_constant_enum, +) @pytest.fixture @@ -2012,3 +2016,12 @@ async def test_loading_invalid_configuration_url_from_storage( identifiers={("serial", "123456ABCDEF")}, ) assert entry.configuration_url == "invalid" + + +@pytest.mark.parametrize(("enum"), list(dr.DeviceEntryDisabler)) +def test_deprecated_constants( + caplog: pytest.LogCaptureFixture, + enum: dr.DeviceEntryDisabler, +) -> None: + """Test deprecated constants.""" + import_and_test_deprecated_constant_enum(caplog, dr, enum, "DISABLED_", "2025.1")