3 from __future__ import absolute_import, print_function, unicode_literals
8 from optparse import OptionParser, make_option
10 bus = dbus.SystemBus()
12 manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
15 make_option("-i", "--device", action="store",
16 type="string", dest="dev_id"),
18 parser = OptionParser(option_list=option_list)
20 (options, args) = parser.parse_args()
23 adapter_path = manager.FindAdapter(options.dev_id)
25 adapter_path = manager.DefaultAdapter()
27 adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
31 print("Usage: %s <command>" % (sys.argv[0]))
36 print(" powered [on/off]")
37 print(" pairable [on/off]")
38 print(" pairabletimeout [timeout]")
39 print(" discoverable [on/off]")
40 print(" discoverabletimeout [timeout]")
44 if (args[0] == "address"):
45 properties = adapter.GetProperties()
46 print(properties["Address"])
49 if (args[0] == "name"):
51 properties = adapter.GetProperties()
52 print(properties["Name"])
54 adapter.SetProperty("Name", args[1])
57 if (args[0] == "list"):
59 properties = manager.GetProperties()
60 for adapter_path in properties["Adapters"]:
61 adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
63 prop = adapter.GetProperties()
64 print(" [ %s ]" % (adapter_path))
65 for (key, value) in prop.items():
67 print(" %s = 0x%06x" % (key, value))
69 print(" %s = %s" % (key, value))
73 if (args[0] == "powered"):
75 properties = adapter.GetProperties()
76 print(properties["Powered"])
79 value = dbus.Boolean(1)
80 elif (args[1] == "off"):
81 value = dbus.Boolean(0)
83 value = dbus.Boolean(args[1])
84 adapter.SetProperty("Powered", value)
87 if (args[0] == "pairable"):
89 properties = adapter.GetProperties()
90 print(properties["Pairable"])
93 value = dbus.Boolean(1)
94 elif (args[1] == "off"):
95 value = dbus.Boolean(0)
97 value = dbus.Boolean(args[1])
98 adapter.SetProperty("Pairable", value)
101 if (args[0] == "pairabletimeout"):
103 properties = adapter.GetProperties()
104 print(properties["PairableTimeout"])
106 timeout = dbus.UInt32(args[1])
107 adapter.SetProperty("PairableTimeout", timeout)
110 if (args[0] == "discoverable"):
112 properties = adapter.GetProperties()
113 print(properties["Discoverable"])
115 if (args[1] == "on"):
116 value = dbus.Boolean(1)
117 elif (args[1] == "off"):
118 value = dbus.Boolean(0)
120 value = dbus.Boolean(args[1])
121 adapter.SetProperty("Discoverable", value)
124 if (args[0] == "discoverabletimeout"):
126 properties = adapter.GetProperties()
127 print(properties["DiscoverableTimeout"])
129 timeout = dbus.UInt32(args[1])
130 adapter.SetProperty("DiscoverableTimeout", timeout)
133 if (args[0] == "discovering"):
134 properties = adapter.GetProperties()
135 print(properties["Discovering"])
138 print("Unknown command")