use the enum module to represent states
[~helmut/onoff.git] / dbus_client.py
index 1650033..5013f0d 100755 (executable)
@@ -12,7 +12,7 @@ import os
 from dbus.mainloop.glib import DBusGMainLoop
 from gi.repository import GObject
 
-from onoff.common import ST_ACTIVE
+from onoff.common import OnoffState
 import onoff.dbusutils
 
 def wait_for_signal(proxy, signal, desired_state):
@@ -42,20 +42,21 @@ def main():
     elif args.command:
         proxy = onoff.dbusutils.get_dbus_proxy(args)
         st, fd = proxy.activatefd()
+        st = OnoffState(st)
         fd = fd.take()
         os.dup2(fd, 254)
         os.close(fd)
-        if st != ST_ACTIVE:
-            print("state is %d waiting for signal" % st)
-            wait_for_signal(proxy, "changestate", ST_ACTIVE)
+        if st != OnoffState.active:
+            print("state is %s waiting for signal" % st.name)
+            wait_for_signal(proxy, "changestate", OnoffState.active.value)
             print("new state is actived")
         os.execvp(args.command[0], args.command)
     else:
         proxy = onoff.dbusutils.get_dbus_proxy(args)
-        st = proxy.activatetime(args.duration)
-        if st != ST_ACTIVE:
-            print("state is %d waiting for signal" % st)
-            wait_for_signal(proxy, "changestate", ST_ACTIVE)
+        st = OnoffState(proxy.activatetime(args.duration))
+        if st != OnoffState.active:
+            print("state is %s waiting for signal" % st.name)
+            wait_for_signal(proxy, "changestate", OnoffState.active.value)
             print("new state is active")
 
 if __name__ == "__main__":