mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add media source support to mpd (#67565)
This commit is contained in:
parent
cf1a21eb6e
commit
84c460ce78
@ -11,13 +11,18 @@ import mpd
|
||||
from mpd.asyncio import MPDClient
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import media_source
|
||||
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity
|
||||
from homeassistant.components.media_player.browse_media import (
|
||||
async_process_play_media_url,
|
||||
)
|
||||
from homeassistant.components.media_player.const import (
|
||||
MEDIA_TYPE_MUSIC,
|
||||
MEDIA_TYPE_PLAYLIST,
|
||||
REPEAT_MODE_ALL,
|
||||
REPEAT_MODE_OFF,
|
||||
REPEAT_MODE_ONE,
|
||||
SUPPORT_BROWSE_MEDIA,
|
||||
SUPPORT_CLEAR_PLAYLIST,
|
||||
SUPPORT_NEXT_TRACK,
|
||||
SUPPORT_PAUSE,
|
||||
@ -71,6 +76,7 @@ SUPPORT_MPD = (
|
||||
| SUPPORT_STOP
|
||||
| SUPPORT_TURN_OFF
|
||||
| SUPPORT_TURN_ON
|
||||
| SUPPORT_BROWSE_MEDIA
|
||||
)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
@ -445,8 +451,13 @@ class MpdDevice(MediaPlayerEntity):
|
||||
|
||||
async def async_play_media(self, media_type, media_id, **kwargs):
|
||||
"""Send the media player the command for playing a playlist."""
|
||||
_LOGGER.debug("Playing playlist: %s", media_id)
|
||||
if media_source.is_media_source_id(media_id):
|
||||
media_type = MEDIA_TYPE_MUSIC
|
||||
play_item = await media_source.async_resolve_media(self.hass, media_id)
|
||||
media_id = play_item.url
|
||||
|
||||
if media_type == MEDIA_TYPE_PLAYLIST:
|
||||
_LOGGER.debug("Playing playlist: %s", media_id)
|
||||
if media_id in self._playlists:
|
||||
self._currentplaylist = media_id
|
||||
else:
|
||||
@ -456,6 +467,8 @@ class MpdDevice(MediaPlayerEntity):
|
||||
await self._client.load(media_id)
|
||||
await self._client.play()
|
||||
else:
|
||||
media_id = async_process_play_media_url(self.hass, media_id)
|
||||
|
||||
await self._client.clear()
|
||||
self._currentplaylist = None
|
||||
await self._client.add(media_id)
|
||||
@ -507,3 +520,11 @@ class MpdDevice(MediaPlayerEntity):
|
||||
async def async_media_seek(self, position):
|
||||
"""Send seek command."""
|
||||
await self._client.seekcur(position)
|
||||
|
||||
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/"),
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user