blob: 96d54bc464d6bf3410ea63f1bfc2a8ca076f7c5f [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 pprint
11
12from gi.repository import GLib
13glib_main_loop = GLib.MainLoop()
14glib_main_ctx = glib_main_loop.get_context()
15
16def propchanged(*args, **kwargs):
17 print('-> PROP CHANGED: %r %r' % (args, kwargs))
18
19
20def pump():
21 global glib_main_ctx
22 print('pump?')
23 while glib_main_ctx.pending():
24 print('* pump')
25 glib_main_ctx.iteration()
26
27def wait(condition):
28 pump()
29 while not condition():
30 time.sleep(.1)
31 pump()
32
33bus = SystemBus()
34
35print('\n- list modems')
36root = bus.get("org.ofono", '/')
37print(root.Introspect())
38modems = sorted(root.GetModems())
39pprint.pprint(modems)
40pump()
41
42first_modem_path = modems[0][0]
43print('\n- first modem %r' % first_modem_path)
44modem = bus.get("org.ofono", first_modem_path)
45modem.PropertyChanged.connect(propchanged)
46
47print(modem.Introspect())
48print(modem.GetProperties())
49
50print('\n- set Powered = True')
51modem.SetProperty('Powered', Variant('b', True))
52print('call returned')
53print('- pump dbus events')
54pump()
55pump()
56print('sleep 1')
57time.sleep(1)
58pump()
59
60
61print('- modem properties:')
62print(modem.GetProperties())
63
64
65print('\n- set Powered = False')
66modem.SetProperty('Powered', Variant('b', False))
67print('call returned')
68
69print(modem.GetProperties())
70
71# vim: tabstop=4 shiftwidth=4 expandtab