Deprecate deprecated sensor constants (#106120)
This commit is contained in:
parent
494a897568
commit
d47ec91231
3 changed files with 49 additions and 6 deletions
|
@ -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,
|
||||
DataRateConverter,
|
||||
|
@ -451,11 +457,21 @@ STATE_CLASSES_SCHEMA: Final = vol.All(vol.Lower, vol.Coerce(SensorStateClass))
|
|||
|
||||
# STATE_CLASS* is deprecated as of 2021.12
|
||||
# use the SensorStateClass enum instead.
|
||||
STATE_CLASS_MEASUREMENT: Final = "measurement"
|
||||
STATE_CLASS_TOTAL: Final = "total"
|
||||
STATE_CLASS_TOTAL_INCREASING: Final = "total_increasing"
|
||||
_DEPRECATED_STATE_CLASS_MEASUREMENT: Final = DeprecatedConstantEnum(
|
||||
SensorStateClass.MEASUREMENT, "2025.1"
|
||||
)
|
||||
_DEPRECATED_STATE_CLASS_TOTAL: Final = DeprecatedConstantEnum(
|
||||
SensorStateClass.TOTAL, "2025.1"
|
||||
)
|
||||
_DEPRECATED_STATE_CLASS_TOTAL_INCREASING: Final = DeprecatedConstantEnum(
|
||||
SensorStateClass.TOTAL_INCREASING, "2025.1"
|
||||
)
|
||||
STATE_CLASSES: Final[list[str]] = [cls.value for cls in SensorStateClass]
|
||||
|
||||
# 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())
|
||||
|
||||
UNIT_CONVERTERS: dict[SensorDeviceClass | str | None, type[BaseUnitConverter]] = {
|
||||
SensorDeviceClass.ATMOSPHERIC_PRESSURE: PressureConverter,
|
||||
SensorDeviceClass.CURRENT: ElectricCurrentConverter,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue