mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Remove deprecated sensor constants (#131843)
This commit is contained in:
parent
4d32fe97c3
commit
1f9ecfe839
@ -8,7 +8,6 @@ from contextlib import suppress
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import UTC, date, datetime, timedelta
|
from datetime import UTC, date, datetime, timedelta
|
||||||
from decimal import Decimal, InvalidOperation as DecimalInvalidOperation
|
from decimal import Decimal, InvalidOperation as DecimalInvalidOperation
|
||||||
from functools import partial
|
|
||||||
import logging
|
import logging
|
||||||
from math import ceil, floor, isfinite, log10
|
from math import ceil, floor, isfinite, log10
|
||||||
from typing import Any, Final, Self, cast, final, override
|
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.core import HomeAssistant, State, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import config_validation as cv, entity_registry as er
|
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 import Entity, EntityDescription
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.entity_platform import EntityPlatform
|
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 homeassistant.util.hass_dict import HassKey
|
||||||
|
|
||||||
from .const import ( # noqa: F401
|
from .const import ( # noqa: F401
|
||||||
_DEPRECATED_STATE_CLASS_MEASUREMENT,
|
|
||||||
_DEPRECATED_STATE_CLASS_TOTAL,
|
|
||||||
_DEPRECATED_STATE_CLASS_TOTAL_INCREASING,
|
|
||||||
ATTR_LAST_RESET,
|
ATTR_LAST_RESET,
|
||||||
ATTR_OPTIONS,
|
ATTR_OPTIONS,
|
||||||
ATTR_STATE_CLASS,
|
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}"
|
value = f"{numerical_value:z.{precision}f}"
|
||||||
|
|
||||||
return value
|
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())
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
from functools import partial
|
|
||||||
from typing import Final
|
from typing import Final
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -41,12 +40,6 @@ from homeassistant.const import (
|
|||||||
UnitOfVolumeFlowRate,
|
UnitOfVolumeFlowRate,
|
||||||
UnitOfVolumetricFlux,
|
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 (
|
from homeassistant.util.unit_conversion import (
|
||||||
AreaConverter,
|
AreaConverter,
|
||||||
BaseUnitConverter,
|
BaseUnitConverter,
|
||||||
@ -494,17 +487,6 @@ class SensorStateClass(StrEnum):
|
|||||||
STATE_CLASSES_SCHEMA: Final = vol.All(vol.Lower, vol.Coerce(SensorStateClass))
|
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]
|
STATE_CLASSES: Final[list[str]] = [cls.value for cls in SensorStateClass]
|
||||||
|
|
||||||
UNIT_CONVERTERS: dict[SensorDeviceClass | str | None, type[BaseUnitConverter]] = {
|
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},
|
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())
|
|
||||||
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
|||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
from datetime import UTC, date, datetime
|
from datetime import UTC, date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from types import ModuleType
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
@ -60,8 +59,6 @@ from tests.common import (
|
|||||||
MockModule,
|
MockModule,
|
||||||
MockPlatform,
|
MockPlatform,
|
||||||
async_mock_restore_state_shutdown_restart,
|
async_mock_restore_state_shutdown_restart,
|
||||||
help_test_all,
|
|
||||||
import_and_test_deprecated_constant_enum,
|
|
||||||
mock_config_flow,
|
mock_config_flow,
|
||||||
mock_integration,
|
mock_integration,
|
||||||
mock_platform,
|
mock_platform,
|
||||||
@ -2643,28 +2640,6 @@ async def test_entity_category_config_raises_error(
|
|||||||
assert not hass.states.get("sensor.test")
|
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(
|
@pytest.mark.parametrize(
|
||||||
("device_class", "native_unit"),
|
("device_class", "native_unit"),
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user