Skip to content

Commit

Permalink
Remove deprecated sensor constants (#131843)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Nov 28, 2024
1 parent 4d32fe9 commit 1f9ecfe
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 69 deletions.
19 changes: 0 additions & 19 deletions homeassistant/components/sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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
Expand All @@ -25,11 +24,6 @@
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
Expand All @@ -40,9 +34,6 @@
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,
Expand Down Expand Up @@ -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())
25 changes: 0 additions & 25 deletions homeassistant/components/sensor/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

from enum import StrEnum
from functools import partial
from typing import Final

import voluptuous as vol
Expand Down Expand Up @@ -41,12 +40,6 @@
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,
Expand Down Expand Up @@ -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]] = {
Expand Down Expand Up @@ -683,10 +665,3 @@ class SensorStateClass(StrEnum):
},
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())
25 changes: 0 additions & 25 deletions tests/components/sensor/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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

Expand Down Expand Up @@ -60,8 +59,6 @@
MockModule,
MockPlatform,
async_mock_restore_state_shutdown_restart,
help_test_all,
import_and_test_deprecated_constant_enum,
mock_config_flow,
mock_integration,
mock_platform,
Expand Down Expand Up @@ -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"),
[
Expand Down

0 comments on commit 1f9ecfe

Please sign in to comment.