Remove deprecated humidifier constants (#131844)

This commit is contained in:
Robert Resch 2024-11-28 16:59:11 +01:00 committed by GitHub
parent 0c5c09390c
commit 0389800e2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 1 additions and 92 deletions

View File

@ -4,7 +4,6 @@ from __future__ import annotations
from datetime import timedelta from datetime import timedelta
from enum import StrEnum from enum import StrEnum
from functools import partial
import logging import logging
from typing import Any, final from typing import Any, final
@ -22,11 +21,6 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import ServiceValidationError from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.deprecation import (
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
from homeassistant.helpers.entity import ToggleEntity, ToggleEntityDescription from homeassistant.helpers.entity import ToggleEntity, ToggleEntityDescription
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
@ -34,9 +28,6 @@ from homeassistant.loader import bind_hass
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_DEVICE_CLASS_DEHUMIDIFIER,
_DEPRECATED_DEVICE_CLASS_HUMIDIFIER,
_DEPRECATED_SUPPORT_MODES,
ATTR_ACTION, ATTR_ACTION,
ATTR_AVAILABLE_MODES, ATTR_AVAILABLE_MODES,
ATTR_CURRENT_HUMIDITY, ATTR_CURRENT_HUMIDITY,
@ -314,13 +305,3 @@ async def async_service_humidity_set(
) )
await entity.async_set_humidity(humidity) await entity.async_set_humidity(humidity)
# 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

@ -1,15 +1,6 @@
"""Provides the constants needed for component.""" """Provides the constants needed for component."""
from enum import IntFlag, StrEnum from enum import IntFlag, StrEnum
from functools import partial
from homeassistant.helpers.deprecation import (
DeprecatedConstant,
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
MODE_NORMAL = "normal" MODE_NORMAL = "normal"
MODE_ECO = "eco" MODE_ECO = "eco"
@ -43,15 +34,6 @@ DEFAULT_MAX_HUMIDITY = 100
DOMAIN = "humidifier" DOMAIN = "humidifier"
# DEVICE_CLASS_* below are deprecated as of 2021.12
# use the HumidifierDeviceClass enum instead.
_DEPRECATED_DEVICE_CLASS_HUMIDIFIER = DeprecatedConstant(
"humidifier", "HumidifierDeviceClass.HUMIDIFIER", "2025.1"
)
_DEPRECATED_DEVICE_CLASS_DEHUMIDIFIER = DeprecatedConstant(
"dehumidifier", "HumidifierDeviceClass.DEHUMIDIFIER", "2025.1"
)
SERVICE_SET_MODE = "set_mode" SERVICE_SET_MODE = "set_mode"
SERVICE_SET_HUMIDITY = "set_humidity" SERVICE_SET_HUMIDITY = "set_humidity"
@ -60,17 +42,3 @@ class HumidifierEntityFeature(IntFlag):
"""Supported features of the humidifier entity.""" """Supported features of the humidifier entity."""
MODES = 1 MODES = 1
# The SUPPORT_MODES constant is deprecated as of Home Assistant 2022.5.
# Please use the HumidifierEntityFeature enum instead.
_DEPRECATED_SUPPORT_MODES = DeprecatedConstantEnum(
HumidifierEntityFeature.MODES, "2025.1"
)
# 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

@ -1,12 +1,9 @@
"""The tests for the humidifier component.""" """The tests for the humidifier component."""
from enum import Enum
from types import ModuleType
from unittest.mock import MagicMock from unittest.mock import MagicMock
import pytest import pytest
from homeassistant.components import humidifier
from homeassistant.components.humidifier import ( from homeassistant.components.humidifier import (
ATTR_HUMIDITY, ATTR_HUMIDITY,
ATTR_MODE, ATTR_MODE,
@ -20,13 +17,7 @@ from homeassistant.components.humidifier import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError from homeassistant.exceptions import ServiceValidationError
from tests.common import ( from tests.common import MockConfigEntry, MockEntity, setup_test_component_platform
MockConfigEntry,
MockEntity,
help_test_all,
import_and_test_deprecated_constant_enum,
setup_test_component_platform,
)
class MockHumidifierEntity(MockEntity, HumidifierEntity): class MockHumidifierEntity(MockEntity, HumidifierEntity):
@ -60,37 +51,6 @@ async def test_sync_turn_off(hass: HomeAssistant) -> None:
assert humidifier.turn_off.called assert humidifier.turn_off.called
def _create_tuples(enum: type[Enum], constant_prefix: str) -> list[tuple[Enum, str]]:
return [(enum_field, constant_prefix) for enum_field in enum]
@pytest.mark.parametrize(
"module",
[humidifier, humidifier.const],
)
def test_all(module: ModuleType) -> None:
"""Test module.__all__ is correctly set."""
help_test_all(module)
@pytest.mark.parametrize(
("enum", "constant_prefix"),
_create_tuples(humidifier.HumidifierEntityFeature, "SUPPORT_")
+ _create_tuples(humidifier.HumidifierDeviceClass, "DEVICE_CLASS_"),
)
@pytest.mark.parametrize(("module"), [humidifier, humidifier.const])
def test_deprecated_constants(
caplog: pytest.LogCaptureFixture,
enum: Enum,
constant_prefix: str,
module: ModuleType,
) -> None:
"""Test deprecated constants."""
import_and_test_deprecated_constant_enum(
caplog, module, enum, constant_prefix, "2025.1"
)
def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None: def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None:
"""Test deprecated supported features ints.""" """Test deprecated supported features ints."""