3 from __future__ import absolute_import, print_function, unicode_literals
7 from optparse import OptionParser, make_option
11 manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
14 make_option("-i", "--device", action="store",
15 type="string", dest="dev_id"),
17 parser = OptionParser(option_list=option_list)
19 (options, args) = parser.parse_args()
22 adapter_path = manager.FindAdapter(options.dev_id)
24 adapter_path = manager.DefaultAdapter()
26 adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
29 test = dbus.Interface(bus.get_object("org.bluez", "/org/bluez/test"),
30 "org.bluez.TelephonyTest")
33 print("""Usage: %s <command>
45 speakergain <bdaddr> [level]
46 microphonegain <bdaddr> [level]
52 if args[0] == "connect":
54 print("Need device address parameter")
56 device = adapter.FindDevice(args[1])
57 headset = dbus.Interface(bus.get_object("org.bluez", device),
62 if args[0] == "disconnect":
64 print("Need device address parameter")
66 device = adapter.FindDevice(args[1])
67 headset = dbus.Interface(bus.get_object("org.bluez", device),
72 if args[0] == "speakergain":
74 print("Need device address parameter")
76 device = adapter.FindDevice(args[1])
77 headset = dbus.Interface(bus.get_object("org.bluez", device),
80 headset.SetProperty('SpeakerGain', dbus.UInt16(args[2]))
82 props = headset.GetProperties()
83 print(props['SpeakerGain'])
87 if args[0] == "microphonegain":
89 print("Need device address parameter")
91 device = adapter.FindDevice(args[1])
92 headset = dbus.Interface(bus.get_object("org.bluez", device),
95 headset.SetProperty('MicrophoneGain', dbus.UInt16(args[2]))
97 props = headset.GetProperties()
98 print(props['MicrophoneGain'])
102 if args[0] == "play":
104 print("Need device address parameter")
106 device = adapter.FindDevice(args[1])
107 headset = dbus.Interface(bus.get_object("org.bluez", device),
113 if args[0] == "stop":
115 print("Need device address parameter")
117 device = adapter.FindDevice(args[1])
118 headset = dbus.Interface(bus.get_object("org.bluez", device),
124 if args[0] == "outgoing":
126 test.OutgoingCall(args[1])
128 print("Need number parameter")
131 if args[0] == "incoming":
133 test.IncomingCall(args[1])
135 print("Need number parameter")
138 if args[0] == "cancel":
142 if args[0] == "signal":
144 test.SignalStrength(args[1])
146 print("Need signal strength parameter")
149 if args[0] == "battery":
151 test.BatteryLevel(args[1])
153 print("Need battery level parameter")
156 if args[0] == "roaming":
158 test.RoamingStatus(args[1] == "yes" or False)
160 print("Need yes/no parameter")
163 if args[0] == "registration":
165 test.RegistrationStatus(args[1] == "yes" or False)
167 print("Need yes/no parameter")
170 if args[0] == "subscriber":
172 test.SetSubscriberNumber(args[1])
174 print("Need number parameter")
177 print("Unknown command")