Remove deprecated sensor constants (#131843)

This commit is contained in:
Robert Resch 2024-11-28 20:49:49 +01:00 committed by GitHub
parent 4d32fe97c3
commit 1f9ecfe839
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 0 additions and 69 deletions

View File

@ -8,7 +8,6 @@ from contextlib import suppress
from dataclasses import dataclass
from datetime import UTC, date, datetime, timedelta
from decimal import Decimal, InvalidOperation as DecimalInvalidOperation
from functools import partial
import logging
from math import ceil, floor, isfinite, log10
from typing import Any, Final, Self, cast, final, override
@ -25,11 +24,6 @@ from homeassistant.const import ( # noqa: F401
from homeassistant.core import HomeAssistant, State, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, entity_registry as er
from homeassistant.helpers.deprecation import (
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.entity_platform import EntityPlatform
@ -40,9 +34,6 @@ from homeassistant.util.enum import try_parse_enum
from homeassistant.util.hass_dict import HassKey
from .const import ( # noqa: F401
_DEPRECATED_STATE_CLASS_MEASUREMENT,
_DEPRECATED_STATE_CLASS_TOTAL,
_DEPRECATED_STATE_CLASS_TOTAL_INCREASING,
ATTR_LAST_RESET,
ATTR_OPTIONS,
ATTR_STATE_CLASS,
@ -962,13 +953,3 @@ def async_rounded_state(hass: HomeAssistant, entity_id: str, state: State) -> st
value = f"{numerical_value:z.{precision}f}"
return value
# As we import deprecated constants from the const module, we need to add these two functions
# otherwise this module will be logged for using deprecated constants and not the custom component
# These 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_keys=[*globals().keys()]
)
__all__ = all_with_deprecated_constants(globals())

View File

@ -3,7 +3,6 @@
from __future__ import annotations
from enum import StrEnum
from functools import partial
from typing import Final
import voluptuous as vol
@ -41,12 +40,6 @@ from homeassistant.const import (
UnitOfVolumeFlowRate,
UnitOfVolumetricFlux,
)
from homeassistant.helpers.deprecation import (
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
from homeassistant.util.unit_conversion import (
AreaConverter,
BaseUnitConverter,
@ -494,17 +487,6 @@ class SensorStateClass(StrEnum):
STATE_CLASSES_SCHEMA: Final = vol.All(vol.Lower, vol.Coerce(SensorStateClass))
# STATE_CLASS* is deprecated as of 2021.12
# use the SensorStateClass enum instead.
_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]
UNIT_CONVERTERS: dict[SensorDeviceClass | str | None, type[BaseUnitConverter]] = {
@ -683,10 +665,3 @@ DEVICE_CLASS_STATE_CLASSES: dict[SensorDeviceClass, set[SensorStateClass]] = {
},
SensorDeviceClass.WIND_SPEED: {SensorStateClass.MEASUREMENT},
}
# These 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_keys=[*globals().keys()]
)
__all__ = all_with_deprecated_constants(globals())

View File

@ -5,7 +5,6 @@ from __future__ import annotations
from collections.abc import Generator
from datetime import UTC, date, datetime
from decimal import Decimal
from types import ModuleType
from typing import Any
from unittest.mock import patch
@ -60,8 +59,6 @@ from tests.common import (
MockModule,
MockPlatform,
async_mock_restore_state_shutdown_restart,
help_test_all,
import_and_test_deprecated_constant_enum,
mock_config_flow,
mock_integration,
mock_platform,
@ -2643,28 +2640,6 @@ async def test_entity_category_config_raises_error(
assert not hass.states.get("sensor.test")
@pytest.mark.parametrize(
"module",
[sensor, sensor.const],
)
def test_all(module: ModuleType) -> None:
"""Test module.__all__ is correctly set."""
help_test_all(module)
@pytest.mark.parametrize(("enum"), list(sensor.SensorStateClass))
@pytest.mark.parametrize(("module"), [sensor, sensor.const])
def test_deprecated_constants(
caplog: pytest.LogCaptureFixture,
enum: sensor.SensorStateClass,
module: ModuleType,
) -> None:
"""Test deprecated constants."""
import_and_test_deprecated_constant_enum(
caplog, module, enum, "STATE_CLASS_", "2025.1"
)
@pytest.mark.parametrize(
("device_class", "native_unit"),
[