Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | ''' |
| 4 | Power on and off some modem on ofono, while running the glib main loop in a |
| 5 | thread and receiving modem state changes by dbus signals. |
| 6 | ''' |
| 7 | |
| 8 | from pydbus import SystemBus, Variant |
| 9 | import time |
| 10 | import threading |
| 11 | import pprint |
| 12 | |
| 13 | from gi.repository import GLib |
| 14 | loop = GLib.MainLoop() |
| 15 | |
| 16 | def propchanged(*args, **kwargs): |
| 17 | print('-> PROP CHANGED: %r %r' % (args, kwargs)) |
| 18 | |
| 19 | class GlibMainloop(threading.Thread): |
| 20 | def run(self): |
| 21 | loop.run() |
| 22 | |
| 23 | ml = GlibMainloop() |
| 24 | ml.start() |
| 25 | |
| 26 | try: |
| 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()) |
| 55 | finally: |
| 56 | loop.quit() |
| 57 | ml.join() |