Deprecate deprecated device_registry helper constants (#106227)

pull/106214/head
Robert Resch 2023-12-22 11:21:45 +01:00 committed by GitHub
parent 23fa86cc23
commit e18d2b8873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 4 deletions

View File

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

View File

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