summaryrefslogtreecommitdiffstats
path: root/hcid/test-device
blob: a4dd0969003c50a19be5603ef026884c82ca9435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/python

import sys
import dbus

bus = dbus.SystemBus()

bus = dbus.SystemBus()

manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")

adapter = dbus.Interface(bus.get_object("org.bluez", manager.DefaultAdapter()),
							"org.bluez.Adapter")

if (len(sys.argv) < 2):
	print "Usage: %s <command>" % (sys.argv[0])
	print ""
	print "  list"
	print "  create <address>"
	print "  remove <path>"
	print "  class <address>"
	print "  name <address>"
	print "  alias <address> [alias]"
	print "  trusted <address> [yes/no]"
	sys.exit(1)

if (sys.argv[1] == "list"):
	list = adapter.ListDevices()
	print list
	sys.exit(0)

if (sys.argv[1] == "create"):
	if (len(sys.argv) < 3):
		print "Need address parameter"
	else:
		device = adapter.CreateDevice(sys.argv[2])
		print device
	sys.exit(0)

if (sys.argv[1] == "remove"):
	if (len(sys.argv) < 3):
		print "Need object path parameter"
	else:
		adapter.RemoveDevice(sys.argv[2])
	sys.exit(0)

if (sys.argv[1] == "class"):
	if (len(sys.argv) < 3):
		print "Need address parameter"
	else:
		path = adapter.FindDevice(sys.argv[2])
		device = dbus.Interface(bus.get_object("org.bluez", path),
							"org.bluez.Device")
		properties = device.GetProperties()
		print "0x%06x" % (properties["Class"])
	sys.exit(0)

if (sys.argv[1] == "name"):
	if (len(sys.argv) < 3):
		print "Need address parameter"
	else:
		path = adapter.FindDevice(sys.argv[2])
		device = dbus.Interface(bus.get_object("org.bluez", path),
							"org.bluez.Device")
		properties = device.GetProperties()
		print properties["Name"]
	sys.exit(0)

if (sys.argv[1] == "alias"):
	if (len(sys.argv) < 3):
		print "Need address parameter"
	else:
		path = adapter.FindDevice(sys.argv[2])
		device = dbus.Interface(bus.get_object("org.bluez", path),
							"org.bluez.Device")
		if (len(sys.argv) < 4):
			properties = device.GetProperties()
			print properties["Alias"]
		else:
			device.SetProperty("Alias", sys.argv[3])
	sys.exit(0)

if (sys.argv[1] == "trusted"):
	if (len(sys.argv) < 3):
		print "Need address parameter"
	else:
		path = adapter.FindDevice(sys.argv[2])
		device = dbus.Interface(bus.get_object("org.bluez", path),
							"org.bluez.Device")
		if (len(sys.argv) < 4):
			properties = device.GetProperties()
			print properties["Trusted"]
		else:
			if (sys.argv[2] == "yes"):
				value = dbus.Boolean(1)
			elif (sys.argv[2] == "no"):
				value = dbus.Boolean(0)
			else:
				value = dbus.Boolean(sys.argv[2])
			device.SetProperty("Trusted", value)
	sys.exit(0)

print "Unknown command"
sys.exit(1)