bluez/test/list-devices
Gustavo Padovan 91b9c50aa4 Remove documentation about Node API
Node API was never implemented.
2012-07-19 10:42:20 +03:00

78 lines
1.9 KiB
Python
Executable File

#!/usr/bin/python
from __future__ import absolute_import, print_function, unicode_literals
import dbus
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object("org.bluez", "/"),
"org.bluez.Manager")
def extract_objects(object_list):
list = ""
for object in object_list:
val = str(object)
list = list + val[val.rfind("/") + 1:] + " "
return list
def extract_uuids(uuid_list):
list = ""
for uuid in uuid_list:
if (uuid.endswith("-0000-1000-8000-00805f9b34fb")):
if (uuid.startswith("0000")):
val = "0x" + uuid[4:8]
else:
val = "0x" + uuid[0:8]
else:
val = str(uuid)
list = list + val + " "
return list
adapter_list = manager.GetProperties()["Adapters"]
for i in adapter_list:
adapter = dbus.Interface(bus.get_object("org.bluez", i),
"org.bluez.Adapter")
print("[ " + i + " ]")
properties = adapter.GetProperties()
for key in properties.keys():
value = properties[key]
if (key == "Devices"):
list = extract_objects(value)
print(" %s = %s" % (key, list))
elif (key == "UUIDs"):
list = extract_uuids(value)
print(" %s = %s" % (key, list))
else:
print(" %s = %s" % (key, value))
try:
device_list = properties["Devices"]
except:
device_list = []
for n in device_list:
device = dbus.Interface(bus.get_object("org.bluez", n),
"org.bluez.Device")
print(" [ " + n + " ]")
properties = device.GetProperties()
for key in properties.keys():
value = properties[key]
if (key == "UUIDs"):
list = extract_uuids(value)
print(" %s = %s" % (key, list))
elif (key == "Class"):
print(" %s = 0x%06x" % (key, value))
elif (key == "Vendor"):
print(" %s = 0x%04x" % (key, value))
elif (key == "Product"):
print(" %s = 0x%04x" % (key, value))
elif (key == "Version"):
print(" %s = 0x%04x" % (key, value))
else:
print(" %s = %s" % (key, value))
print("")