list-devices 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/python
  2. # SPDX-License-Identifier: LGPL-2.1-or-later
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import dbus
  5. bus = dbus.SystemBus()
  6. manager = dbus.Interface(bus.get_object("org.bluez", "/"),
  7. "org.freedesktop.DBus.ObjectManager")
  8. def extract_objects(object_list):
  9. list = ""
  10. for object in object_list:
  11. val = str(object)
  12. list = list + val[val.rfind("/") + 1:] + " "
  13. return list
  14. def extract_uuids(uuid_list):
  15. list = ""
  16. for uuid in uuid_list:
  17. if (uuid.endswith("-0000-1000-8000-00805f9b34fb")):
  18. if (uuid.startswith("0000")):
  19. val = "0x" + uuid[4:8]
  20. else:
  21. val = "0x" + uuid[0:8]
  22. else:
  23. val = str(uuid)
  24. list = list + val + " "
  25. return list
  26. objects = manager.GetManagedObjects()
  27. all_devices = (str(path) for path, interfaces in objects.iteritems() if
  28. "org.bluez.Device1" in interfaces.keys())
  29. for path, interfaces in objects.iteritems():
  30. if "org.bluez.Adapter1" not in interfaces.keys():
  31. continue
  32. print("[ " + path + " ]")
  33. properties = interfaces["org.bluez.Adapter1"]
  34. for key in properties.keys():
  35. value = properties[key]
  36. if (key == "UUIDs"):
  37. list = extract_uuids(value)
  38. print(" %s = %s" % (key, list))
  39. else:
  40. print(" %s = %s" % (key, value))
  41. device_list = [d for d in all_devices if d.startswith(path + "/")]
  42. for dev_path in device_list:
  43. print(" [ " + dev_path + " ]")
  44. dev = objects[dev_path]
  45. properties = dev["org.bluez.Device1"]
  46. for key in properties.keys():
  47. value = properties[key]
  48. if (key == "UUIDs"):
  49. list = extract_uuids(value)
  50. print(" %s = %s" % (key, list))
  51. elif (key == "Class"):
  52. print(" %s = 0x%06x" % (key, value))
  53. elif (key == "Vendor"):
  54. print(" %s = 0x%04x" % (key, value))
  55. elif (key == "Product"):
  56. print(" %s = 0x%04x" % (key, value))
  57. elif (key == "Version"):
  58. print(" %s = 0x%04x" % (key, value))
  59. else:
  60. print(" %s = %s" % (key, value))
  61. print("")