Add Recently Added and On Deck to Plex media browser (#39232)
This commit is contained in:
1 parent
49daf57c54
commit
d66bc6a873
3 files changed
+126
-5
No files matched your search
@@ -346,6 +346,14 @@ class MockPlexLibrary:
|
||||
"""Mock the sectionByID lookup."""
|
||||
return [x for x in self.sections() if x.key == section_id][0]
|
||||
|
||||
def onDeck(self):
|
||||
"""Mock an empty On Deck folder."""
|
||||
return []
|
||||
|
||||
def recentlyAdded(self):
|
||||
"""Mock an empty Recently Added folder."""
|
||||
return []
|
||||
|
||||
|
||||
class MockPlexLibrarySection:
|
||||
"""Mock a Plex LibrarySection instance."""
|
||||
@@ -381,6 +389,14 @@ class MockPlexLibrarySection:
|
||||
if child.ratingKey == ratingKey:
|
||||
return child
|
||||
|
||||
def onDeck(self):
|
||||
"""Mock an empty On Deck folder."""
|
||||
return []
|
||||
|
||||
def recentlyAdded(self):
|
||||
"""Mock an empty Recently Added folder."""
|
||||
return self.all()
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
"""Mock the library type."""
|
||||
|
||||
@@ -4,6 +4,7 @@ from homeassistant.components.media_player.const import (
|
||||
ATTR_MEDIA_CONTENT_TYPE,
|
||||
)
|
||||
from homeassistant.components.plex.const import CONF_SERVER_IDENTIFIER, DOMAIN
|
||||
from homeassistant.components.plex.media_browser import SPECIAL_METHODS
|
||||
from homeassistant.components.websocket_api.const import ERR_UNKNOWN_ERROR, TYPE_RESULT
|
||||
|
||||
from .const import DEFAULT_DATA, DEFAULT_OPTIONS
|
||||
@@ -77,10 +78,61 @@ async def test_browse_media(hass, hass_ws_client):
|
||||
result = msg["result"]
|
||||
assert result[ATTR_MEDIA_CONTENT_TYPE] == "server"
|
||||
assert result[ATTR_MEDIA_CONTENT_ID] == DEFAULT_DATA[CONF_SERVER_IDENTIFIER]
|
||||
assert len(result["children"]) == len(mock_plex_server.library.sections())
|
||||
assert len(result["children"]) == len(mock_plex_server.library.sections()) + len(
|
||||
SPECIAL_METHODS
|
||||
)
|
||||
|
||||
tvshows = next(iter(x for x in result["children"] if x["title"] == "TV Shows"))
|
||||
playlists = next(iter(x for x in result["children"] if x["title"] == "Playlists"))
|
||||
special_keys = list(SPECIAL_METHODS.keys())
|
||||
|
||||
# Browse into a special folder (server)
|
||||
msg_id += 1
|
||||
await websocket_client.send_json(
|
||||
{
|
||||
"id": msg_id,
|
||||
"type": "media_player/browse_media",
|
||||
"entity_id": media_players[0],
|
||||
ATTR_MEDIA_CONTENT_TYPE: "server",
|
||||
ATTR_MEDIA_CONTENT_ID: f"{DEFAULT_DATA[CONF_SERVER_IDENTIFIER]}:{special_keys[0]}",
|
||||
}
|
||||
)
|
||||
|
||||
msg = await websocket_client.receive_json()
|
||||
assert msg["id"] == msg_id
|
||||
assert msg["type"] == TYPE_RESULT
|
||||
assert msg["success"]
|
||||
result = msg["result"]
|
||||
assert result[ATTR_MEDIA_CONTENT_TYPE] == "server"
|
||||
assert (
|
||||
result[ATTR_MEDIA_CONTENT_ID]
|
||||
== f"{DEFAULT_DATA[CONF_SERVER_IDENTIFIER]}:{special_keys[0]}"
|
||||
)
|
||||
assert len(result["children"]) == len(mock_plex_server.library.onDeck())
|
||||
|
||||
# Browse into a special folder (library)
|
||||
msg_id += 1
|
||||
library_section_id = next(iter(mock_plex_server.library.sections())).key
|
||||
await websocket_client.send_json(
|
||||
{
|
||||
"id": msg_id,
|
||||
"type": "media_player/browse_media",
|
||||
"entity_id": media_players[0],
|
||||
ATTR_MEDIA_CONTENT_TYPE: "library",
|
||||
ATTR_MEDIA_CONTENT_ID: f"{library_section_id}:{special_keys[1]}",
|
||||
}
|
||||
)
|
||||
|
||||
msg = await websocket_client.receive_json()
|
||||
assert msg["id"] == msg_id
|
||||
assert msg["type"] == TYPE_RESULT
|
||||
assert msg["success"]
|
||||
result = msg["result"]
|
||||
assert result[ATTR_MEDIA_CONTENT_TYPE] == "library"
|
||||
assert result[ATTR_MEDIA_CONTENT_ID] == f"{library_section_id}:{special_keys[1]}"
|
||||
assert len(result["children"]) == len(
|
||||
mock_plex_server.library.sectionByID(library_section_id).recentlyAdded()
|
||||
)
|
||||
|
||||
# Browse into a Plex TV show library
|
||||
msg_id += 1
|
||||
@@ -103,7 +155,7 @@ async def test_browse_media(hass, hass_ws_client):
|
||||
result_id = result[ATTR_MEDIA_CONTENT_ID]
|
||||
assert len(result["children"]) == len(
|
||||
mock_plex_server.library.sectionByID(result_id).all()
|
||||
)
|
||||
) + len(SPECIAL_METHODS)
|
||||
|
||||
# Browse into a Plex TV show
|
||||
msg_id += 1
|
||||
@@ -112,8 +164,8 @@ async def test_browse_media(hass, hass_ws_client):
|
||||
"id": msg_id,
|
||||
"type": "media_player/browse_media",
|
||||
"entity_id": media_players[0],
|
||||
ATTR_MEDIA_CONTENT_TYPE: result["children"][0][ATTR_MEDIA_CONTENT_TYPE],
|
||||
ATTR_MEDIA_CONTENT_ID: str(result["children"][0][ATTR_MEDIA_CONTENT_ID]),
|
||||
ATTR_MEDIA_CONTENT_TYPE: result["children"][-1][ATTR_MEDIA_CONTENT_TYPE],
|
||||
ATTR_MEDIA_CONTENT_ID: str(result["children"][-1][ATTR_MEDIA_CONTENT_ID]),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user