diff --git a/pyheos/command/__init__.py b/pyheos/command/__init__.py index 91a1719..a2271de 100644 --- a/pyheos/command/__init__.py +++ b/pyheos/command/__init__.py @@ -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" diff --git a/pyheos/command/player.py b/pyheos/command/player.py index ef1b68d..14e5d7c 100644 --- a/pyheos/command/player.py +++ b/pyheos/command/player.py @@ -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 @@ -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. diff --git a/pyheos/const.py b/pyheos/const.py index d867053..72c0f83 100644 --- a/pyheos/const.py +++ b/pyheos/const.py @@ -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" @@ -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" diff --git a/pyheos/heos.py b/pyheos/heos.py index 3f5c280..fdfd22b 100644 --- a/pyheos/heos.py +++ b/pyheos/heos.py @@ -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. diff --git a/pyheos/player.py b/pyheos/player.py index e65a075..1f0fe29 100644 --- a/pyheos/player.py +++ b/pyheos/player.py @@ -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" diff --git a/tests/fixtures/player.move_queue_item.json b/tests/fixtures/player.move_queue_item.json new file mode 100644 index 0000000..0919e5c --- /dev/null +++ b/tests/fixtures/player.move_queue_item.json @@ -0,0 +1 @@ +{"heos": {"command": "player/move_queue_item", "result": "success", "message": "pid={player_id}&sqid=2,3,4&dqid=1"}} \ No newline at end of file diff --git a/tests/test_player.py b/tests/test_player.py index 7ffbce5..103a35a 100644 --- a/tests/test_player.py +++ b/tests/test_player.py @@ -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."""