Home | History | Annotate | Download | only in test
      1 #!/usr/bin/python
      2 
      3 import sys
      4 import dbus
      5 from optparse import OptionParser, make_option
      6 
      7 bus = dbus.SystemBus()
      8 
      9 manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
     10 
     11 option_list = [
     12 		make_option("-i", "--device", action="store",
     13 				type="string", dest="dev_id"),
     14 		]
     15 parser = OptionParser(option_list=option_list)
     16 
     17 (options, args) = parser.parse_args()
     18 
     19 if options.dev_id:
     20 	adapter_path = manager.FindAdapter(options.dev_id)
     21 else:
     22 	adapter_path = manager.DefaultAdapter()
     23 
     24 adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
     25 							"org.bluez.Adapter")
     26 
     27 if len(args) < 2:
     28 	print """Usage: %s <command>
     29 
     30 	connect <bdaddr>
     31 	disconnect <bdaddr>
     32 	""" % sys.argv[0]
     33 	sys.exit(1)
     34 
     35 device = adapter.FindDevice(args[1])
     36 audio = dbus.Interface(bus.get_object("org.bluez", device),
     37 				"org.bluez.Audio")
     38 
     39 if args[0] == "connect":
     40 	audio.Connect()
     41 elif args[0] == "disconnect":
     42 	audio.Disconnect()
     43 else:
     44 	print "Unknown command"
     45 	sys.exit(1)
     46