From 1f9ecfe8390e1b3382b5c095d05eb5ca20ca5c9f Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Thu, 28 Nov 2024 20:49:49 +0100 Subject: [PATCH] Remove deprecated sensor constants (#131843) --- homeassistant/components/sensor/__init__.py | 19 ---------------- homeassistant/components/sensor/const.py | 25 --------------------- tests/components/sensor/test_init.py | 25 --------------------- 3 files changed, 69 deletions(-) diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index 3c92506a45e..6b264efdd46 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -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()) diff --git a/homeassistant/components/sensor/const.py b/homeassistant/components/sensor/const.py index 87012c3631a..4d0454cbff3 100644 --- a/homeassistant/components/sensor/const.py +++ b/homeassistant/components/sensor/const.py @@ -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()) diff --git a/tests/components/sensor/test_init.py b/tests/components/sensor/test_init.py index 6c2d73cb68c..44ad076807c 100644 --- a/tests/components/sensor/test_init.py +++ b/tests/components/sensor/test_init.py @@ -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"), [