Skip to content

Commit

Permalink
Add move queue item
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsayre committed Jan 8, 2025
1 parent 5a825b6 commit 6b3c881
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyheos/command/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
COMMAND_CLEAR_QUEUE: Final = "player/clear_queue"
COMMAND_PLAY_QUEUE: Final = "player/play_queue"
COMMAND_SAVE_QUEUE: Final = "player/save_queue"
COMMAND_MOVE_QUEUE_ITEM: Final = "player/move_queue_item"
COMMAND_PLAY_NEXT: Final = "player/play_next"
COMMAND_PLAY_PREVIOUS: Final = "player/play_previous"
COMMAND_PLAY_QUICK_SELECT: Final = "player/play_quickselect"
Expand Down
20 changes: 17 additions & 3 deletions pyheos/command/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
Define the player command module.
This module creates HEOS player commands.
Commands not currently implemented:
4.2.20 Move Queue
"""

from typing import Any
Expand Down Expand Up @@ -237,6 +234,23 @@ def clear_queue(player_id: int) -> HeosCommand:
command.COMMAND_CLEAR_QUEUE, {const.ATTR_PLAYER_ID: player_id}
)

@staticmethod
def move_queue_item(
player_id: int, source_queue_ids: list[int], destination_queue_id: int
) -> HeosCommand:
"""Move one or more items in the queue.
References:
4.2.20 Move Queue"""
return HeosCommand(
command.COMMAND_MOVE_QUEUE_ITEM,
{
const.ATTR_PLAYER_ID: player_id,
const.ATTR_SOURCE_QUEUE_ID: ",".join(map(str, source_queue_ids)),
const.ATTR_DESTINATION_QUEUE_ID: destination_queue_id,
},
)

@staticmethod
def play_next(player_id: int) -> HeosCommand:
"""Play next.
Expand Down
2 changes: 2 additions & 0 deletions pyheos/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ATTR_CONTAINER_ID: Final = "cid"
ATTR_COUNT: Final = "count"
ATTR_CURRENT_POSITION: Final = "cur_pos"
ATTR_DESTINATION_QUEUE_ID: Final = "dqid"
ATTR_DURATION: Final = "duration"
ATTR_ENABLE: Final = "enable"
ATTR_ERROR: Final = "error"
Expand Down Expand Up @@ -56,6 +57,7 @@
ATTR_SONG: Final = "song"
ATTR_SOURCE_ID: Final = "sid"
ATTR_SOURCE_PLAYER_ID: Final = "spid"
ATTR_SOURCE_QUEUE_ID: Final = "sqid"
ATTR_SIGNED_OUT: Final = "signed_out"
ATTR_SIGNED_IN: Final = "signed_in"
ATTR_STATE: Final = "state"
Expand Down
13 changes: 13 additions & 0 deletions pyheos/heos.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,19 @@ async def player_clear_queue(self, player_id: int) -> None:
4.2.19 Clear Queue"""
await self._connection.command(PlayerCommands.clear_queue(player_id))

async def player_move_queue_item(
self, player_id: int, source_queue_ids: list[int], destination_queue_id: int
) -> None:
"""Move one or more items in the queue.
References:
4.2.20 Move Queue"""
await self._connection.command(
PlayerCommands.move_queue_item(
player_id, source_queue_ids, destination_queue_id
)
)

async def player_play_next(self, player_id: int) -> None:
"""Play next.
Expand Down
9 changes: 9 additions & 0 deletions pyheos/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,15 @@ async def save_queue(self, name: str) -> None:
assert self.heos, "Heos instance not set"
await self.heos.player_save_queue(self.player_id, name)

async def move_queue_item(
self, source_queue_ids: list[int], destination_queue_id: int
) -> None:
"""Move one or more items in the queue."""
assert self.heos, "Heos instance not set"
await self.heos.player_move_queue_item(
self.player_id, source_queue_ids, destination_queue_id
)

async def play_next(self) -> None:
"""Clear the queue of the player."""
assert self.heos, "Heos instance not set"
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/player.move_queue_item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"heos": {"command": "player/move_queue_item", "result": "success", "message": "pid={player_id}&sqid=2,3,4&dqid=1"}}
13 changes: 13 additions & 0 deletions tests/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,19 @@ async def test_save_queue(player: HeosPlayer) -> None:
await player.save_queue("Test")


@calls_command(
"player.move_queue_item",
{
const.ATTR_PLAYER_ID: 1,
const.ATTR_SOURCE_QUEUE_ID: "2,3,4",
const.ATTR_DESTINATION_QUEUE_ID: 1,
},
)
async def test_move_queue_item(player: HeosPlayer) -> None:
"""Test the move_queue_item command."""
await player.move_queue_item([2, 3, 4], 1)


@calls_command("player.get_queue", {const.ATTR_PLAYER_ID: 1, const.ATTR_RANGE: "0,10"})
async def test_get_queue_with_range(player: HeosPlayer) -> None:
"""Test the check_update command."""
Expand Down

0 comments on commit 6b3c881

Please sign in to comment.