3 A simpe client for an onoff device. If no parameters are given, the device
4 is activated for 10 seconds. When a command is given, the device is activated,
5 then the command is run. 10 seconds after the command finishes, the device is
12 from dbus.mainloop.glib import DBusGMainLoop
13 from gi.repository import GObject
15 from onoff.common import ST_ACTIVE
16 import onoff.dbusutils
18 def wait_for_signal(proxy, signal):
19 loop = GObject.MainLoop()
24 proxy.connect_to_signal(signal, callback)
29 parser = argparse.ArgumentParser(parents=[onoff.dbusutils.dbus_options])
30 parser.add_argument("command", nargs=argparse.REMAINDER)
31 args = parser.parse_args()
32 DBusGMainLoop(set_as_default=True)
33 proxy = onoff.dbusutils.get_dbus_proxy(args)
35 st, fd = proxy.activatefd(10)
40 print("state is %d waiting for signal" % st)
41 st = wait_for_signal(proxy, "changestate")
42 print("new state is %d" % st)
43 os.execvp(args.command[0], args.command)
45 st = proxy.activatetime(10)
47 print("state is %d waiting for signal" % st)
48 st = wait_for_signal(proxy, "changestate")
49 print("new state is %d" % st)
51 if __name__ == "__main__":