Skip to content

Commit

Permalink
Handle invalid playmode better
Browse files Browse the repository at this point in the history
  • Loading branch information
silamon committed Sep 26, 2024
1 parent 0a752a7 commit 0959ec9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/linkplay/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,12 @@ def channel_type(self) -> ChannelType:
@property
def play_mode(self) -> PlayingMode:
"""Returns the current playing mode of the player."""
return PlayingMode(
self.properties.get(PlayerAttribute.PLAYBACK_MODE, PlayingMode.IDLE)
)
try:
return PlayingMode(
self.properties.get(PlayerAttribute.PLAYBACK_MODE, PlayingMode.IDLE)
)
except ValueError:
return PlayingMode(PlayingMode.IDLE)

@property
def loop_mode(self) -> LoopMode:
Expand Down
10 changes: 9 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 @@ -197,6 +196,15 @@ async def test_player_set_volume_raises_value_error(volume: Any):
await player.set_volume(volume)


async def test_player_invalid_playmode():
"""Tests if the player handles an invalid playmode correctly."""
bridge = AsyncMock()
player = LinkPlayPlayer(bridge)
player.properties[PlayerAttribute.PLAYBACK_MODE] = 33

assert player.play_mode == PlayingMode.IDLE


async def test_player_set_equalizer_mode():
"""Tests if the player set equalizer mode is correctly called."""
bridge = AsyncMock()
Expand Down

0 comments on commit 0959ec9

Please sign in to comment.