Upgrade ofono to 1.2
[profile/ivi/ofono.git] / test / initiate-ussd
1 #!/usr/bin/python
2
3 import sys
4 import dbus
5
6 if (len(sys.argv) < 2):
7         print "Usage: %s [modem] <ussd-string>" % (sys.argv[0])
8         sys.exit(1)
9
10 bus = dbus.SystemBus()
11
12 manager = dbus.Interface(bus.get_object('org.ofono', '/'),
13                                                 'org.ofono.Manager')
14
15 modems = manager.GetModems()
16
17 if (len(sys.argv) == 2):
18         path = modems[0][0]
19         ussdstring = sys.argv[1]
20 else:
21         path = sys.argv[1]
22         ussdstring = sys.argv[2]
23
24 ussd = dbus.Interface(bus.get_object('org.ofono', path),
25                                         'org.ofono.SupplementaryServices')
26
27 properties = ussd.GetProperties()
28 state = properties["State"]
29
30 print "State: %s" % (state)
31
32 if state != "idle":
33         sys.exit(1);
34
35 result = ussd.Initiate(ussdstring, timeout=100)
36
37 properties = ussd.GetProperties()
38 state = properties["State"]
39
40 print result[0] + ": " + result[1]
41
42 if state == "idle":
43         sys.exit(0)
44
45 print "State: %s" % (state)
46
47 while state == "user-response":
48         response = raw_input("Enter response: ")
49
50         result = ussd.Respond(response, timeout=100)
51
52         properties = ussd.GetProperties()
53         state = properties["State"]
54
55         print result
56
57         if state != "idle":
58                 print "State: %s" % (state)