6
from optparse import OptionParser, make_option
10
manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
13
make_option("-i", "--device", action="store",
14
type="string", dest="dev_id"),
16
parser = OptionParser(option_list=option_list)
18
(options, args) = parser.parse_args()
21
adapter_path = manager.FindAdapter(options.dev_id)
23
adapter_path = manager.DefaultAdapter()
25
adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
29
print("Usage: %s <command>" % (sys.argv[0]))
34
print(" powered [on/off]")
35
print(" pairable [on/off]")
36
print(" pairabletimeout [timeout]")
37
print(" discoverable [on/off]")
38
print(" discoverabletimeout [timeout]")
42
if (args[0] == "address"):
43
properties = adapter.GetProperties()
44
print(properties["Address"])
47
if (args[0] == "name"):
49
properties = adapter.GetProperties()
50
print(properties["Name"])
52
adapter.SetProperty("Name", args[1])
55
if (args[0] == "list"):
57
properties = manager.GetProperties()
58
for adapter_path in properties["Adapters"]:
59
adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
61
prop = adapter.GetProperties()
62
print(" [ %s ]" % (adapter_path))
63
for (key, value) in prop.items():
65
print(" %s = 0x%06x" % (key, value))
67
print(" %s = %s" % (key, value))
71
if (args[0] == "powered"):
73
properties = adapter.GetProperties()
74
print(properties["Powered"])
77
value = dbus.Boolean(1)
78
elif (args[1] == "off"):
79
value = dbus.Boolean(0)
81
value = dbus.Boolean(args[1])
82
adapter.SetProperty("Powered", value)
85
if (args[0] == "pairable"):
87
properties = adapter.GetProperties()
88
print(properties["Pairable"])
91
value = dbus.Boolean(1)
92
elif (args[1] == "off"):
93
value = dbus.Boolean(0)
95
value = dbus.Boolean(args[1])
96
adapter.SetProperty("Pairable", value)
99
if (args[0] == "pairabletimeout"):
101
properties = adapter.GetProperties()
102
print(properties["PairableTimeout"])
104
timeout = dbus.UInt32(args[1])
105
adapter.SetProperty("PairableTimeout", timeout)
108
if (args[0] == "discoverable"):
110
properties = adapter.GetProperties()
111
print(properties["Discoverable"])
113
if (args[1] == "on"):
114
value = dbus.Boolean(1)
115
elif (args[1] == "off"):
116
value = dbus.Boolean(0)
118
value = dbus.Boolean(args[1])
119
adapter.SetProperty("Discoverable", value)
122
if (args[0] == "discoverabletimeout"):
124
properties = adapter.GetProperties()
125
print(properties["DiscoverableTimeout"])
127
timeout = dbus.UInt32(args[1])
128
adapter.SetProperty("DiscoverableTimeout", timeout)
131
if (args[0] == "discovering"):
132
properties = adapter.GetProperties()
133
print(properties["Discovering"])
136
print("Unknown command")