Skip to content
Snippets Groups Projects
Unverified Commit 28e4358c authored by Robert Resch's avatar Robert Resch Committed by GitHub
Browse files

Deprecate deprecated humidifier constants (#106112)

parent 9830f77e
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ from __future__ import annotations ...@@ -3,6 +3,7 @@ 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,12 +23,19 @@ from homeassistant.helpers.config_validation import ( # noqa: F401 ...@@ -22,12 +23,19 @@ from homeassistant.helpers.config_validation import ( # noqa: F401
PLATFORM_SCHEMA, PLATFORM_SCHEMA,
PLATFORM_SCHEMA_BASE, PLATFORM_SCHEMA_BASE,
) )
from homeassistant.helpers.deprecation import (
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
from homeassistant.loader import bind_hass from homeassistant.loader import bind_hass
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,
...@@ -36,15 +44,12 @@ from .const import ( # noqa: F401 ...@@ -36,15 +44,12 @@ from .const import ( # noqa: F401
ATTR_MIN_HUMIDITY, ATTR_MIN_HUMIDITY,
DEFAULT_MAX_HUMIDITY, DEFAULT_MAX_HUMIDITY,
DEFAULT_MIN_HUMIDITY, DEFAULT_MIN_HUMIDITY,
DEVICE_CLASS_DEHUMIDIFIER,
DEVICE_CLASS_HUMIDIFIER,
DOMAIN, DOMAIN,
MODE_AUTO, MODE_AUTO,
MODE_AWAY, MODE_AWAY,
MODE_NORMAL, MODE_NORMAL,
SERVICE_SET_HUMIDITY, SERVICE_SET_HUMIDITY,
SERVICE_SET_MODE, SERVICE_SET_MODE,
SUPPORT_MODES,
HumidifierAction, HumidifierAction,
HumidifierEntityFeature, HumidifierEntityFeature,
) )
...@@ -70,6 +75,12 @@ DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.Coerce(HumidifierDeviceClass)) ...@@ -70,6 +75,12 @@ DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.Coerce(HumidifierDeviceClass))
# use the HumidifierDeviceClass enum instead. # use the HumidifierDeviceClass enum instead.
DEVICE_CLASSES = [cls.value for cls in HumidifierDeviceClass] DEVICE_CLASSES = [cls.value for cls in HumidifierDeviceClass]
# 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
# Both 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=globals())
# mypy: disallow-any-generics # mypy: disallow-any-generics
......
"""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,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
MODE_NORMAL = "normal" MODE_NORMAL = "normal"
MODE_ECO = "eco" MODE_ECO = "eco"
...@@ -35,8 +43,12 @@ DOMAIN = "humidifier" ...@@ -35,8 +43,12 @@ DOMAIN = "humidifier"
# DEVICE_CLASS_* below are deprecated as of 2021.12 # DEVICE_CLASS_* below are deprecated as of 2021.12
# use the HumidifierDeviceClass enum instead. # use the HumidifierDeviceClass enum instead.
DEVICE_CLASS_HUMIDIFIER = "humidifier" _DEPRECATED_DEVICE_CLASS_HUMIDIFIER = DeprecatedConstant(
DEVICE_CLASS_DEHUMIDIFIER = "dehumidifier" "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"
...@@ -50,4 +62,10 @@ class HumidifierEntityFeature(IntFlag): ...@@ -50,4 +62,10 @@ class HumidifierEntityFeature(IntFlag):
# The SUPPORT_MODES constant is deprecated as of Home Assistant 2022.5. # The SUPPORT_MODES constant is deprecated as of Home Assistant 2022.5.
# Please use the HumidifierEntityFeature enum instead. # Please use the HumidifierEntityFeature enum instead.
SUPPORT_MODES = 1 _DEPRECATED_SUPPORT_MODES = DeprecatedConstantEnum(
HumidifierEntityFeature.MODES, "2025.1"
)
# Both 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=globals())
"""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
from homeassistant.components import humidifier
from homeassistant.components.humidifier import HumidifierEntity from homeassistant.components.humidifier import HumidifierEntity
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from tests.common import import_and_test_deprecated_constant_enum
class MockHumidifierEntity(HumidifierEntity): class MockHumidifierEntity(HumidifierEntity):
"""Mock Humidifier device to use in tests.""" """Mock Humidifier device to use in tests."""
...@@ -34,3 +41,28 @@ async def test_sync_turn_off(hass: HomeAssistant) -> None: ...@@ -34,3 +41,28 @@ async def test_sync_turn_off(hass: HomeAssistant) -> None:
await humidifier.async_turn_off() await humidifier.async_turn_off()
assert humidifier.turn_off.called assert humidifier.turn_off.called
def _create_tuples(enum: Enum, constant_prefix: str) -> list[tuple[Enum, str]]:
result = []
for enum in enum:
result.append((enum, constant_prefix))
return result
@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"
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment