Skip to content

Commit

Permalink
replace deprecated media class constants
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Oct 20, 2024
1 parent a1c163a commit 70835b1
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions custom_components/mass/media_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@

from homeassistant.components import media_source
from homeassistant.components.media_player import BrowseError, BrowseMedia
from homeassistant.components.media_player.const import (
MEDIA_CLASS_ALBUM,
MEDIA_CLASS_ARTIST,
MEDIA_CLASS_DIRECTORY,
MEDIA_CLASS_MUSIC,
MEDIA_CLASS_PLAYLIST,
MEDIA_CLASS_TRACK,
MediaClass,
MediaType,
)
from homeassistant.components.media_player.const import MediaClass, MediaType
from homeassistant.core import HomeAssistant, callback
from music_assistant.common.models.media_items import MediaItemType

Expand Down Expand Up @@ -51,11 +42,11 @@
}

LIBRARY_MEDIA_CLASS_MAP = {
LIBRARY_ARTISTS: MEDIA_CLASS_ARTIST,
LIBRARY_ALBUMS: MEDIA_CLASS_ALBUM,
LIBRARY_TRACKS: MEDIA_CLASS_TRACK,
LIBRARY_PLAYLISTS: MEDIA_CLASS_PLAYLIST,
LIBRARY_RADIO: MEDIA_CLASS_MUSIC, # radio is not accepted by HA
LIBRARY_ARTISTS: MediaClass.ARTIST,
LIBRARY_ALBUMS: MediaClass.ALBUM,
LIBRARY_TRACKS: MediaClass.TRACK,
LIBRARY_PLAYLISTS: MediaClass.PLAYLIST,
LIBRARY_RADIO: MediaClass.MUSIC, # radio is not accepted by HA
}

MEDIA_CONTENT_TYPE_FLAC = "audio/flac"
Expand Down Expand Up @@ -119,7 +110,7 @@ async def build_main_listing(hass: HomeAssistant):
)
for library, media_class in LIBRARY_MEDIA_CLASS_MAP.items():
child_source = BrowseMedia(
media_class=MEDIA_CLASS_DIRECTORY,
media_class=MediaClass.DIRECTORY,
media_content_id=library,
media_content_type=DOMAIN,
title=LIBRARY_TITLE_MAP[library],
Expand Down Expand Up @@ -147,7 +138,7 @@ async def build_playlists_listing(mass: MusicAssistantClient):
"""Build Playlists browse listing."""
media_class = LIBRARY_MEDIA_CLASS_MAP[LIBRARY_PLAYLISTS]
return BrowseMedia(
media_class=MEDIA_CLASS_DIRECTORY,
media_class=MediaClass.DIRECTORY,
media_content_id=LIBRARY_PLAYLISTS,
media_content_type=MediaType.PLAYLIST,
title=LIBRARY_TITLE_MAP[LIBRARY_PLAYLISTS],
Expand All @@ -172,13 +163,13 @@ async def build_playlist_items_listing(mass: MusicAssistantClient, identifier: s
playlist = await mass.music.get_item_by_uri(identifier)

return BrowseMedia(
media_class=MEDIA_CLASS_PLAYLIST,
media_class=MediaClass.PLAYLIST,
media_content_id=playlist.uri,
media_content_type=MediaType.PLAYLIST,
title=playlist.name,
can_play=True,
can_expand=True,
children_media_class=MEDIA_CLASS_TRACK,
children_media_class=MediaClass.TRACK,
children=[
build_item(mass, item, can_expand=False)
# we only grab the first page here because the
Expand All @@ -196,7 +187,7 @@ async def build_artists_listing(mass: MusicAssistantClient):
media_class = LIBRARY_MEDIA_CLASS_MAP[LIBRARY_ARTISTS]

return BrowseMedia(
media_class=MEDIA_CLASS_DIRECTORY,
media_class=MediaClass.DIRECTORY,
media_content_id=LIBRARY_ARTISTS,
media_content_type=MediaType.ARTIST,
title=LIBRARY_TITLE_MAP[LIBRARY_ARTISTS],
Expand Down Expand Up @@ -228,7 +219,7 @@ async def build_artist_items_listing(mass: MusicAssistantClient, identifier: str
title=artist.name,
can_play=True,
can_expand=True,
children_media_class=MEDIA_CLASS_ALBUM,
children_media_class=MediaClass.ALBUM,
children=[
build_item(mass, album, can_expand=True)
for album in albums
Expand All @@ -242,7 +233,7 @@ async def build_albums_listing(mass: MusicAssistantClient):
media_class = LIBRARY_MEDIA_CLASS_MAP[LIBRARY_ALBUMS]

return BrowseMedia(
media_class=MEDIA_CLASS_DIRECTORY,
media_class=MediaClass.DIRECTORY,
media_content_id=LIBRARY_ALBUMS,
media_content_type=MediaType.ALBUM,
title=LIBRARY_TITLE_MAP[LIBRARY_ALBUMS],
Expand Down Expand Up @@ -274,7 +265,7 @@ async def build_album_items_listing(mass: MusicAssistantClient, identifier: str)
title=album.name,
can_play=True,
can_expand=True,
children_media_class=MEDIA_CLASS_TRACK,
children_media_class=MediaClass.TRACK,
children=[
build_item(mass, track, False) for track in tracks if track.available
],
Expand All @@ -286,7 +277,7 @@ async def build_tracks_listing(mass: MusicAssistantClient):
media_class = LIBRARY_MEDIA_CLASS_MAP[LIBRARY_TRACKS]

return BrowseMedia(
media_class=MEDIA_CLASS_DIRECTORY,
media_class=MediaClass.DIRECTORY,
media_content_id=LIBRARY_ALBUMS,
media_content_type=MediaType.TRACK,
title=LIBRARY_TITLE_MAP[LIBRARY_TRACKS],
Expand All @@ -310,7 +301,7 @@ async def build_radio_listing(mass: MusicAssistantClient):
"""Build Radio browse listing."""
media_class = LIBRARY_MEDIA_CLASS_MAP[LIBRARY_RADIO]
return BrowseMedia(
media_class=MEDIA_CLASS_DIRECTORY,
media_class=MediaClass.DIRECTORY,
media_content_id=LIBRARY_ALBUMS,
media_content_type=DOMAIN,
title=LIBRARY_TITLE_MAP[LIBRARY_RADIO],
Expand Down

0 comments on commit 70835b1

Please sign in to comment.