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.

50 lines
1.8 KiB

4 years ago
  1. """Discover Songpal devices."""
  2. import logging
  3. from . import SSDPDiscoverable
  4. from . import ATTR_PROPERTIES
  5. class Discoverable(SSDPDiscoverable):
  6. """Support for Songpal devices.
  7. Supported devices: http://vssupport.sony.net/en_ww/device.html."""
  8. def get_entries(self):
  9. """Get all the Songpal devices."""
  10. devs = self.find_by_st(
  11. "urn:schemas-sony-com:service:ScalarWebAPI:1")
  12. # At least some Bravia televisions use this API for communication.
  13. # Based on some examples they always seem to lack modelNumber,
  14. # so we use it here to keep them undiscovered for now.
  15. non_bravias = []
  16. for dev in devs:
  17. if 'device' in dev.description:
  18. device = dev.description['device']
  19. if 'modelNumber' in device:
  20. non_bravias.append(dev)
  21. return non_bravias
  22. def info_from_entry(self, entry):
  23. """Get information for a device.."""
  24. info = super().info_from_entry(entry)
  25. cached_descs = entry.DESCRIPTION_CACHE[entry.location]
  26. device_info_element = "X_ScalarWebAPI_DeviceInfo"
  27. baseurl_element = "X_ScalarWebAPI_BaseURL"
  28. device_element = "device"
  29. if device_element in cached_descs and \
  30. device_info_element in cached_descs[device_element]:
  31. scalarweb = cached_descs[device_element][device_info_element]
  32. properties = {"scalarwebapi": scalarweb}
  33. if baseurl_element in scalarweb:
  34. properties["endpoint"] = scalarweb[baseurl_element]
  35. else:
  36. logging.warning("Unable to find %s", baseurl_element)
  37. info[ATTR_PROPERTIES] = properties
  38. else:
  39. logging.warning("Unable to find ScalarWeb element from desc.")
  40. return info