mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 07:47:08 +00:00
Remove deprecated binary sensor constants (#131793)
This commit is contained in:
parent
fb152c7d22
commit
b28f352902
@ -4,7 +4,6 @@ from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
from enum import StrEnum
|
||||
from functools import partial
|
||||
import logging
|
||||
from typing import Literal, final
|
||||
|
||||
@ -16,12 +15,6 @@ from homeassistant.const import STATE_OFF, STATE_ON, EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.deprecation import (
|
||||
DeprecatedConstantEnum,
|
||||
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.typing import ConfigType
|
||||
@ -126,94 +119,7 @@ class BinarySensorDeviceClass(StrEnum):
|
||||
|
||||
|
||||
DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.Coerce(BinarySensorDeviceClass))
|
||||
|
||||
# DEVICE_CLASS* below are deprecated as of 2021.12
|
||||
# use the BinarySensorDeviceClass enum instead.
|
||||
DEVICE_CLASSES = [cls.value for cls in BinarySensorDeviceClass]
|
||||
_DEPRECATED_DEVICE_CLASS_BATTERY = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.BATTERY, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_BATTERY_CHARGING = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.BATTERY_CHARGING, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_CO = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.CO, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_COLD = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.COLD, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_CONNECTIVITY = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.CONNECTIVITY, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_DOOR = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.DOOR, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_GARAGE_DOOR = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.GARAGE_DOOR, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_GAS = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.GAS, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_HEAT = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.HEAT, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_LIGHT = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.LIGHT, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_LOCK = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.LOCK, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_MOISTURE = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.MOISTURE, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_MOTION = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.MOTION, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_MOVING = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.MOVING, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_OCCUPANCY = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.OCCUPANCY, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_OPENING = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.OPENING, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_PLUG = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.PLUG, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_POWER = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.POWER, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_PRESENCE = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.PRESENCE, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_PROBLEM = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.PROBLEM, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_RUNNING = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.RUNNING, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_SAFETY = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.SAFETY, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_SMOKE = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.SMOKE, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_SOUND = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.SOUND, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_TAMPER = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.TAMPER, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_UPDATE = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.UPDATE, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_VIBRATION = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.VIBRATION, "2025.1"
|
||||
)
|
||||
_DEPRECATED_DEVICE_CLASS_WINDOW = DeprecatedConstantEnum(
|
||||
BinarySensorDeviceClass.WINDOW, "2025.1"
|
||||
)
|
||||
|
||||
# mypy: disallow-any-generics
|
||||
|
||||
@ -294,11 +200,3 @@ class BinarySensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_)
|
||||
if (is_on := self.is_on) is None:
|
||||
return None
|
||||
return STATE_ON if is_on else STATE_OFF
|
||||
|
||||
|
||||
# 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())
|
||||
|
@ -17,8 +17,6 @@ from tests.common import (
|
||||
MockConfigEntry,
|
||||
MockModule,
|
||||
MockPlatform,
|
||||
help_test_all,
|
||||
import_and_test_deprecated_constant_enum,
|
||||
mock_config_flow,
|
||||
mock_integration,
|
||||
mock_platform,
|
||||
@ -198,22 +196,3 @@ async def test_entity_category_config_raises_error(
|
||||
"Entity binary_sensor.test2 cannot be added as the entity category is set to config"
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
|
||||
def test_all() -> None:
|
||||
"""Test module.__all__ is correctly set."""
|
||||
help_test_all(binary_sensor)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"device_class",
|
||||
list(binary_sensor.BinarySensorDeviceClass),
|
||||
)
|
||||
def test_deprecated_constant_device_class(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_class: binary_sensor.BinarySensorDeviceClass,
|
||||
) -> None:
|
||||
"""Test deprecated binary sensor device classes."""
|
||||
import_and_test_deprecated_constant_enum(
|
||||
caplog, binary_sensor, device_class, "DEVICE_CLASS_", "2025.1"
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user