diff options
author | Ruben Undheim <ruben.undheim@gmail.com> | 2018-12-21 21:01:06 +0100 |
---|---|---|
committer | Ruben Undheim <ruben.undheim@gmail.com> | 2018-12-21 21:01:06 +0100 |
commit | d41ea366e7c2e51c9f7e68092d89e3f0be580362 (patch) | |
tree | 949fd6476faf99d225a5787356a48b54b8b15192 /netdisco/discoverables/yamaha.py |
Import python-netdisco_2.2.0.orig.tar.gz
[dgit import orig python-netdisco_2.2.0.orig.tar.gz]
Diffstat (limited to 'netdisco/discoverables/yamaha.py')
-rw-r--r-- | netdisco/discoverables/yamaha.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/netdisco/discoverables/yamaha.py b/netdisco/discoverables/yamaha.py new file mode 100644 index 0000000..7361818 --- /dev/null +++ b/netdisco/discoverables/yamaha.py @@ -0,0 +1,42 @@ +"""Discover Yamaha Receivers.""" +from . import SSDPDiscoverable + + +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' + + def info_from_entry(self, entry): + """Return the most important info from a uPnP entry.""" + info = super().info_from_entry(entry) + + yam = entry.description['X_device'] + services = yam['X_serviceList']['X_service'] + if isinstance(services, list): + service = next( + (s for s in services + if s['X_specType'] == self.REMOTE_CONTROL_SPEC_TYPE), + services[0]) + else: + service = services + # do a slice of the second element so we don't have double / + info['control_url'] = yam['X_URLBase'] + service['X_controlURL'][1:] + info['description_url'] = (yam['X_URLBase'] + + service['X_unitDescURL'][1:]) + + return info + + def get_entries(self): + """Get all the Yamaha uPnP entries.""" + 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] |