Skip to content

Commit

Permalink
Add a supports_play_method
Browse files Browse the repository at this point in the history
This allows us to discover if a given Play method works for a given
Source via the features in desc.xml. It's done with some kind of
complex xpath, broken into parts, to make it a bit easier to read.

Tests include.
  • Loading branch information
sdague committed Nov 10, 2016
1 parent 07b4f37 commit 2e951d6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
18 changes: 18 additions & 0 deletions rxv/rxv.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,24 @@ def supports_method(self, source, *args):
return True
return False

def supports_play_method(self, source, method):
# if there was a complete xpath implementation we could do
# this all with xpath, but without it it's lots of
# iteration. This is probably not worth optimizing, these
# loops are cheep in the long run.
source_xml = self._desc_xml.find('.//*[@YNC_Tag="%s"]' % source)
if source_xml is None:
return False

play_control = source_xml.find('.//*[@Func="Play_Control"]')
if play_control is None:
return False

supports = play_control.find('.//Put_1[@Func="%s"]' % method)
if supports is None:
return False
return True

def _src_name(self, cur_input):
if cur_input not in self.inputs():
return None
Expand Down
16 changes: 16 additions & 0 deletions tests/test_feature_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,19 @@ def test_supports_method(self):
self.assertTrue(rec.supports_method("Tuner", "Config"))
self.assertFalse(
rec.supports_method("Tuner", "Play_Control", "Playback"))

def test_supports_play_method(self):
rec = self.rec
self.assertFalse(rec.supports_play_method("NET_RADIO", "Pause"))
self.assertTrue(rec.supports_play_method("NET_RADIO", "Play"))
self.assertTrue(rec.supports_play_method("NET_RADIO", "Stop"))
# Plus_1 / Minus_1 are the FF and RW methods in the xml api
self.assertFalse(rec.supports_play_method("NET_RADIO", "Plus_1"))
self.assertFalse(rec.supports_play_method("NET_RADIO", "Minus_1"))

self.assertTrue(rec.supports_play_method("SERVER", "Pause"))
self.assertTrue(rec.supports_play_method("SERVER", "Play"))
self.assertTrue(rec.supports_play_method("SERVER", "Stop"))
# Plus_1 / Minus_1 are the FF and RW methods in the xml api
self.assertTrue(rec.supports_play_method("SERVER", "Plus_1"))
self.assertTrue(rec.supports_play_method("SERVER", "Minus_1"))

0 comments on commit 2e951d6

Please sign in to comment.