From acac9472a5825744022de4b20c9a8ad3241c8ff0 Mon Sep 17 00:00:00 2001 From: Daniel Bowman Date: Sat, 18 Aug 2018 10:59:06 +0100 Subject: [PATCH] Ensure N301 player ignored by yamaha discovery as not supported --- netdisco/discoverables/yamaha.py | 8 +++++- tests/discoverables/test_yamaha.py | 14 ++++++++++ .../yamaha_files/desc_incompatible_device.xml | 26 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/discoverables/yamaha_files/desc_incompatible_device.xml diff --git a/netdisco/discoverables/yamaha.py b/netdisco/discoverables/yamaha.py index 7eab1126..73618187 100644 --- a/netdisco/discoverables/yamaha.py +++ b/netdisco/discoverables/yamaha.py @@ -5,6 +5,8 @@ class Discoverable(SSDPDiscoverable): """Add support for discovering Yamaha Receivers.""" + INCOMPATIBLE_MODELS = set('N301') + REMOTE_CONTROL_SPEC_TYPE =\ 'urn:schemas-yamaha-com:service:X_YamahaRemoteControl:1' @@ -30,7 +32,11 @@ def info_from_entry(self, entry): def get_entries(self): """Get all the Yamaha uPnP entries.""" - return self.find_by_device_description({ + devices = self.find_by_device_description({ "manufacturer": "Yamaha Corporation", "deviceType": "urn:schemas-upnp-org:device:MediaRenderer:1" }) + + return [device for device in devices if + device.description['device'].get('modelNumber', '') not in + self.INCOMPATIBLE_MODELS] diff --git a/tests/discoverables/test_yamaha.py b/tests/discoverables/test_yamaha.py index 1f2175d5..687b3e36 100644 --- a/tests/discoverables/test_yamaha.py +++ b/tests/discoverables/test_yamaha.py @@ -1,5 +1,6 @@ """The tests for discovering Yamaha Receivers.""" import unittest +from unittest.mock import MagicMock import xml.etree.ElementTree as ElementTree from netdisco.discoverables.yamaha import Discoverable @@ -107,3 +108,16 @@ def test_info_from_entry_multiple_services_no_remote_control(self): 'udn': None, 'upnp_device_type': None, }) + + def test_get_entries_incompatible_models(self): + supported_model = MockUPNPEntry("desc_multiple_services_no_remote_control.xml") + devices = [ + supported_model, + MockUPNPEntry("desc_incompatible_device.xml") + ] + + discoverable = Discoverable(None) + discoverable.INCOMPATIBLE_MODELS = ["aaa"] + discoverable.find_by_device_description = MagicMock(return_value=devices) + + self.assertEqual(discoverable.get_entries(), [supported_model]) diff --git a/tests/discoverables/yamaha_files/desc_incompatible_device.xml b/tests/discoverables/yamaha_files/desc_incompatible_device.xml new file mode 100644 index 00000000..53127b7a --- /dev/null +++ b/tests/discoverables/yamaha_files/desc_incompatible_device.xml @@ -0,0 +1,26 @@ + + +multi service friendly name +multi service model name +aaa + + +http://192.168.1.2:80/ + + + +urn:schemas-yamaha-com:service:X_YamahaNewControl:1 + +/YamahaNewControl/ctrl +/YamahaNewControl/desc.xml + + + +urn:schemas-yamaha-com:service:X_YamahaExtendedControl:1 + +/YamahaExtendedControl/v1/ +1131 + + + +