Fix basic browse_media support in forked-daapd (#77595)

pull/77656/head
uvjustin 2022-09-01 16:46:43 +08:00 committed by GitHub
parent f9a3757d71
commit 3d64cf7304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 9 deletions

View File

@ -1,6 +1,17 @@
"""Const for forked-daapd."""
from homeassistant.components.media_player import MediaPlayerEntityFeature
CAN_PLAY_TYPE = {
"audio/mp4",
"audio/aac",
"audio/mpeg",
"audio/flac",
"audio/ogg",
"audio/x-ms-wma",
"audio/aiff",
"audio/wav",
}
CALLBACK_TIMEOUT = 8 # max time between command and callback from forked-daapd server
CONF_LIBRESPOT_JAVA_PORT = "librespot_java_port"
CONF_MAX_PLAYLISTS = "max_playlists"

View File

@ -1,4 +1,6 @@
"""This library brings support for forked_daapd to Home Assistant."""
from __future__ import annotations
import asyncio
from collections import defaultdict
import logging
@ -8,7 +10,7 @@ from pyforked_daapd import ForkedDaapdAPI
from pylibrespot_java import LibrespotJavaAPI
from homeassistant.components import media_source
from homeassistant.components.media_player import MediaPlayerEntity
from homeassistant.components.media_player import BrowseMedia, MediaPlayerEntity
from homeassistant.components.media_player.browse_media import (
async_process_play_media_url,
)
@ -35,6 +37,7 @@ from homeassistant.util.dt import utcnow
from .const import (
CALLBACK_TIMEOUT,
CAN_PLAY_TYPE,
CONF_LIBRESPOT_JAVA_PORT,
CONF_MAX_PLAYLISTS,
CONF_TTS_PAUSE_TIME,
@ -769,6 +772,18 @@ class ForkedDaapdMaster(MediaPlayerEntity):
)()
_LOGGER.warning("No pipe control available for %s", pipe_name)
async def async_browse_media(
self,
media_content_type: str | None = None,
media_content_id: str | None = None,
) -> BrowseMedia:
"""Implement the websocket media browsing helper."""
return await media_source.async_browse_media(
self.hass,
media_content_id,
content_filter=lambda bm: bm.media_content_type in CAN_PLAY_TYPE,
)
class ForkedDaapdUpdater:
"""Manage updates for the forked-daapd device."""
@ -885,11 +900,3 @@ class ForkedDaapdUpdater:
self._api,
outputs_to_add,
)
async def async_browse_media(self, media_content_type=None, media_content_id=None):
"""Implement the websocket media browsing helper."""
return await media_source.async_browse_media(
self.hass,
media_content_id,
content_filter=lambda item: item.media_content_type.startswith("audio/"),
)