Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
silamon committed Nov 2, 2024
1 parent d9b6dd2 commit 149b935
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/linkplay/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ async def set_play_mode(self, mode: PlayingMode) -> None:

async def play_preset(self, preset_number: int) -> None:
"""Play a preset."""
max_number_of_presets_allowed = int(self.bridge.device.properties.get(
DeviceAttribute.PRESET_KEY, 10
))
max_number_of_presets_allowed = int(
self.bridge.device.properties.get(DeviceAttribute.PRESET_KEY) or "10"
)
if not 0 < preset_number <= max_number_of_presets_allowed:
raise ValueError(
f"Preset must be between 1 and {max_number_of_presets_allowed}."
Expand Down
24 changes: 24 additions & 0 deletions tests/linkplay/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,32 @@ async def test_player_set_play_mode():
)


@pytest.mark.parametrize("preset_number", range(1, 11))
async def test_player_play_preset_when_max_key_empty(preset_number: int):
"""Tests if a player is able to play a preset."""
bridge = AsyncMock()
device = LinkPlayDevice(bridge)
player = LinkPlayPlayer(bridge)
bridge.device = device
bridge.player = player

bridge.device.properties[DeviceAttribute.PRESET_KEY] = ""

await player.play_preset(preset_number)

bridge.request.assert_called_once_with(
LinkPlayCommand.PLAY_PRESET.format(preset_number)
)


@pytest.mark.parametrize("preset_number", range(1, 11))
async def test_player_play_preset(preset_number: int):
"""Tests if a player is able to play a preset."""
bridge = AsyncMock()
device = LinkPlayDevice(bridge)
player = LinkPlayPlayer(bridge)
bridge.device = device
bridge.player = player

await player.play_preset(preset_number)

Expand All @@ -283,7 +304,10 @@ async def test_player_play_preset(preset_number: int):
async def test_player_play_preset_raises_value_error(preset_number: int):
"""Tests that a player fails in an expected way if play preset input is incorrect."""
bridge = AsyncMock()
device = LinkPlayDevice(bridge)
player = LinkPlayPlayer(bridge)
bridge.device = device
bridge.player = player

with pytest.raises(ValueError):
await player.play_preset(preset_number)
Expand Down

0 comments on commit 149b935

Please sign in to comment.