Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions homeassistant/components/roku/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
SUPPORT_VOLUME_STEP,
)
from homeassistant.components.media_player.errors import BrowseError
from homeassistant.components.stream.const import FORMAT_CONTENT_TYPE, HLS_PROVIDER
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_NAME,
Expand Down Expand Up @@ -79,6 +80,13 @@
ATTR_MEDIA_TYPE: "MediaType",
}

PLAY_MEDIA_SUPPORTED_TYPES = (
MEDIA_TYPE_APP,
MEDIA_TYPE_CHANNEL,
MEDIA_TYPE_URL,
FORMAT_CONTENT_TYPE[HLS_PROVIDER],
)

ATTRS_TO_PLAY_VIDEO_PARAMS = {
ATTR_NAME: "videoName",
ATTR_FORMAT: "videoFormat",
Expand Down Expand Up @@ -375,9 +383,9 @@ async def async_play_media(self, media_type: str, media_id: str, **kwargs) -> No
"""Tune to channel."""
extra: dict[str, Any] = kwargs.get(ATTR_MEDIA_EXTRA) or {}

if media_type not in (MEDIA_TYPE_APP, MEDIA_TYPE_CHANNEL, MEDIA_TYPE_URL):
if media_type not in PLAY_MEDIA_SUPPORTED_TYPES:
_LOGGER.error(
"Invalid media type %s. Only %s, %s and %s are supported",
"Invalid media type %s. Only %s, %s, %s, and camera HLS streams are supported",
media_type,
MEDIA_TYPE_APP,
MEDIA_TYPE_CHANNEL,
Expand All @@ -402,6 +410,12 @@ async def async_play_media(self, media_type: str, media_id: str, **kwargs) -> No
if attr in extra
}

await self.coordinator.roku.play_video(media_id, params)
elif media_type == FORMAT_CONTENT_TYPE[HLS_PROVIDER]:
params = {
"MediaType": "hls",
}

await self.coordinator.roku.play_video(media_id, params)

await self.coordinator.async_request_refresh()
Expand Down
20 changes: 20 additions & 0 deletions tests/components/roku/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
DOMAIN,
SERVICE_SEARCH,
)
from homeassistant.components.stream.const import FORMAT_CONTENT_TYPE, HLS_PROVIDER
from homeassistant.components.websocket_api.const import TYPE_RESULT
from homeassistant.config import async_process_ha_core_config
from homeassistant.const import (
Expand Down Expand Up @@ -508,6 +509,25 @@ async def test_services(
},
)

with patch("homeassistant.components.roku.coordinator.Roku.play_video") as pv_mock:
await hass.services.async_call(
MP_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: MAIN_ENTITY_ID,
ATTR_MEDIA_CONTENT_TYPE: FORMAT_CONTENT_TYPE[HLS_PROVIDER],
ATTR_MEDIA_CONTENT_ID: "https://awesome.tld/api/hls/api_token/master_playlist.m3u8",
},
blocking=True,
)

pv_mock.assert_called_once_with(
"https://awesome.tld/api/hls/api_token/master_playlist.m3u8",
{
"MediaType": "hls",
},
)

with patch("homeassistant.components.roku.coordinator.Roku.remote") as remote_mock:
await hass.services.async_call(
MP_DOMAIN,
Expand Down