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