aboutsummaryrefslogtreecommitdiffstats
path: root/selftest/dbus_test/ofono_client.py
blob: 6b60f981e022f2f7c8191a3c6bf12520b6298694 (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
#!/usr/bin/env python3

'''
Power on and off some modem on ofono, while running the glib main loop in a
thread and receiving modem state changes by dbus signals.
'''

from pydbus import SystemBus, Variant
import time
import threading
import pprint

from gi.repository import GLib
loop = GLib.MainLoop()

def propchanged(*args, **kwargs):
        print('-> PROP CHANGED: %r %r' % (args, kwargs))

class GlibMainloop(threading.Thread):
        def run(self):
                loop.run()

ml = GlibMainloop()
ml.start()

try:
        bus = SystemBus()

        print('\n- list modems')
        root = bus.get("org.ofono", '/')
        print(root.Introspect())
	modems = sorted(root.GetModems())
        pprint.pprint(modems)

        first_modem_path = modems[0][0]
        print('\n- first modem %r' % first_modem_path)
        modem = bus.get("org.ofono", first_modem_path)
        modem.PropertyChanged.connect(propchanged)

        print(modem.Introspect())
        print(modem.GetProperties())

        print('\n- set Powered = True')
        modem.SetProperty('Powered', Variant('b', True))
        print('call returned')
        print(modem.GetProperties())

        time.sleep(1)

        print('\n- set Powered = False')
        modem.SetProperty('Powered', Variant('b', False))
        print('call returned')

        print(modem.GetProperties())
finally:
        loop.quit()
ml.join()