mirror of
https://github.com/home-assistant/core.git
synced 2025-09-07 22:01:34 +02:00
Fix demo media_player.browse browsing (#150669)
This commit is contained in:
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.components import media_source
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
BrowseMedia,
|
BrowseMedia,
|
||||||
MediaClass,
|
MediaClass,
|
||||||
@@ -396,6 +397,15 @@ class DemoBrowsePlayer(AbstractDemoPlayer):
|
|||||||
|
|
||||||
_attr_supported_features = BROWSE_PLAYER_SUPPORT
|
_attr_supported_features = BROWSE_PLAYER_SUPPORT
|
||||||
|
|
||||||
|
async def async_browse_media(
|
||||||
|
self,
|
||||||
|
media_content_type: MediaType | str | None = None,
|
||||||
|
media_content_id: str | None = None,
|
||||||
|
) -> BrowseMedia:
|
||||||
|
"""Implement the websocket media browsing helper."""
|
||||||
|
|
||||||
|
return await media_source.async_browse_media(self.hass, media_content_id)
|
||||||
|
|
||||||
|
|
||||||
class DemoGroupPlayer(AbstractDemoPlayer):
|
class DemoGroupPlayer(AbstractDemoPlayer):
|
||||||
"""A Demo media player that supports grouping."""
|
"""A Demo media player that supports grouping."""
|
||||||
|
@@ -55,7 +55,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.aiohttp_client import DATA_CLIENTSESSION, _make_key
|
from homeassistant.helpers.aiohttp_client import DATA_CLIENTSESSION, _make_key
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.typing import ClientSessionGenerator
|
from tests.typing import ClientSessionGenerator, WebSocketGenerator
|
||||||
|
|
||||||
TEST_ENTITY_ID = "media_player.walkman"
|
TEST_ENTITY_ID = "media_player.walkman"
|
||||||
|
|
||||||
@@ -563,3 +563,32 @@ async def test_grouping(hass: HomeAssistant) -> None:
|
|||||||
)
|
)
|
||||||
state = hass.states.get(walkman)
|
state = hass.states.get(walkman)
|
||||||
assert state.attributes.get(ATTR_GROUP_MEMBERS) == []
|
assert state.attributes.get(ATTR_GROUP_MEMBERS) == []
|
||||||
|
|
||||||
|
|
||||||
|
async def test_browse(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
) -> None:
|
||||||
|
"""Test the media player browse."""
|
||||||
|
entity = "media_player.browse"
|
||||||
|
|
||||||
|
await async_setup_component(hass, "media_source", {"media_source": {}})
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass, MP_DOMAIN, {"media_player": {"platform": "demo"}}
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
websocket_client = await hass_ws_client(hass)
|
||||||
|
await websocket_client.send_json(
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"type": "media_player/browse_media",
|
||||||
|
"entity_id": entity,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
msg = await websocket_client.receive_json()
|
||||||
|
assert msg["success"]
|
||||||
|
assert msg["result"]["title"] == "media"
|
||||||
|
assert msg["result"]["media_class"] == "directory"
|
||||||
|
assert len(msg["result"]["children"])
|
||||||
|
Reference in New Issue
Block a user