Deprecate deprecated sensor constants (#106120)

This commit is contained in:
Robert Resch 2023-12-21 00:02:20 +01:00 committed by GitHub
parent 494a897568
commit d47ec91231
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 6 deletions

View file

@ -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,