Skip to content

Commit

Permalink
Remove deprecated siren constants (home-assistant#131807)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Nov 28, 2024
1 parent 4d27a32 commit 3e0326d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 79 deletions.
23 changes: 1 addition & 22 deletions homeassistant/components/siren/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

from datetime import timedelta
from functools import partial
import logging
from typing import Any, TypedDict, cast, final

Expand All @@ -14,22 +13,12 @@
from homeassistant.const import SERVICE_TOGGLE, SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.core import HomeAssistant, ServiceCall
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, VolDictType
from homeassistant.util.hass_dict import HassKey

from .const import ( # noqa: F401
_DEPRECATED_SUPPORT_DURATION,
_DEPRECATED_SUPPORT_TONES,
_DEPRECATED_SUPPORT_TURN_OFF,
_DEPRECATED_SUPPORT_TURN_ON,
_DEPRECATED_SUPPORT_VOLUME_SET,
from .const import (
ATTR_AVAILABLE_TONES,
ATTR_DURATION,
ATTR_TONE,
Expand Down Expand Up @@ -208,13 +197,3 @@ def supported_features(self) -> SirenEntityFeature:
self._report_deprecated_supported_features_values(new_features)
return new_features
return features


# 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())
34 changes: 0 additions & 34 deletions homeassistant/components/siren/const.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
"""Constants for the siren component."""

from enum import IntFlag
from functools import partial
from typing import Final

from homeassistant.helpers.deprecation import (
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)

DOMAIN: Final = "siren"

ATTR_TONE: Final = "tone"
Expand All @@ -28,29 +20,3 @@ class SirenEntityFeature(IntFlag):
TONES = 4
VOLUME_SET = 8
DURATION = 16


# These constants are deprecated as of Home Assistant 2022.5
# Please use the SirenEntityFeature enum instead.
_DEPRECATED_SUPPORT_TURN_ON: Final = DeprecatedConstantEnum(
SirenEntityFeature.TURN_ON, "2025.1"
)
_DEPRECATED_SUPPORT_TURN_OFF: Final = DeprecatedConstantEnum(
SirenEntityFeature.TURN_OFF, "2025.1"
)
_DEPRECATED_SUPPORT_TONES: Final = DeprecatedConstantEnum(
SirenEntityFeature.TONES, "2025.1"
)
_DEPRECATED_SUPPORT_VOLUME_SET: Final = DeprecatedConstantEnum(
SirenEntityFeature.VOLUME_SET, "2025.1"
)
_DEPRECATED_SUPPORT_DURATION: Final = DeprecatedConstantEnum(
SirenEntityFeature.DURATION, "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())
23 changes: 0 additions & 23 deletions tests/components/siren/test_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""The tests for the siren component."""

from types import ModuleType
from unittest.mock import MagicMock

import pytest
Expand All @@ -14,8 +13,6 @@
from homeassistant.components.siren.const import SirenEntityFeature
from homeassistant.core import HomeAssistant

from tests.common import help_test_all, import_and_test_deprecated_constant_enum


class MockSirenEntity(SirenEntity):
"""Mock siren device to use in tests."""
Expand Down Expand Up @@ -111,26 +108,6 @@ async def test_missing_tones_dict(hass: HomeAssistant) -> None:
process_turn_on_params(siren, {"tone": 3})


@pytest.mark.parametrize(
"module",
[siren, siren.const],
)
def test_all(module: ModuleType) -> None:
"""Test module.__all__ is correctly set."""
help_test_all(module)


@pytest.mark.parametrize(("enum"), list(SirenEntityFeature))
@pytest.mark.parametrize(("module"), [siren, siren.const])
def test_deprecated_constants(
caplog: pytest.LogCaptureFixture,
enum: SirenEntityFeature,
module: ModuleType,
) -> None:
"""Test deprecated constants."""
import_and_test_deprecated_constant_enum(caplog, module, enum, "SUPPORT_", "2025.1")


def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None:
"""Test deprecated supported features ints."""

Expand Down

0 comments on commit 3e0326d

Please sign in to comment.