mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Add play queue item to HEOS (#141480)
Add ability to play specific queue item
This commit is contained in:
parent
002ca9611d
commit
6bfd39f094
@ -387,6 +387,15 @@ class HeosMediaPlayer(CoordinatorEntity[HeosCoordinator], MediaPlayerEntity):
|
||||
await self._player.play_preset_station(index)
|
||||
return
|
||||
|
||||
if media_type == "queue":
|
||||
# media_id must be an int
|
||||
try:
|
||||
queue_id = int(media_id)
|
||||
except ValueError:
|
||||
raise ValueError(f"Invalid queue id '{media_id}'") from None
|
||||
await self._player.play_queue(queue_id)
|
||||
return
|
||||
|
||||
raise ValueError(f"Unsupported media type '{media_type}'")
|
||||
|
||||
@catch_action_error("select source")
|
||||
|
@ -41,6 +41,7 @@ class MockHeos(Heos):
|
||||
self.player_get_quick_selects: AsyncMock = AsyncMock()
|
||||
self.player_play_next: AsyncMock = AsyncMock()
|
||||
self.player_play_previous: AsyncMock = AsyncMock()
|
||||
self.player_play_queue: AsyncMock = AsyncMock()
|
||||
self.player_play_quick_select: AsyncMock = AsyncMock()
|
||||
self.player_set_mute: AsyncMock = AsyncMock()
|
||||
self.player_set_play_mode: AsyncMock = AsyncMock()
|
||||
|
@ -1321,6 +1321,51 @@ async def test_play_media_music_source_url(
|
||||
controller.play_url.assert_called_once()
|
||||
|
||||
|
||||
async def test_play_media_queue(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
controller: MockHeos,
|
||||
) -> None:
|
||||
"""Test the play media service with type queue."""
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.services.async_call(
|
||||
MEDIA_PLAYER_DOMAIN,
|
||||
SERVICE_PLAY_MEDIA,
|
||||
{
|
||||
ATTR_ENTITY_ID: "media_player.test_player",
|
||||
ATTR_MEDIA_CONTENT_TYPE: "queue",
|
||||
ATTR_MEDIA_CONTENT_ID: "2",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
controller.player_play_queue.assert_called_once_with(1, 2)
|
||||
|
||||
|
||||
async def test_play_media_queue_invalid(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, controller: MockHeos
|
||||
) -> None:
|
||||
"""Test the play media service with an invalid queue id."""
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match=re.escape("Unable to play media: Invalid queue id 'Invalid'"),
|
||||
):
|
||||
await hass.services.async_call(
|
||||
MEDIA_PLAYER_DOMAIN,
|
||||
SERVICE_PLAY_MEDIA,
|
||||
{
|
||||
ATTR_ENTITY_ID: "media_player.test_player",
|
||||
ATTR_MEDIA_CONTENT_TYPE: "queue",
|
||||
ATTR_MEDIA_CONTENT_ID: "Invalid",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert controller.player_play_queue.call_count == 0
|
||||
|
||||
|
||||
async def test_browse_media_root(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
|
Loading…
x
Reference in New Issue
Block a user