Skip to content

Commit

Permalink
Add check for visible speaker; expand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pwt committed Dec 12, 2020
1 parent b97b581 commit 66e4794
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
15 changes: 9 additions & 6 deletions soco/core.py
Expand Up @@ -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":
Expand All @@ -985,13 +988,13 @@ 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 int(
self.renderingControl.GetRoomCalibrationStatus([("InstanceID", 0)])[
"RoomCalibrationAvailable"
]
):
response = self.renderingControl.GetRoomCalibrationStatus([("InstanceID", 0)])
if response["RoomCalibrationAvailable"] == "0":
raise NotSupportedException
if not self.is_visible:
raise SoCoNotVisibleException
trueplay_value = "1" if trueplay else "0"
self.renderingControl.SetRoomCalibrationStatus(
[
Expand Down
47 changes: 33 additions & 14 deletions tests/test_core.py
Expand Up @@ -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 = {
Expand Down

0 comments on commit 66e4794

Please sign in to comment.