From 70835b1392eaa270e43debdaa6d169dab5958965 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Mon, 21 Oct 2024 01:08:15 +0200 Subject: [PATCH] replace deprecated media class constants --- custom_components/mass/media_browser.py | 41 ++++++++++--------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/custom_components/mass/media_browser.py b/custom_components/mass/media_browser.py index e6c90368..7d677697 100644 --- a/custom_components/mass/media_browser.py +++ b/custom_components/mass/media_browser.py @@ -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 @@ -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" @@ -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], @@ -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], @@ -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 @@ -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], @@ -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 @@ -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], @@ -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 ], @@ -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], @@ -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],