Skip to content

Commit

Permalink
Support stop command (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
silamon authored Sep 26, 2024
1 parent 649a40a commit dc975ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/linkplay/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,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)
Expand Down
1 change: 1 addition & 0 deletions src/linkplay/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:{}"
Expand Down
11 changes: 11 additions & 0 deletions tests/linkplay/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,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()
Expand Down

0 comments on commit dc975ec

Please sign in to comment.