From 149b93559b5ee6516b6db6a6acb6ec6bef91cef5 Mon Sep 17 00:00:00 2001 From: Simon Lamon <32477463+silamon@users.noreply.github.com> Date: Sat, 2 Nov 2024 15:15:27 +0000 Subject: [PATCH] Fixes --- src/linkplay/bridge.py | 6 +++--- tests/linkplay/test_bridge.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/linkplay/bridge.py b/src/linkplay/bridge.py index 59e1bad..09f7994 100644 --- a/src/linkplay/bridge.py +++ b/src/linkplay/bridge.py @@ -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}." diff --git a/tests/linkplay/test_bridge.py b/tests/linkplay/test_bridge.py index 87b1a52..0b88985 100644 --- a/tests/linkplay/test_bridge.py +++ b/tests/linkplay/test_bridge.py @@ -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) @@ -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)