Add media browser support to roku (#39652)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
1 parent
405311e89f
commit
13a6aaa6ff
3 files changed
+245
-3
No files matched your search
@@ -17,9 +17,12 @@ from homeassistant.components.media_player.const import (
|
||||
ATTR_MEDIA_VOLUME_MUTED,
|
||||
DOMAIN as MP_DOMAIN,
|
||||
MEDIA_TYPE_APP,
|
||||
MEDIA_TYPE_APPS,
|
||||
MEDIA_TYPE_CHANNEL,
|
||||
MEDIA_TYPE_CHANNELS,
|
||||
SERVICE_PLAY_MEDIA,
|
||||
SERVICE_SELECT_SOURCE,
|
||||
SUPPORT_BROWSE_MEDIA,
|
||||
SUPPORT_NEXT_TRACK,
|
||||
SUPPORT_PAUSE,
|
||||
SUPPORT_PLAY,
|
||||
@@ -32,6 +35,7 @@ from homeassistant.components.media_player.const import (
|
||||
SUPPORT_VOLUME_STEP,
|
||||
)
|
||||
from homeassistant.components.roku.const import ATTR_KEYWORD, DOMAIN, SERVICE_SEARCH
|
||||
from homeassistant.components.websocket_api.const import TYPE_RESULT
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_MEDIA_NEXT_TRACK,
|
||||
@@ -158,6 +162,7 @@ async def test_supported_features(
|
||||
| SUPPORT_PLAY_MEDIA
|
||||
| SUPPORT_TURN_ON
|
||||
| SUPPORT_TURN_OFF
|
||||
| SUPPORT_BROWSE_MEDIA
|
||||
== state.attributes.get("supported_features")
|
||||
)
|
||||
|
||||
@@ -187,6 +192,7 @@ async def test_tv_supported_features(
|
||||
| SUPPORT_PLAY_MEDIA
|
||||
| SUPPORT_TURN_ON
|
||||
| SUPPORT_TURN_OFF
|
||||
| SUPPORT_BROWSE_MEDIA
|
||||
== state.attributes.get("supported_features")
|
||||
)
|
||||
|
||||
@@ -364,6 +370,20 @@ async def test_services(
|
||||
|
||||
remote_mock.assert_called_once_with("reverse")
|
||||
|
||||
with patch("homeassistant.components.roku.Roku.launch") as launch_mock:
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_PLAY_MEDIA,
|
||||
{
|
||||
ATTR_ENTITY_ID: MAIN_ENTITY_ID,
|
||||
ATTR_MEDIA_CONTENT_TYPE: MEDIA_TYPE_APP,
|
||||
ATTR_MEDIA_CONTENT_ID: "11",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
launch_mock.assert_called_once_with("11")
|
||||
|
||||
with patch("homeassistant.components.roku.Roku.remote") as remote_mock:
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
@@ -450,6 +470,129 @@ async def test_tv_services(
|
||||
tune_mock.assert_called_once_with("55")
|
||||
|
||||
|
||||
async def test_media_browse(hass, aioclient_mock, hass_ws_client):
|
||||
"""Test browsing media."""
|
||||
await setup_integration(
|
||||
hass,
|
||||
aioclient_mock,
|
||||
device="rokutv",
|
||||
app="tvinput-dtv",
|
||||
host=TV_HOST,
|
||||
unique_id=TV_SERIAL,
|
||||
)
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
await client.send_json(
|
||||
{
|
||||
"id": 1,
|
||||
"type": "media_player/browse_media",
|
||||
"entity_id": TV_ENTITY_ID,
|
||||
}
|
||||
)
|
||||
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg["id"] == 1
|
||||
assert msg["type"] == TYPE_RESULT
|
||||
assert msg["success"]
|
||||
|
||||
assert msg["result"]
|
||||
assert msg["result"]["title"] == "Media Library"
|
||||
assert msg["result"]["media_content_type"] == "library"
|
||||
assert msg["result"]["can_expand"]
|
||||
assert not msg["result"]["can_play"]
|
||||
assert len(msg["result"]["children"]) == 2
|
||||
|
||||
# test apps
|
||||
await client.send_json(
|
||||
{
|
||||
"id": 2,
|
||||
"type": "media_player/browse_media",
|
||||
"entity_id": TV_ENTITY_ID,
|
||||
"media_content_type": MEDIA_TYPE_APPS,
|
||||
"media_content_id": "apps",
|
||||
}
|
||||
)
|
||||
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg["id"] == 2
|
||||
assert msg["type"] == TYPE_RESULT
|
||||
assert msg["success"]
|
||||
|
||||
assert msg["result"]
|
||||
assert msg["result"]["title"] == "Apps"
|
||||
assert msg["result"]["media_content_type"] == MEDIA_TYPE_APPS
|
||||
assert msg["result"]["can_expand"]
|
||||
assert not msg["result"]["can_play"]
|
||||
assert len(msg["result"]["children"]) == 11
|
||||
|
||||
assert msg["result"]["children"][0]["title"] == "Satellite TV"
|
||||
assert msg["result"]["children"][0]["media_content_type"] == MEDIA_TYPE_APP
|
||||
assert msg["result"]["children"][0]["media_content_id"] == "tvinput.hdmi2"
|
||||
assert (
|
||||
msg["result"]["children"][0]["thumbnail"]
|
||||
== "http://192.168.1.161:8060/query/icon/tvinput.hdmi2"
|
||||
)
|
||||
assert msg["result"]["children"][0]["can_play"]
|
||||
|
||||
assert msg["result"]["children"][3]["title"] == "Roku Channel Store"
|
||||
assert msg["result"]["children"][3]["media_content_type"] == MEDIA_TYPE_APP
|
||||
assert msg["result"]["children"][3]["media_content_id"] == "11"
|
||||
assert (
|
||||
msg["result"]["children"][3]["thumbnail"]
|
||||
== "http://192.168.1.161:8060/query/icon/11"
|
||||
)
|
||||
assert msg["result"]["children"][3]["can_play"]
|
||||
|
||||
# test channels
|
||||
await client.send_json(
|
||||
{
|
||||
"id": 3,
|
||||
"type": "media_player/browse_media",
|
||||
"entity_id": TV_ENTITY_ID,
|
||||
"media_content_type": MEDIA_TYPE_CHANNELS,
|
||||
"media_content_id": "channels",
|
||||
}
|
||||
)
|
||||
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg["id"] == 3
|
||||
assert msg["type"] == TYPE_RESULT
|
||||
assert msg["success"]
|
||||
|
||||
assert msg["result"]
|
||||
assert msg["result"]["title"] == "Channels"
|
||||
assert msg["result"]["media_content_type"] == MEDIA_TYPE_CHANNELS
|
||||
assert msg["result"]["can_expand"]
|
||||
assert not msg["result"]["can_play"]
|
||||
assert len(msg["result"]["children"]) == 2
|
||||
|
||||
assert msg["result"]["children"][0]["title"] == "WhatsOn"
|
||||
assert msg["result"]["children"][0]["media_content_type"] == MEDIA_TYPE_CHANNEL
|
||||
assert msg["result"]["children"][0]["media_content_id"] == "1.1"
|
||||
assert msg["result"]["children"][0]["can_play"]
|
||||
|
||||
# test invalid media type
|
||||
await client.send_json(
|
||||
{
|
||||
"id": 4,
|
||||
"type": "media_player/browse_media",
|
||||
"entity_id": TV_ENTITY_ID,
|
||||
"media_content_type": "invalid",
|
||||
"media_content_id": "invalid",
|
||||
}
|
||||
)
|
||||
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg["id"] == 4
|
||||
assert msg["type"] == TYPE_RESULT
|
||||
assert not msg["success"]
|
||||
|
||||
|
||||
async def test_integration_services(
|
||||
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
|
||||
Reference in new issue
Block a user