Merge with lastest private git
[framework/connectivity/bluez.git] / test / list-devices
1 #!/usr/bin/python
2
3 import dbus
4
5 bus = dbus.SystemBus()
6
7 manager = dbus.Interface(bus.get_object("org.bluez", "/"),
8                                                 "org.bluez.Manager")
9
10 def extract_objects(object_list):
11         list = ""
12         for object in object_list:
13                 val = str(object)
14                 list = list + val[val.rfind("/") + 1:] + " "
15         return list
16
17 def extract_uuids(uuid_list):
18         list = ""
19         for uuid in uuid_list:
20                 if (uuid.endswith("-0000-1000-8000-00805f9b34fb")):
21                         if (uuid.startswith("0000")):
22                                 val = "0x" + uuid[4:8]
23                         else:
24                                 val = "0x" + uuid[0:8]
25                 else:
26                         val = str(uuid)
27                 list = list + val + " "
28         return list
29
30 adapter_list = manager.ListAdapters()
31
32 for i in adapter_list:
33         adapter = dbus.Interface(bus.get_object("org.bluez", i),
34                                                         "org.bluez.Adapter")
35         print "[ " + i + " ]"
36
37         properties  = adapter.GetProperties()
38         for key in properties.keys():
39                 value = properties[key]
40                 if (key == "Devices"):
41                         list = extract_objects(value)
42                         print "    %s = %s" % (key, list)
43                 elif (key == "UUIDs"):
44                         list = extract_uuids(value)
45                         print "    %s = %s" % (key, list)
46                 else:
47                         print "    %s = %s" % (key, value)
48
49         try:
50                 device_list = properties["Devices"]
51         except:
52                 device_list = []
53
54         for n in device_list:
55                 device = dbus.Interface(bus.get_object("org.bluez", n),
56                                                         "org.bluez.Device")
57                 print "    [ " + n + " ]"
58
59                 properties = device.GetProperties()
60                 for key in properties.keys():
61                         value = properties[key]
62                         if (key == "Nodes"):
63                                 list = extract_objects(value)
64                                 print "        %s = %s" % (key, list)
65                         elif (key == "UUIDs"):
66                                 list = extract_uuids(value)
67                                 print "        %s = %s" % (key, list)
68                         elif (key == "Class"):
69                                 print "        %s = 0x%06x" % (key, value)
70                         elif (key == "Vendor"):
71                                 print "        %s = 0x%04x" % (key, value)
72                         elif (key == "Product"):
73                                 print "        %s = 0x%04x" % (key, value)
74                         elif (key == "Version"):
75                                 print "        %s = 0x%04x" % (key, value)
76                         else:
77                                 print "        %s = %s" % (key, value)
78
79                 try:
80                         node_list = properties["Nodes"]
81                 except:
82                         node_list = []
83
84                 for x in node_list:
85                         node = dbus.Interface(bus.get_object("org.bluez", x),
86                                                         "org.bluez.Node")
87                         print "        [ " + x + " ]"
88
89                         properties = node.GetProperties()
90                         for key in properties.keys():
91                                 print "            %s = %s" % (key, properties[key])
92
93         print