You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.5 KiB

4 years ago
  1. """Discover Yamaha Receivers."""
  2. from . import SSDPDiscoverable
  3. class Discoverable(SSDPDiscoverable):
  4. """Add support for discovering Yamaha Receivers."""
  5. INCOMPATIBLE_MODELS = set('N301')
  6. REMOTE_CONTROL_SPEC_TYPE =\
  7. 'urn:schemas-yamaha-com:service:X_YamahaRemoteControl:1'
  8. def info_from_entry(self, entry):
  9. """Return the most important info from a uPnP entry."""
  10. info = super().info_from_entry(entry)
  11. yam = entry.description['X_device']
  12. services = yam['X_serviceList']['X_service']
  13. if isinstance(services, list):
  14. service = next(
  15. (s for s in services
  16. if s['X_specType'] == self.REMOTE_CONTROL_SPEC_TYPE),
  17. services[0])
  18. else:
  19. service = services
  20. # do a slice of the second element so we don't have double /
  21. info['control_url'] = yam['X_URLBase'] + service['X_controlURL'][1:]
  22. info['description_url'] = (yam['X_URLBase'] +
  23. service['X_unitDescURL'][1:])
  24. return info
  25. def get_entries(self):
  26. """Get all the Yamaha uPnP entries."""
  27. devices = self.find_by_device_description({
  28. "manufacturer": "Yamaha Corporation",
  29. "deviceType": "urn:schemas-upnp-org:device:MediaRenderer:1"
  30. })
  31. return [device for device in devices if
  32. device.description['device'].get('modelNumber', '') not in
  33. self.INCOMPATIBLE_MODELS]