From 63dd243a8f7956cd2fabd1aeb45f34dcaa6a33b5 Mon Sep 17 00:00:00 2001 From: Simon Lamon <32477463+silamon@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:20:37 +0000 Subject: [PATCH] Support stop command --- src/linkplay/bridge.py | 5 +++++ src/linkplay/consts.py | 1 + tests/linkplay/test_bridge.py | 12 +++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/linkplay/bridge.py b/src/linkplay/bridge.py index 01c25b0..f91bfb3 100644 --- a/src/linkplay/bridge.py +++ b/src/linkplay/bridge.py @@ -124,6 +124,11 @@ async def pause(self) -> None: await self.bridge.request(LinkPlayCommand.PAUSE) self.properties[PlayerAttribute.PLAYING_STATUS] = PlayingStatus.PAUSED + async def stop(self) -> None: + """Stop the current playing track and remove the selected source.""" + await self.bridge.request(LinkPlayCommand.STOP) + self.properties[PlayerAttribute.PLAYING_STATUS] = PlayingStatus.STOPPED + async def toggle(self) -> None: """Start playing if the player is currently not playing. Stops playing if it is.""" await self.bridge.request(LinkPlayCommand.TOGGLE) diff --git a/src/linkplay/consts.py b/src/linkplay/consts.py index 7468ca0..28f5987 100644 --- a/src/linkplay/consts.py +++ b/src/linkplay/consts.py @@ -79,6 +79,7 @@ class LinkPlayCommand(StrEnum): VOLUME = "setPlayerCmd:vol:{}" PLAYLIST = "setPlayerCmd:playlist:uri:{}" PAUSE = "setPlayerCmd:pause" + STOP = "setPlayerCmd:stop" TOGGLE = "setPlayerCmd:onepause" EQUALIZER_MODE = "setPlayerCmd:equalizer:{}" LOOP_MODE = "setPlayerCmd:loopmode:{}" diff --git a/tests/linkplay/test_bridge.py b/tests/linkplay/test_bridge.py index 0af91b8..9744ac3 100644 --- a/tests/linkplay/test_bridge.py +++ b/tests/linkplay/test_bridge.py @@ -4,7 +4,6 @@ from unittest.mock import AsyncMock, patch import pytest - from linkplay.bridge import ( LinkPlayBridge, LinkPlayDevice, @@ -166,6 +165,17 @@ async def test_player_pause(): assert player.status == PlayingStatus.PAUSED +async def test_player_stop(): + """Tests if the player stop is correctly called.""" + bridge = AsyncMock() + player = LinkPlayPlayer(bridge) + + await player.stop() + + bridge.request.assert_called_once_with(LinkPlayCommand.STOP) + assert player.status == PlayingStatus.STOPPED + + async def test_player_toggle(): """Tests if the player pause is correctly called.""" bridge = AsyncMock()