Skip to content

Commit

Permalink
Add tests for ZoneB and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdwetering committed Aug 26, 2024
1 parent 7a73e85 commit 08fcac1
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 3 deletions.
11 changes: 11 additions & 0 deletions tests/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@
PlaybackInfo,
PureDirMode,
Pwr,
PwrB,
Repeat,
Shuffle,
Sleep,
SoundPrg,
SpeakerA,
SpeakerB,
Straight,
ThreeDeeCinema,
TwoChDecoder,
ZoneBAvail,
ZoneBMute,
)


Expand All @@ -51,10 +56,16 @@ def test_invalid_values_on_enums():
assert PlaybackInfo("x") is PlaybackInfo.UNKNOWN
assert PureDirMode("x") is PureDirMode.UNKNOWN
assert Pwr("x") is Pwr.UNKNOWN
assert PwrB("x") is PwrB.UNKNOWN
assert Repeat("x") is Repeat.UNKNOWN
assert Shuffle("x") is Shuffle.UNKNOWN
assert Sleep("x") is Sleep.UNKNOWN
assert SoundPrg("x") is SoundPrg.UNKNOWN
assert SpeakerA("x") is SpeakerA.UNKNOWN
assert SpeakerB("x") is SpeakerB.UNKNOWN
assert Straight("x") is Straight.UNKNOWN
assert ThreeDeeCinema("x") is ThreeDeeCinema.UNKNOWN
assert TwoChDecoder("x") is TwoChDecoder.UNKNOWN
assert ZoneBAvail("x") is ZoneBAvail.UNKNOWN
assert ZoneBMute("x") is ZoneBMute.UNKNOWN

130 changes: 128 additions & 2 deletions tests/test_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
Mute,
PureDirMode,
Pwr,
PwrB,
SoundPrg,
SpeakerA,
SpeakerB,
Straight,
TwoChDecoder,
ZoneBMute,
)
from ynca.subunits.zone import Main, ZoneBase

from .mock_yncaconnection import YncaConnectionMock

SYS = "SYS"
SUBUNIT = "MAIN"
NUM_SCENES = 12
Expand All @@ -33,9 +35,13 @@
(SUBUNIT, "BASIC"),
[
(SUBUNIT, "PWR", "Standby"),
(SUBUNIT, "PWRB", "On"),
(SUBUNIT, "SLEEP", "Off"),
(SUBUNIT, "VOL", "-30.0"),
(SUBUNIT, "MUTE", "Off"),
(SUBUNIT, "ZONEBAVAIL", "Ready"),
(SUBUNIT, "ZONEBVOL", "-20.5"),
(SUBUNIT, "ZONEBMUTE", "On"),
(SUBUNIT, "INP", "HDMI1"),
(SUBUNIT, "STRAIGHT", "Off"),
(SUBUNIT, "ENHANCER", "On"),
Expand All @@ -45,6 +51,8 @@
(SUBUNIT, "SPBASS", "4"),
(SUBUNIT, "SPTREBLE", "-4"),
(SUBUNIT, "ADAPTIVEDRC", "Off"),
(SUBUNIT, "SPEAKERA", "Off"),
(SUBUNIT, "SPEAKERB", "On"),
],
),
(
Expand Down Expand Up @@ -76,6 +84,12 @@
(SUBUNIT, "2CHDECODER", "Dolby PLIIx Movie"),
],
),
(
(SUBUNIT, "ZONEBNAME"),
[
(SUBUNIT, "ZONEBNAME", "ZoneBName"),
],
),
(
(SUBUNIT, "ZONENAME"),
[
Expand Down Expand Up @@ -172,6 +186,13 @@ def test_initialize_full(connection, update_callback):
for scene_id in range(1, NUM_SCENES + 1):
assert getattr(z, f"scene{scene_id}name") == f"Scene name {scene_id}"

assert z.pwrb is PwrB.ON
assert z.zonebmute is ZoneBMute.ON
assert z.zonebname == "ZoneBName"
assert z.zonebvol == -20.5
assert z.speakera is SpeakerA.OFF
assert z.speakerb is SpeakerB.ON


def test_mute(connection, initialized_zone: ZoneBase):
# Writing to device
Expand All @@ -195,6 +216,20 @@ def test_mute(connection, initialized_zone: ZoneBase):
assert initialized_zone.mute is Mute.OFF


def test_zoneb_mute(connection, initialized_zone: Main):
# Writing to device
initialized_zone.zonebmute = ZoneBMute.ON
connection.put.assert_called_with(SUBUNIT, "ZONEBMUTE", "On")
initialized_zone.zonebmute = ZoneBMute.OFF
connection.put.assert_called_with(SUBUNIT, "ZONEBMUTE", "Off")

# Updates from device
connection.send_protocol_message(SUBUNIT, "ZONEBMUTE", "On")
assert initialized_zone.zonebmute is ZoneBMute.ON
connection.send_protocol_message(SUBUNIT, "ZONEBMUTE", "Off")
assert initialized_zone.zonebmute is ZoneBMute.OFF


def test_volume(connection, initialized_zone: ZoneBase):
# Writing to device

Expand Down Expand Up @@ -249,6 +284,60 @@ def test_volume(connection, initialized_zone: ZoneBase):
assert initialized_zone.vol == -10


def test_zoneb_volume(connection, initialized_zone: Main):
# Writing to device

# Positive with step rounding
initialized_zone.zonebvol = 0
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "0.0")
initialized_zone.zonebvol = 0.1
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "0.0")
initialized_zone.zonebvol = 0.4
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "0.5")

