Skip to content

Commit f56b94c

Browse files
Remove deprecated constants from media_player (home-assistant#153366)
1 parent 3cf0358 commit f56b94c

File tree

3 files changed

+3
-261
lines changed

3 files changed

+3
-261
lines changed

homeassistant/components/media_player/__init__.py

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@
5555
from homeassistant.core import HomeAssistant, SupportsResponse
5656
from homeassistant.helpers import config_validation as cv
5757
from homeassistant.helpers.aiohttp_client import async_get_clientsession
58-
from homeassistant.helpers.deprecation import (
59-
DeprecatedConstantEnum,
60-
all_with_deprecated_constants,
61-
check_if_deprecated_constant,
62-
dir_with_deprecated_constants,
63-
)
6458
from homeassistant.helpers.entity import Entity, EntityDescription
6559
from homeassistant.helpers.entity_component import EntityComponent
6660
from homeassistant.helpers.network import get_url
@@ -75,26 +69,6 @@
7569
async_process_play_media_url,
7670
)
7771
from .const import ( # noqa: F401
78-
_DEPRECATED_MEDIA_CLASS_DIRECTORY,
79-
_DEPRECATED_SUPPORT_BROWSE_MEDIA,
80-
_DEPRECATED_SUPPORT_CLEAR_PLAYLIST,
81-
_DEPRECATED_SUPPORT_GROUPING,
82-
_DEPRECATED_SUPPORT_NEXT_TRACK,
83-
_DEPRECATED_SUPPORT_PAUSE,
84-
_DEPRECATED_SUPPORT_PLAY,
85-
_DEPRECATED_SUPPORT_PLAY_MEDIA,
86-
_DEPRECATED_SUPPORT_PREVIOUS_TRACK,
87-
_DEPRECATED_SUPPORT_REPEAT_SET,
88-
_DEPRECATED_SUPPORT_SEEK,
89-
_DEPRECATED_SUPPORT_SELECT_SOUND_MODE,
90-
_DEPRECATED_SUPPORT_SELECT_SOURCE,
91-
_DEPRECATED_SUPPORT_SHUFFLE_SET,
92-
_DEPRECATED_SUPPORT_STOP,
93-
_DEPRECATED_SUPPORT_TURN_OFF,
94-
_DEPRECATED_SUPPORT_TURN_ON,
95-
_DEPRECATED_SUPPORT_VOLUME_MUTE,
96-
_DEPRECATED_SUPPORT_VOLUME_SET,
97-
_DEPRECATED_SUPPORT_VOLUME_STEP,
9872
ATTR_APP_ID,
9973
ATTR_APP_NAME,
10074
ATTR_ENTITY_PICTURE_LOCAL,
@@ -188,17 +162,6 @@ class MediaPlayerDeviceClass(StrEnum):
188162
DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.Coerce(MediaPlayerDeviceClass))
189163

190164

191-
# DEVICE_CLASS* below are deprecated as of 2021.12
192-
# use the MediaPlayerDeviceClass enum instead.
193-
_DEPRECATED_DEVICE_CLASS_TV = DeprecatedConstantEnum(
194-
MediaPlayerDeviceClass.TV, "2025.10"
195-
)
196-
_DEPRECATED_DEVICE_CLASS_SPEAKER = DeprecatedConstantEnum(
197-
MediaPlayerDeviceClass.SPEAKER, "2025.10"
198-
)
199-
_DEPRECATED_DEVICE_CLASS_RECEIVER = DeprecatedConstantEnum(
200-
MediaPlayerDeviceClass.RECEIVER, "2025.10"
201-
)
202165
DEVICE_CLASSES = [cls.value for cls in MediaPlayerDeviceClass]
203166

204167

