Update roku media browser classes (#40285)

* update roku media browser classes

this should allow proper icons to be shown vs plain directory

* Update test_media_player.py

* Update browse_media.py

* Update browse_media.py

* Update browse_media.py

* Update browse_media.py

* Update browse_media.py

* Update browse_media.py

* Update test_media_player.py
This commit is contained in:
Chris Talkington 2020-09-19 11:02:15 -05:00 committed by GitHub
parent e300cf3747
commit 6b317ced17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -13,8 +13,13 @@ from homeassistant.components.media_player.const import (
CONTENT_TYPE_MEDIA_CLASS = { CONTENT_TYPE_MEDIA_CLASS = {
MEDIA_TYPE_APP: MEDIA_CLASS_APP, MEDIA_TYPE_APP: MEDIA_CLASS_APP,
MEDIA_TYPE_APPS: MEDIA_CLASS_DIRECTORY, MEDIA_TYPE_APPS: MEDIA_CLASS_APP,
MEDIA_TYPE_CHANNEL: MEDIA_CLASS_CHANNEL, MEDIA_TYPE_CHANNEL: MEDIA_CLASS_CHANNEL,
MEDIA_TYPE_CHANNELS: MEDIA_CLASS_CHANNEL,
}
CONTAINER_TYPES_SPECIFIC_MEDIA_CLASS = {
MEDIA_TYPE_APPS: MEDIA_CLASS_DIRECTORY,
MEDIA_TYPE_CHANNELS: MEDIA_CLASS_DIRECTORY, MEDIA_TYPE_CHANNELS: MEDIA_CLASS_DIRECTORY,
} }
@ -37,6 +42,7 @@ def build_item_response(coordinator, payload):
thumbnail = None thumbnail = None
title = None title = None
media = None media = None
children_media_class = None
if search_type == MEDIA_TYPE_APPS: if search_type == MEDIA_TYPE_APPS:
title = "Apps" title = "Apps"
@ -44,6 +50,7 @@ def build_item_response(coordinator, payload):
{"app_id": item.app_id, "title": item.name, "type": MEDIA_TYPE_APP} {"app_id": item.app_id, "title": item.name, "type": MEDIA_TYPE_APP}
for item in coordinator.data.apps for item in coordinator.data.apps
] ]
children_media_class = MEDIA_CLASS_APP
elif search_type == MEDIA_TYPE_CHANNELS: elif search_type == MEDIA_TYPE_CHANNELS:
title = "Channels" title = "Channels"
media = [ media = [
@ -54,18 +61,22 @@ def build_item_response(coordinator, payload):
} }
for item in coordinator.data.channels for item in coordinator.data.channels
] ]
children_media_class = MEDIA_CLASS_CHANNEL
if media is None: if media is None:
return None return None
return BrowseMedia( return BrowseMedia(
media_class=MEDIA_CLASS_DIRECTORY, media_class=CONTAINER_TYPES_SPECIFIC_MEDIA_CLASS.get(
search_type, MEDIA_CLASS_DIRECTORY
),
media_content_id=search_id, media_content_id=search_id,
media_content_type=search_type, media_content_type=search_type,
title=title, title=title,
can_play=search_type in PLAYABLE_MEDIA_TYPES and search_id, can_play=search_type in PLAYABLE_MEDIA_TYPES and search_id,
can_expand=True, can_expand=True,
children=[item_payload(item, coordinator) for item in media], children=[item_payload(item, coordinator) for item in media],
children_media_class=children_media_class,
thumbnail=thumbnail, thumbnail=thumbnail,
) )
@ -148,7 +159,5 @@ def library_payload(coordinator):
for child in library_info.children for child in library_info.children
): ):
library_info.children_media_class = MEDIA_CLASS_CHANNEL library_info.children_media_class = MEDIA_CLASS_CHANNEL
else:
library_info.children_media_class = MEDIA_CLASS_DIRECTORY
return library_info return library_info

View File

@ -529,6 +529,7 @@ async def test_media_browse(hass, aioclient_mock, hass_ws_client):
assert msg["result"]["title"] == "Apps" assert msg["result"]["title"] == "Apps"
assert msg["result"]["media_class"] == MEDIA_CLASS_DIRECTORY assert msg["result"]["media_class"] == MEDIA_CLASS_DIRECTORY
assert msg["result"]["media_content_type"] == MEDIA_TYPE_APPS assert msg["result"]["media_content_type"] == MEDIA_TYPE_APPS
assert msg["result"]["children_media_class"] == MEDIA_CLASS_APP
assert msg["result"]["can_expand"] assert msg["result"]["can_expand"]
assert not msg["result"]["can_play"] assert not msg["result"]["can_play"]
assert len(msg["result"]["children"]) == 11 assert len(msg["result"]["children"]) == 11
@ -573,6 +574,7 @@ async def test_media_browse(hass, aioclient_mock, hass_ws_client):
assert msg["result"]["title"] == "Channels" assert msg["result"]["title"] == "Channels"
assert msg["result"]["media_class"] == MEDIA_CLASS_DIRECTORY assert msg["result"]["media_class"] == MEDIA_CLASS_DIRECTORY
assert msg["result"]["media_content_type"] == MEDIA_TYPE_CHANNELS assert msg["result"]["media_content_type"] == MEDIA_TYPE_CHANNELS
assert msg["result"]["children_media_class"] == MEDIA_CLASS_CHANNEL
assert msg["result"]["can_expand"] assert msg["result"]["can_expand"]
assert not msg["result"]["can_play"] assert not msg["result"]["can_play"]
assert len(msg["result"]["children"]) == 2 assert len(msg["result"]["children"]) == 2