# Negative with step rounding
initialized_zone.zonebvol = -5
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "-5.0")
initialized_zone.zonebvol = -0.5
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "-0.5")
initialized_zone.zonebvol = -0.4
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "-0.5")
initialized_zone.zonebvol = -0.1
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "0.0")

# Up
initialized_zone.zonebvol_up()
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "Up")
initialized_zone.zonebvol_up(1)
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "Up 1 dB")
initialized_zone.zonebvol_up(2)
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "Up 2 dB")
initialized_zone.zonebvol_up(5)
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "Up 5 dB")
initialized_zone.zonebvol_up(50)
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "Up")

# Down
initialized_zone.zonebvol_down()
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "Down")
initialized_zone.zonebvol_down(1)
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "Down 1 dB")
initialized_zone.zonebvol_down(2)
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "Down 2 dB")
initialized_zone.zonebvol_down(5)
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "Down 5 dB")
initialized_zone.zonebvol_down(50)
connection.put.assert_called_with(SUBUNIT, "ZONEBVOL", "Down")

# Updates from device
connection.send_protocol_message(SUBUNIT, "ZONEBVOL", "0.0")
assert initialized_zone.zonebvol == 0
connection.send_protocol_message(SUBUNIT, "ZONEBVOL", "10.0")
assert initialized_zone.zonebvol == 10
connection.send_protocol_message(SUBUNIT, "ZONEBVOL", "-10.0")
assert initialized_zone.zonebvol == -10


def test_maxvol(connection, initialized_zone: ZoneBase):
# Writing to device

Expand Down Expand Up @@ -346,6 +435,18 @@ def test_zonename(connection, initialized_zone: ZoneBase):
assert initialized_zone.zonename == "updated"


def test_zonebname(connection, initialized_zone: Main):
# Writing to device
initialized_zone.zonebname = "new name"
connection.put.assert_called_with(SUBUNIT, "ZONEBNAME", "new name")
with pytest.raises(ValueError):
initialized_zone.zonebname = "new name is too long"

# Updates from device
connection.send_protocol_message(SUBUNIT, "ZONEBNAME", "updated")
assert initialized_zone.zonebname == "updated"


def test_twochdecoder(connection, initialized_zone: ZoneBase):
# Writing to device
initialized_zone.twochdecoder = TwoChDecoder.DolbyPl
Expand Down Expand Up @@ -447,3 +548,28 @@ def test_lipsynchdmioutoffset(connection, initialized_zone: ZoneBase):
assert initialized_zone.lipsynchdmiout2offset == 250
connection.send_protocol_message(SUBUNIT, "LIPSYNCHDMIOUT2OFFSET", "-250")
assert initialized_zone.lipsynchdmiout2offset == -250

def test_speaker_ab(connection, initialized_zone: Main):
# Writing to device
initialized_zone.speakera = SpeakerA.ON
connection.put.assert_called_with(SUBUNIT, "SPEAKERA", "On")
initialized_zone.speakera = SpeakerA.OFF
connection.put.assert_called_with(SUBUNIT, "SPEAKERA", "Off")

# Updates from device
connection.send_protocol_message(SUBUNIT, "SPEAKERA", "On")
assert initialized_zone.speakera is SpeakerA.ON
connection.send_protocol_message(SUBUNIT, "SPEAKERA", "Off")
assert initialized_zone.speakera is SpeakerA.OFF

# Writing to device
initialized_zone.speakerb = SpeakerB.ON
connection.put.assert_called_with(SUBUNIT, "SPEAKERB", "On")
initialized_zone.speakerb = SpeakerB.OFF
connection.put.assert_called_with(SUBUNIT, "SPEAKERB", "Off")

# Updates from device
connection.send_protocol_message(SUBUNIT, "SPEAKERB", "On")
assert initialized_zone.speakerb is SpeakerB.ON
connection.send_protocol_message(SUBUNIT, "SPEAKERB", "Off")
assert initialized_zone.speakerb is SpeakerB.OFF
2 changes: 1 addition & 1 deletion ynca/subunits/zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def scene(self, scene_id: int | str):
self._put("SCENE", f"Scene {scene_id}")

def vol_up(self, step_size: float = 0.5):
do_vol_up(self, step_size = 0.5, function="VOL")
do_vol_up(self, step_size = step_size, function="VOL")

def vol_down(self, step_size: float = 0.5):
do_vol_down(self, step_size, function="VOL")
Expand Down

0 comments on commit 08fcac1

Please sign in to comment.