@@ -1196,6 +1159,7 @@ async def async_internal_search_media(
11961159
media_content_id: str | None = None,
11971160
media_filter_classes: list[MediaClass] | None = None,
11981161
) -> SearchMedia:
1162+
"""Search for media."""
11991163
return await self.async_search_media(
12001164
query=SearchMediaQuery(
12011165
search_query=search_query,
@@ -1510,13 +1474,3 @@ async def async_fetch_image(
15101474
logger.warning("Error retrieving proxied image from %s", url)
15111475

15121476
return content, content_type
1513-
1514-
1515-
# As we import deprecated constants from the const module, we need to add these two functions
1516-
# otherwise this module will be logged for using deprecated constants and not the custom component
1517-
# These can be removed if no deprecated constant are in this module anymore
1518-
__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals())
1519-
__dir__ = ft.partial(
1520-
dir_with_deprecated_constants, module_globals_keys=[*globals().keys()]
1521-
)
1522-
__all__ = all_with_deprecated_constants(globals())
Lines changed: 1 addition & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
"""Provides the constants needed for component."""
22

33
from enum import IntFlag, StrEnum
4-
from functools import partial
54

6-
from homeassistant.helpers.deprecation import (
7-
DeprecatedConstantEnum,
8-
EnumWithDeprecatedMembers,
9-
all_with_deprecated_constants,
10-
check_if_deprecated_constant,
11-
dir_with_deprecated_constants,
12-
)
5+
from homeassistant.helpers.deprecation import EnumWithDeprecatedMembers
136

147
# How long our auth signature on the content should be valid for
158
CONTENT_AUTH_EXPIRY_TIME = 3600 * 24
@@ -94,38 +87,6 @@ class MediaClass(StrEnum):
9487
VIDEO = "video"
9588

9689

97-
# These MEDIA_CLASS_* constants are deprecated as of Home Assistant 2022.10.
98-
# Please use the MediaClass enum instead.
99-
_DEPRECATED_MEDIA_CLASS_ALBUM = DeprecatedConstantEnum(MediaClass.ALBUM, "2025.10")
100-
_DEPRECATED_MEDIA_CLASS_APP = DeprecatedConstantEnum(MediaClass.APP, "2025.10")
101-
_DEPRECATED_MEDIA_CLASS_ARTIST = DeprecatedConstantEnum(MediaClass.ARTIST, "2025.10")
102-
_DEPRECATED_MEDIA_CLASS_CHANNEL = DeprecatedConstantEnum(MediaClass.CHANNEL, "2025.10")
103-
_DEPRECATED_MEDIA_CLASS_COMPOSER = DeprecatedConstantEnum(
104-
MediaClass.COMPOSER, "2025.10"
105-
)
106-
_DEPRECATED_MEDIA_CLASS_CONTRIBUTING_ARTIST = DeprecatedConstantEnum(
107-
MediaClass.CONTRIBUTING_ARTIST, "2025.10"
108-
)
109-
_DEPRECATED_MEDIA_CLASS_DIRECTORY = DeprecatedConstantEnum(
110-
MediaClass.DIRECTORY, "2025.10"
111-
)
112-
_DEPRECATED_MEDIA_CLASS_EPISODE = DeprecatedConstantEnum(MediaClass.EPISODE, "2025.10")
113-
_DEPRECATED_MEDIA_CLASS_GAME = DeprecatedConstantEnum(MediaClass.GAME, "2025.10")
114-
_DEPRECATED_MEDIA_CLASS_GENRE = DeprecatedConstantEnum(MediaClass.GENRE, "2025.10")
115-
_DEPRECATED_MEDIA_CLASS_IMAGE = DeprecatedConstantEnum(MediaClass.IMAGE, "2025.10")
116-
_DEPRECATED_MEDIA_CLASS_MOVIE = DeprecatedConstantEnum(MediaClass.MOVIE, "2025.10")
117-
_DEPRECATED_MEDIA_CLASS_MUSIC = DeprecatedConstantEnum(MediaClass.MUSIC, "2025.10")
118-
_DEPRECATED_MEDIA_CLASS_PLAYLIST = DeprecatedConstantEnum(
119-
MediaClass.PLAYLIST, "2025.10"
120-
)
121-
_DEPRECATED_MEDIA_CLASS_PODCAST = DeprecatedConstantEnum(MediaClass.PODCAST, "2025.10")
122-
_DEPRECATED_MEDIA_CLASS_SEASON = DeprecatedConstantEnum(MediaClass.SEASON, "2025.10")
123-
_DEPRECATED_MEDIA_CLASS_TRACK = DeprecatedConstantEnum(MediaClass.TRACK, "2025.10")
124-
_DEPRECATED_MEDIA_CLASS_TV_SHOW = DeprecatedConstantEnum(MediaClass.TV_SHOW, "2025.10")
125-
_DEPRECATED_MEDIA_CLASS_URL = DeprecatedConstantEnum(MediaClass.URL, "2025.10")
126-
_DEPRECATED_MEDIA_CLASS_VIDEO = DeprecatedConstantEnum(MediaClass.VIDEO, "2025.10")
127-
128-
12990
class MediaType(StrEnum):
13091
"""Media type for media player entities."""
13192

@@ -152,33 +113,6 @@ class MediaType(StrEnum):
152113
VIDEO = "video"
153114

154115

155-
# These MEDIA_TYPE_* constants are deprecated as of Home Assistant 2022.10.
156-
# Please use the MediaType enum instead.
157-
_DEPRECATED_MEDIA_TYPE_ALBUM = DeprecatedConstantEnum(MediaType.ALBUM, "2025.10")
158-
_DEPRECATED_MEDIA_TYPE_APP = DeprecatedConstantEnum(MediaType.APP, "2025.10")
159-
_DEPRECATED_MEDIA_TYPE_APPS = DeprecatedConstantEnum(MediaType.APPS, "2025.10")
160-
_DEPRECATED_MEDIA_TYPE_ARTIST = DeprecatedConstantEnum(MediaType.ARTIST, "2025.10")
161-
_DEPRECATED_MEDIA_TYPE_CHANNEL = DeprecatedConstantEnum(MediaType.CHANNEL, "2025.10")
162-
_DEPRECATED_MEDIA_TYPE_CHANNELS = DeprecatedConstantEnum(MediaType.CHANNELS, "2025.10")
163-
_DEPRECATED_MEDIA_TYPE_COMPOSER = DeprecatedConstantEnum(MediaType.COMPOSER, "2025.10")
164-
_DEPRECATED_MEDIA_TYPE_CONTRIBUTING_ARTIST = DeprecatedConstantEnum(
165-
MediaType.CONTRIBUTING_ARTIST, "2025.10"
166-
)
167-
_DEPRECATED_MEDIA_TYPE_EPISODE = DeprecatedConstantEnum(MediaType.EPISODE, "2025.10")
168-
_DEPRECATED_MEDIA_TYPE_GAME = DeprecatedConstantEnum(MediaType.GAME, "2025.10")
169-
_DEPRECATED_MEDIA_TYPE_GENRE = DeprecatedConstantEnum(MediaType.GENRE, "2025.10")
170-
_DEPRECATED_MEDIA_TYPE_IMAGE = DeprecatedConstantEnum(MediaType.IMAGE, "2025.10")
171-
_DEPRECATED_MEDIA_TYPE_MOVIE = DeprecatedConstantEnum(MediaType.MOVIE, "2025.10")
172-
_DEPRECATED_MEDIA_TYPE_MUSIC = DeprecatedConstantEnum(MediaType.MUSIC, "2025.10")
173-
_DEPRECATED_MEDIA_TYPE_PLAYLIST = DeprecatedConstantEnum(MediaType.PLAYLIST, "2025.10")
174-
_DEPRECATED_MEDIA_TYPE_PODCAST = DeprecatedConstantEnum(MediaType.PODCAST, "2025.10")
175-
_DEPRECATED_MEDIA_TYPE_SEASON = DeprecatedConstantEnum(MediaType.SEASON, "2025.10")
176-
_DEPRECATED_MEDIA_TYPE_TRACK = DeprecatedConstantEnum(MediaType.TRACK, "2025.10")
177-
_DEPRECATED_MEDIA_TYPE_TVSHOW = DeprecatedConstantEnum(MediaType.TVSHOW, "2025.10")
178-
_DEPRECATED_MEDIA_TYPE_URL = DeprecatedConstantEnum(MediaType.URL, "2025.10")
179-
_DEPRECATED_MEDIA_TYPE_VIDEO = DeprecatedConstantEnum(MediaType.VIDEO, "2025.10")
180-
181-
182116
SERVICE_CLEAR_PLAYLIST = "clear_playlist"
183117
SERVICE_JOIN = "join"
184118
SERVICE_PLAY_MEDIA = "play_media"
@@ -197,11 +131,6 @@ class RepeatMode(StrEnum):
197131
ONE = "one"
198132

199133

200-
# These REPEAT_MODE_* constants are deprecated as of Home Assistant 2022.10.
201-
# Please use the RepeatMode enum instead.
202-
_DEPRECATED_REPEAT_MODE_ALL = DeprecatedConstantEnum(RepeatMode.ALL, "2025.10")
203-
_DEPRECATED_REPEAT_MODE_OFF = DeprecatedConstantEnum(RepeatMode.OFF, "2025.10")
204-
_DEPRECATED_REPEAT_MODE_ONE = DeprecatedConstantEnum(RepeatMode.ONE, "2025.10")
205134
REPEAT_MODES = [cls.value for cls in RepeatMode]
206135

207136

@@ -231,71 +160,3 @@ class MediaPlayerEntityFeature(IntFlag):
231160
MEDIA_ANNOUNCE = 1048576
232161
MEDIA_ENQUEUE = 2097152
233162
SEARCH_MEDIA = 4194304
234-
235-
236-
# These SUPPORT_* constants are deprecated as of Home Assistant 2022.5.
237-
# Please use the MediaPlayerEntityFeature enum instead.
238-
_DEPRECATED_SUPPORT_PAUSE = DeprecatedConstantEnum(
239-
MediaPlayerEntityFeature.PAUSE, "2025.10"
240-
)
241-
_DEPRECATED_SUPPORT_SEEK = DeprecatedConstantEnum(
242-
MediaPlayerEntityFeature.SEEK, "2025.10"
243-
)
244-
_DEPRECATED_SUPPORT_VOLUME_SET = DeprecatedConstantEnum(
245-
MediaPlayerEntityFeature.VOLUME_SET, "2025.10"
246-
)
247-
_DEPRECATED_SUPPORT_VOLUME_MUTE = DeprecatedConstantEnum(
248-
MediaPlayerEntityFeature.VOLUME_MUTE, "2025.10"
249-
)
250-
_DEPRECATED_SUPPORT_PREVIOUS_TRACK = DeprecatedConstantEnum(
251-
MediaPlayerEntityFeature.PREVIOUS_TRACK, "2025.10"
252-
)
253-
_DEPRECATED_SUPPORT_NEXT_TRACK = DeprecatedConstantEnum(
254-
MediaPlayerEntityFeature.NEXT_TRACK, "2025.10"
255-
)
256-
_DEPRECATED_SUPPORT_TURN_ON = DeprecatedConstantEnum(
257-
MediaPlayerEntityFeature.TURN_ON, "2025.10"
258-
)
259-
_DEPRECATED_SUPPORT_TURN_OFF = DeprecatedConstantEnum(
260-
MediaPlayerEntityFeature.TURN_OFF, "2025.10"
261-
)
262-
_DEPRECATED_SUPPORT_PLAY_MEDIA = DeprecatedConstantEnum(
263-
MediaPlayerEntityFeature.PLAY_MEDIA, "2025.10"
264-
)
265-
_DEPRECATED_SUPPORT_VOLUME_STEP = DeprecatedConstantEnum(
266-
MediaPlayerEntityFeature.VOLUME_STEP, "2025.10"
267-
)
268-
_DEPRECATED_SUPPORT_SELECT_SOURCE = DeprecatedConstantEnum(
269-
MediaPlayerEntityFeature.SELECT_SOURCE, "2025.10"
270-
)
271-
_DEPRECATED_SUPPORT_STOP = DeprecatedConstantEnum(
272-
MediaPlayerEntityFeature.STOP, "2025.10"
273-
)
274-
_DEPRECATED_SUPPORT_CLEAR_PLAYLIST = DeprecatedConstantEnum(
275-
MediaPlayerEntityFeature.CLEAR_PLAYLIST, "2025.10"
276-
)
277-
_DEPRECATED_SUPPORT_PLAY = DeprecatedConstantEnum(
278-
MediaPlayerEntityFeature.PLAY, "2025.10"
279-
)
280-
_DEPRECATED_SUPPORT_SHUFFLE_SET = DeprecatedConstantEnum(
281-
MediaPlayerEntityFeature.SHUFFLE_SET, "2025.10"
282-
)
283-
_DEPRECATED_SUPPORT_SELECT_SOUND_MODE = DeprecatedConstantEnum(
284-
MediaPlayerEntityFeature.SELECT_SOUND_MODE, "2025.10"
285-
)
286-
_DEPRECATED_SUPPORT_BROWSE_MEDIA = DeprecatedConstantEnum(
287-
MediaPlayerEntityFeature.BROWSE_MEDIA, "2025.10"
288-
)
289-
_DEPRECATED_SUPPORT_REPEAT_SET = DeprecatedConstantEnum(
290-
MediaPlayerEntityFeature.REPEAT_SET, "2025.10"
291-
)
292-
_DEPRECATED_SUPPORT_GROUPING = DeprecatedConstantEnum(
293-
MediaPlayerEntityFeature.GROUPING, "2025.10"
294-
)
295-
296-
# These can be removed if no deprecated constant are in this module anymore
297-
__getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
298-
__dir__ = partial(
299-
dir_with_deprecated_constants, module_globals_keys=[*globals().keys()]
300-
)
301-
__all__ = all_with_deprecated_constants(globals())

tests/components/media_player/test_init.py

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""Test the base functions of the media player."""
22

3-
from enum import Enum
43
from http import HTTPStatus
5-
from types import ModuleType
64
from unittest.mock import patch
75

86
import pytest
@@ -18,7 +16,6 @@
1816
MediaClass,
1917
MediaPlayerEnqueue,
2018
MediaPlayerEntity,
21-
MediaPlayerEntityFeature,
2219
SearchMedia,
2320
SearchMediaQuery,
2421
)
@@ -31,11 +28,7 @@
3128
from homeassistant.core import HomeAssistant
3229
from homeassistant.setup import async_setup_component
3330

34-
from tests.common import (
35-
MockEntityPlatform,
36-
help_test_all,
37-
import_and_test_deprecated_constant_enum,
38-
)
31+
from tests.common import MockEntityPlatform
3932
from tests.test_util.aiohttp import AiohttpClientMocker
4033
from tests.typing import ClientSessionGenerator, WebSocketGenerator
4134

@@ -46,72 +39,6 @@ async def setup_homeassistant(hass: HomeAssistant):
4639
await async_setup_component(hass, "homeassistant", {})
4740

4841

49-
def _create_tuples(enum: type[Enum], constant_prefix: str) -> list[tuple[Enum, str]]:
50-
return [
51-
(enum_field, constant_prefix)
52-
for enum_field in enum
53-
if enum_field
54-
not in [
55-
MediaPlayerEntityFeature.MEDIA_ANNOUNCE,
56-
MediaPlayerEntityFeature.MEDIA_ENQUEUE,
57-
MediaPlayerEntityFeature.SEARCH_MEDIA,
58-
]
59-
]
60-
61-
62-
@pytest.mark.parametrize(
63-
"module",
64-
[media_player, media_player.const],
65-
)
66-
def test_all(module: ModuleType) -> None:
67-
"""Test module.__all__ is correctly set."""
68-
help_test_all(module)
69-
70-
71-
@pytest.mark.parametrize(
72-
("enum", "constant_prefix"),
73-
_create_tuples(media_player.MediaPlayerEntityFeature, "SUPPORT_")
74-
+ _create_tuples(media_player.MediaPlayerDeviceClass, "DEVICE_CLASS_"),
75-
)
76-
@pytest.mark.parametrize(
77-
"module",
78-
[media_player],
79-
)
80-
def test_deprecated_constants(
81-
caplog: pytest.LogCaptureFixture,
82-
enum: Enum,
83-
constant_prefix: str,
84-
module: ModuleType,
85-
) -> None:
86-
"""Test deprecated constants."""
87-
import_and_test_deprecated_constant_enum(
88-
caplog, module, enum, constant_prefix, "2025.10"
89-
)
90-
91-
92-
@pytest.mark.parametrize(
93-
("enum", "constant_prefix"),
94-
_create_tuples(media_player.MediaClass, "MEDIA_CLASS_")
95-
+ _create_tuples(media_player.MediaPlayerEntityFeature, "SUPPORT_")
96-
+ _create_tuples(media_player.MediaType, "MEDIA_TYPE_")
97-
+ _create_tuples(media_player.RepeatMode, "REPEAT_MODE_"),
98-
)
99-
@pytest.mark.parametrize(
100-
"module",
101-
[media_player.const],
102-
)
103-
def test_deprecated_constants_const(
104-
caplog: pytest.LogCaptureFixture,
105-
enum: Enum,
106-
constant_prefix: str,
107-
module: ModuleType,
108-
) -> None:
109-
"""Test deprecated constants."""
110-
import_and_test_deprecated_constant_enum(
111-
caplog, module, enum, constant_prefix, "2025.10"
112-
)
113-
114-
11542
@pytest.mark.parametrize(
11643
"property_suffix",
11744
[

0 commit comments

Comments
 (0)