Skip to content

Commit

Permalink
Deprecate deprecated device_registry helper constants (home-assistant…
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Dec 22, 2023
1 parent 23fa86c commit e18d2b8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
20 changes: 17 additions & 3 deletions homeassistant/helpers/device_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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
Expand All @@ -21,6 +22,11 @@

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
Expand Down Expand Up @@ -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):
Expand Down
15 changes: 14 additions & 1 deletion tests/helpers/test_device_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
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
Expand Down Expand Up @@ -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")

0 comments on commit e18d2b8

Please sign in to comment.