Skip to content

Commit

Permalink
Support stop command
Browse files Browse the repository at this point in the history
  • Loading branch information
silamon committed Sep 26, 2024
1 parent 0a752a7 commit 63dd243
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/linkplay/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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
12 changes: 11 additions & 1 deletion tests/linkplay/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from unittest.mock import AsyncMock, patch

import pytest

from linkplay.bridge import (
LinkPlayBridge,
LinkPlayDevice,
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 63dd243

Please sign in to comment.