Add media source support to openhome (#67566)
This commit is contained in:
parent
314175135f
commit
a109889f13
1 changed files with 26 additions and 1 deletions
|
@ -10,9 +10,14 @@ from async_upnp_client.client import UpnpError
|
||||||
from openhomedevice.device import Device
|
from openhomedevice.device import Device
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.components import media_source
|
||||||
from homeassistant.components.media_player import MediaPlayerEntity
|
from homeassistant.components.media_player import MediaPlayerEntity
|
||||||
|
from homeassistant.components.media_player.browse_media import (
|
||||||
|
async_process_play_media_url,
|
||||||
|
)
|
||||||
from homeassistant.components.media_player.const import (
|
from homeassistant.components.media_player.const import (
|
||||||
MEDIA_TYPE_MUSIC,
|
MEDIA_TYPE_MUSIC,
|
||||||
|
SUPPORT_BROWSE_MEDIA,
|
||||||
SUPPORT_NEXT_TRACK,
|
SUPPORT_NEXT_TRACK,
|
||||||
SUPPORT_PAUSE,
|
SUPPORT_PAUSE,
|
||||||
SUPPORT_PLAY,
|
SUPPORT_PLAY,
|
||||||
|
@ -149,7 +154,10 @@ class OpenhomeDevice(MediaPlayerEntity):
|
||||||
|
|
||||||
if self._source["type"] == "Radio":
|
if self._source["type"] == "Radio":
|
||||||
self._supported_features |= (
|
self._supported_features |= (
|
||||||
SUPPORT_STOP | SUPPORT_PLAY | SUPPORT_PLAY_MEDIA
|
SUPPORT_STOP
|
||||||
|
| SUPPORT_PLAY
|
||||||
|
| SUPPORT_PLAY_MEDIA
|
||||||
|
| SUPPORT_BROWSE_MEDIA
|
||||||
)
|
)
|
||||||
if self._source["type"] in ("Playlist", "Spotify"):
|
if self._source["type"] in ("Playlist", "Spotify"):
|
||||||
self._supported_features |= (
|
self._supported_features |= (
|
||||||
|
@ -158,6 +166,7 @@ class OpenhomeDevice(MediaPlayerEntity):
|
||||||
| SUPPORT_PAUSE
|
| SUPPORT_PAUSE
|
||||||
| SUPPORT_PLAY
|
| SUPPORT_PLAY
|
||||||
| SUPPORT_PLAY_MEDIA
|
| SUPPORT_PLAY_MEDIA
|
||||||
|
| SUPPORT_BROWSE_MEDIA
|
||||||
)
|
)
|
||||||
|
|
||||||
if self._in_standby:
|
if self._in_standby:
|
||||||
|
@ -189,6 +198,11 @@ class OpenhomeDevice(MediaPlayerEntity):
|
||||||
@catch_request_errors()
|
@catch_request_errors()
|
||||||
async def async_play_media(self, media_type, media_id, **kwargs):
|
async def async_play_media(self, media_type, media_id, **kwargs):
|
||||||
"""Send the play_media command to the media player."""
|
"""Send the play_media command to the media player."""
|
||||||
|
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_MUSIC:
|
if media_type != MEDIA_TYPE_MUSIC:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Invalid media type %s. Only %s is supported",
|
"Invalid media type %s. Only %s is supported",
|
||||||
|
@ -196,6 +210,9 @@ class OpenhomeDevice(MediaPlayerEntity):
|
||||||
MEDIA_TYPE_MUSIC,
|
MEDIA_TYPE_MUSIC,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
media_id = async_process_play_media_url(self.hass, media_id)
|
||||||
|
|
||||||
track_details = {"title": "Home Assistant", "uri": media_id}
|
track_details = {"title": "Home Assistant", "uri": media_id}
|
||||||
await self._device.play_media(track_details)
|
await self._device.play_media(track_details)
|
||||||
|
|
||||||
|
@ -320,3 +337,11 @@ class OpenhomeDevice(MediaPlayerEntity):
|
||||||
async def async_mute_volume(self, mute):
|
async def async_mute_volume(self, mute):
|
||||||
"""Mute (true) or unmute (false) media player."""
|
"""Mute (true) or unmute (false) media player."""
|
||||||
await self._device.set_mute(mute)
|
await self._device.set_mute(mute)
|
||||||
|
|
||||||
|
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…
Add table
Add a link
Reference in a new issue