Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated humidifier constants #131844

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions homeassistant/components/humidifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from datetime import timedelta
from enum import StrEnum
from functools import partial
import logging
from typing import Any, final

Expand All @@ -22,21 +21,13 @@
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import ServiceValidationError
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_component import EntityComponent
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import bind_hass
from homeassistant.util.hass_dict import HassKey

from .const import ( # noqa: F401
_DEPRECATED_DEVICE_CLASS_DEHUMIDIFIER,
_DEPRECATED_DEVICE_CLASS_HUMIDIFIER,
_DEPRECATED_SUPPORT_MODES,
ATTR_ACTION,
ATTR_AVAILABLE_MODES,
ATTR_CURRENT_HUMIDITY,
Expand Down Expand Up @@ -314,13 +305,3 @@ async def async_service_humidity_set(
)

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())
32 changes: 0 additions & 32 deletions homeassistant/components/humidifier/const.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
"""Provides the constants needed for component."""

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_ECO = "eco"
Expand Down Expand Up @@ -43,15 +34,6 @@ class HumidifierAction(StrEnum):

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_HUMIDITY = "set_humidity"

Expand All @@ -60,17 +42,3 @@ class HumidifierEntityFeature(IntFlag):
"""Supported features of the humidifier entity."""

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())
42 changes: 1 addition & 41 deletions tests/components/humidifier/test_init.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
"""The tests for the humidifier component."""

from enum import Enum
from types import ModuleType
from unittest.mock import MagicMock

import pytest

from homeassistant.components import humidifier
from homeassistant.components.humidifier import (
ATTR_HUMIDITY,
ATTR_MODE,
Expand All @@ -20,13 +17,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError

from tests.common import (
MockConfigEntry,
MockEntity,
help_test_all,
import_and_test_deprecated_constant_enum,
setup_test_component_platform,
)
from tests.common import MockConfigEntry, MockEntity, setup_test_component_platform


class MockHumidifierEntity(MockEntity, HumidifierEntity):
Expand Down Expand Up @@ -60,37 +51,6 @@ async def test_sync_turn_off(hass: HomeAssistant) -> None:
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:
"""Test deprecated supported features ints."""

Expand Down
Loading