mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Deprecate deprecated number constants (#106114)
This commit is contained in:
parent
58759ff6b7
commit
036c856500
@ -2,6 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import StrEnum
|
||||
from functools import partial
|
||||
from typing import Final
|
||||
|
||||
import voluptuous as vol
|
||||
@ -35,6 +36,11 @@ from homeassistant.const import (
|
||||
UnitOfVolume,
|
||||
UnitOfVolumetricFlux,
|
||||
)
|
||||
from homeassistant.helpers.deprecation import (
|
||||
DeprecatedConstantEnum,
|
||||
check_if_deprecated_constant,
|
||||
dir_with_deprecated_constants,
|
||||
)
|
||||
from homeassistant.util.unit_conversion import BaseUnitConverter, TemperatureConverter
|
||||
|
||||
ATTR_VALUE = "value"
|
||||
@ -50,10 +56,23 @@ DOMAIN = "number"
|
||||
|
||||
SERVICE_SET_VALUE = "set_value"
|
||||
|
||||
|
||||
class NumberMode(StrEnum):
|
||||
"""Modes for number entities."""
|
||||
|
||||
AUTO = "auto"
|
||||
BOX = "box"
|
||||
SLIDER = "slider"
|
||||
|
||||
|
||||
# MODE_* are deprecated as of 2021.12, use the NumberMode enum instead.
|
||||
MODE_AUTO: Final = "auto"
|
||||
MODE_BOX: Final = "box"
|
||||
MODE_SLIDER: Final = "slider"
|
||||
_DEPRECATED_MODE_AUTO: Final = DeprecatedConstantEnum(NumberMode.AUTO, "2025.1")
|
||||
_DEPRECATED_MODE_BOX: Final = DeprecatedConstantEnum(NumberMode.BOX, "2025.1")
|
||||
_DEPRECATED_MODE_SLIDER: Final = DeprecatedConstantEnum(NumberMode.SLIDER, "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 NumberDeviceClass(StrEnum):
|
||||
@ -385,14 +404,6 @@ class NumberDeviceClass(StrEnum):
|
||||
"""
|
||||
|
||||
|
||||
class NumberMode(StrEnum):
|
||||
"""Modes for number entities."""
|
||||
|
||||
AUTO = "auto"
|
||||
BOX = "box"
|
||||
SLIDER = "slider"
|
||||
|
||||
|
||||
DEVICE_CLASSES_SCHEMA: Final = vol.All(vol.Lower, vol.Coerce(NumberDeviceClass))
|
||||
DEVICE_CLASS_UNITS: dict[NumberDeviceClass, set[type[StrEnum] | str | None]] = {
|
||||
NumberDeviceClass.APPARENT_POWER: set(UnitOfApparentPower),
|
||||
|
16
tests/components/number/test_const.py
Normal file
16
tests/components/number/test_const.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""Test the number const module."""
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.number import const
|
||||
|
||||
from tests.common import import_and_test_deprecated_constant_enum
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("enum"), list(const.NumberMode))
|
||||
def test_deprecated_constants(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
enum: const.NumberMode,
|
||||
) -> None:
|
||||
"""Test deprecated constants."""
|
||||
import_and_test_deprecated_constant_enum(caplog, const, enum, "MODE_", "2025.1")
|
Loading…
x
Reference in New Issue
Block a user