blob: 6b60f981e022f2f7c8191a3c6bf12520b6298694 [file] [log] [blame]
Neels Hofmeyr3531a192017-03-28 14:30:28 +02001#!/usr/bin/env python3
2
3'''
4Power on and off some modem on ofono, while running the glib main loop in a
5thread and receiving modem state changes by dbus signals.
6'''
7
8from pydbus import SystemBus, Variant
9import time
10import threading
11import pprint
12
13from gi.repository import GLib
14loop = GLib.MainLoop()
15
16def propchanged(*args, **kwargs):
17 print('-> PROP CHANGED: %r %r' % (args, kwargs))
18
19class GlibMainloop(threading.Thread):
20 def run(self):
21 loop.run()
22
23ml = GlibMainloop()
24ml.start()
25
26try:
27 bus = SystemBus()
28
29 print('\n- list modems')
30 root = bus.get("org.ofono", '/')
31 print(root.Introspect())
32 modems = sorted(root.GetModems())
33 pprint.pprint(modems)
34
35 first_modem_path = modems[0][0]
36 print('\n- first modem %r' % first_modem_path)
37 modem = bus.get("org.ofono", first_modem_path)
38 modem.PropertyChanged.connect(propchanged)
39
40 print(modem.Introspect())
41 print(modem.GetProperties())
42
43 print('\n- set Powered = True')
44 modem.SetProperty('Powered', Variant('b', True))
45 print('call returned')
46 print(modem.GetProperties())
47
48 time.sleep(1)
49
50 print('\n- set Powered = False')
51 modem.SetProperty('Powered', Variant('b', False))
52 print('call returned')
53
54 print(modem.GetProperties())
55finally:
56 loop.quit()
57ml.join()