Remove deprecated siren constants (#131807)

This commit is contained in:
Robert Resch 2024-11-28 12:14:43 +01:00 committed by GitHub
parent 4d27a32905
commit 3e0326dd66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 1 additions and 79 deletions

View File

@ -3,7 +3,6 @@
from __future__ import annotations from __future__ import annotations
from datetime import timedelta from datetime import timedelta
from functools import partial
import logging import logging
from typing import Any, TypedDict, cast, final from typing import Any, TypedDict, cast, final
@ -14,22 +13,12 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import SERVICE_TOGGLE, SERVICE_TURN_OFF, SERVICE_TURN_ON from homeassistant.const import SERVICE_TOGGLE, SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
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, VolDictType from homeassistant.helpers.typing import ConfigType, VolDictType
from homeassistant.util.hass_dict import HassKey from homeassistant.util.hass_dict import HassKey
from .const import ( # noqa: F401 from .const import (
_DEPRECATED_SUPPORT_DURATION,
_DEPRECATED_SUPPORT_TONES,
_DEPRECATED_SUPPORT_TURN_OFF,
_DEPRECATED_SUPPORT_TURN_ON,
_DEPRECATED_SUPPORT_VOLUME_SET,
ATTR_AVAILABLE_TONES, ATTR_AVAILABLE_TONES,
ATTR_DURATION, ATTR_DURATION,
ATTR_TONE, ATTR_TONE,
@ -208,13 +197,3 @@ class SirenEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
self._report_deprecated_supported_features_values(new_features) self._report_deprecated_supported_features_values(new_features)
return new_features return new_features
return 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())

View File

@ -1,16 +1,8 @@
"""Constants for the siren component.""" """Constants for the siren component."""
from enum import IntFlag from enum import IntFlag
from functools import partial
from typing import Final 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" DOMAIN: Final = "siren"
ATTR_TONE: Final = "tone" ATTR_TONE: Final = "tone"
@ -28,29 +20,3 @@ class SirenEntityFeature(IntFlag):
TONES = 4 TONES = 4
VOLUME_SET = 8 VOLUME_SET = 8
DURATION = 16 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())

View File

@ -1,6 +1,5 @@
"""The tests for the siren component.""" """The tests for the siren component."""
from types import ModuleType
from unittest.mock import MagicMock from unittest.mock import MagicMock
import pytest import pytest
@ -14,8 +13,6 @@ from homeassistant.components.siren import (
from homeassistant.components.siren.const import SirenEntityFeature from homeassistant.components.siren.const import SirenEntityFeature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from tests.common import help_test_all, import_and_test_deprecated_constant_enum
class MockSirenEntity(SirenEntity): class MockSirenEntity(SirenEntity):
"""Mock siren device to use in tests.""" """Mock siren device to use in tests."""
@ -111,26 +108,6 @@ async def test_missing_tones_dict(hass: HomeAssistant) -> None:
process_turn_on_params(siren, {"tone": 3}) 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: def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None:
"""Test deprecated supported features ints.""" """Test deprecated supported features ints."""