From 5131fbfc47eecfdc3a3e0037776ba2b7ffac89d5 Mon Sep 17 00:00:00 2001 From: pwt <1089749+pwt@users.noreply.github.com> Date: Sat, 12 Dec 2020 20:16:07 +0000 Subject: [PATCH] Add check for visible speaker; expand tests --- soco/core.py | 8 +++++++- tests/test_core.py | 47 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/soco/core.py b/soco/core.py index 6a6993f42..e1082d536 100755 --- a/soco/core.py +++ b/soco/core.py @@ -968,7 +968,10 @@ def trueplay(self): Devices that do not support Trueplay, or which do not have a current Trueplay calibration, will raise a `NotSupportedException` - both when getting and setting the property.. + when both getting and setting the property. + + Can only be set on visible devices. Attempting to set on non-visible + devices will raise a `SoCoNotVisibleException`. """ response = self.renderingControl.GetRoomCalibrationStatus([("InstanceID", 0)]) if response["RoomCalibrationAvailable"] == "0": @@ -985,7 +988,10 @@ def trueplay(self, trueplay): :type trueplay: bool :raises NotSupportedException: If the device does not support Trueplay or doesn't have a current calibration. + :raises SoCoNotVisibleException: If the device is not visible. """ + if not self.is_visible: + raise SoCoNotVisibleException if not int( self.renderingControl.GetRoomCalibrationStatus([("InstanceID", 0)])[ "RoomCalibrationAvailable" diff --git a/tests/test_core.py b/tests/test_core.py index 668523f88..f4a9c79a9 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1154,29 +1154,48 @@ def test_soco_loudness(self, moco): ) def test_soco_trueplay(self, moco): + moco.renderingControl.GetRoomCalibrationStatus.return_value = { + "RoomCalibrationAvailable": "0", + "RoomCalibrationEnabled": "0", + } + with pytest.raises(NotSupportedException): + assert not moco.trueplay + moco.renderingControl.GetRoomCalibrationStatus.assert_called_with( + [("InstanceID", 0)] + ) moco.renderingControl.GetRoomCalibrationStatus.return_value = { "RoomCalibrationAvailable": "1", "RoomCalibrationEnabled": "1", } assert moco.trueplay - moco.renderingControl.GetRoomCalibrationStatus.assert_called_once_with( - [("InstanceID", 0)] - ) - moco.trueplay = False moco.renderingControl.GetRoomCalibrationStatus.assert_called_with( [("InstanceID", 0)] ) - moco.renderingControl.SetRoomCalibrationStatus.assert_called_once_with( - [("InstanceID", 0), ("RoomCalibrationEnabled", "0")] - ) - moco.renderingControl.GetRoomCalibrationStatus.return_value = { - "RoomCalibrationAvailable": "0", - "RoomCalibrationEnabled": "0", - } - with pytest.raises(NotSupportedException): - assert not moco.trueplay - with pytest.raises(NotSupportedException): + # Setter tests for 'is_visible' property, so this needs to be + # mocked. + with mock.patch( + "soco.SoCo.is_visible", new_callable=mock.PropertyMock + ) as mock_is_visible: + mock_is_visible.return_value = True + moco.trueplay = False + moco.renderingControl.SetRoomCalibrationStatus.assert_called_with( + [ + ("InstanceID", 0), + ("RoomCalibrationEnabled", "0"), + ] + ) moco.trueplay = True + moco.renderingControl.SetRoomCalibrationStatus.assert_called_with( + [ + ("InstanceID", 0), + ("RoomCalibrationEnabled", "1"), + ] + ) + # Check for exception if attempt to set the property on a + # non-visible speaker. + mock_is_visible.return_value = False + with pytest.raises(SoCoNotVisibleException): + moco.trueplay = True def test_soco_fixed_volume(self, moco): moco.renderingControl.GetSupportsOutputFixed.return_value = {