Skip to content

Commit

Permalink
Merge pull request #80 from jschmer/surround-prog-no-direct
Browse files Browse the repository at this point in the history
Fix surround programs on AVRs without direct mode
  • Loading branch information
wuub authored Jan 25, 2021
2 parents 4858e3c + 7554b66 commit da90b75
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pip-log.txt
# Unit test / coverage reports
.coverage
.tox
coverage.xml
nosetests.xml

# Translations
Expand Down
16 changes: 13 additions & 3 deletions rxv/rxv.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,12 @@ def _find_commands(self, cmd_name):

@property
def direct_mode(self):
assert DIRECT in self.surround_programs()
"""
Current state of direct mode.
"""
if DIRECT not in self.surround_programs():
return False

request_text = DirectMode.format(parameter="<Mode>GetParam</Mode>")
response = self._request('GET', request_text)
direct = response.find(
Expand All @@ -347,9 +352,14 @@ def direct_mode(self):
return direct

@direct_mode.setter
def direct_mode(self, mode):
def direct_mode(self, on):
"""
Enable/Disable direct mode.
Precondition: DIRECT mode is supported, raises AssertionError otherwise.
"""
assert DIRECT in self.surround_programs()
if mode:
if on:
request_text = DirectMode.format(parameter="<Mode>On</Mode>")
else:
request_text = DirectMode.format(parameter="<Mode>Off</Mode>")
Expand Down
10 changes: 10 additions & 0 deletions tests/check_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,13 @@ def test_fade():
assert rx.volume == -48
rx.volume_fade(-51)
assert rx.volume == -51


def test_direct_mode():
if "Direct" in rx.surround_programs():
rx.surround_program = "Drama"
assert "Drama" == rx.surround_program
rx.surround_program = "Direct"
assert "Direct" == rx.surround_program
rx.surround_program = "Straight"
assert "Straight" == rx.surround_program
1 change: 1 addition & 0 deletions tests/samples/rx-v479-get-directmode-off-resp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<YAMAHA_AV rsp="GET" RC="0"><Main_Zone><Sound_Video><Direct><Mode>Off</Mode></Direct></Sound_Video></Main_Zone></YAMAHA_AV>
1 change: 1 addition & 0 deletions tests/samples/rx-v479-get-directmode-on-resp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<YAMAHA_AV rsp="GET" RC="0"><Main_Zone><Sound_Video><Direct><Mode>On</Mode></Direct></Sound_Video></Main_Zone></YAMAHA_AV>
1 change: 1 addition & 0 deletions tests/samples/rx-v479-get-surround-program-drama-resp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<YAMAHA_AV rsp="GET" RC="0"><Main_Zone><Surround><Program_Sel><Current><Straight>Off</Straight><Enhancer>Off</Enhancer><Sound_Program>Drama</Sound_Program></Current></Program_Sel></Surround></Main_Zone></YAMAHA_AV>
1 change: 1 addition & 0 deletions tests/samples/rx-v479-put-directmode-resp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<YAMAHA_AV rsp="PUT" RC="0"><Main_Zone><Sound_Video><Direct><Mode /></Direct></Sound_Video></Main_Zone></YAMAHA_AV>
1 change: 1 addition & 0 deletions tests/samples/rx-v675-get-surround-program-drama-resp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<YAMAHA_AV rsp="GET" RC="0"><Main_Zone><Surround><Program_Sel><Current><Straight>Off</Straight><Enhancer>Off</Enhancer><Sound_Program>Drama</Sound_Program></Current></Program_Sel></Surround></Main_Zone></YAMAHA_AV>
43 changes: 43 additions & 0 deletions tests/test_surround.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,46 @@ def test_surround(self, m):
self.assertIn("Drama", surround)
self.assertIn("Direct", surround)
self.assertIn("Straight", surround)

@requests_mock.mock()
def test_direct_available(self, m):
# request order for CTRL_URL:
# 1. assert "Drama" == rec.surround_program
# 1.1 request for GET direct mode
# 1.2 request for GET surround program
# 2. rec.direct_mode = True
# 2.1 request for PUT direct mode = true
# 3. assert True == rec.direct_mode
# 3.1 request for GET direct mode
# 4. assert "Direct" == rec.surround_program
# 4.1 request for GET direct mode (reuses last entry in list)
responses = [
{'text': sample_content("rx-v479-get-directmode-off-resp.xml")},
{'text': sample_content("rx-v479-get-surround-program-drama-resp.xml")},
{'text': sample_content("rx-v479-put-directmode-resp.xml")},
{'text': sample_content("rx-v479-get-directmode-on-resp.xml")},
]

m.get(DESC_XML, text=sample_content('rx-v479-desc.xml'))
m.post(CTRL_URL, responses)

rec = rxv.RXV(CTRL_URL)
surround = rec.surround_programs()
self.assertIn("Direct", surround)

self.assertEqual("Drama", rec.surround_program)
rec.surround_program = "Direct"
self.assertTrue(rec.direct_mode)
self.assertEqual("Direct", rec.surround_program)

@requests_mock.mock()
def test_direct_notavailable(self, m):
m.get(DESC_XML, text=sample_content('rx-v675-desc.xml'))
m.post(CTRL_URL, text=sample_content("rx-v675-get-surround-program-drama-resp.xml"))
rec = rxv.RXV(CTRL_URL)
surround = rec.surround_programs()
self.assertNotIn("Direct", surround)
self.assertEqual("Drama", rec.surround_program)
self.assertFalse(rec.direct_mode)
with self.assertRaises(AssertionError):
rec.direct_mode = True

0 comments on commit da90b75

Please sign in to comment.