From 2e951d6789ccb11a3d938432daa39f6c73bf3a06 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Thu, 10 Nov 2016 08:06:03 -0500 Subject: [PATCH] Add a supports_play_method 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. --- rxv/rxv.py | 18 ++++++++++++++++++ tests/test_feature_support.py | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/rxv/rxv.py b/rxv/rxv.py index 36a229a..ca7ec55 100644 --- a/rxv/rxv.py +++ b/rxv/rxv.py @@ -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 diff --git a/tests/test_feature_support.py b/tests/test_feature_support.py index ef177ef..4e49fbd 100644 --- a/tests/test_feature_support.py +++ b/tests/test_feature_support.py @@ -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"))