use the enum module to represent states
[~helmut/onoff.git] / onoff / command.py
index d9b12c0..7a40bbd 100644 (file)
@@ -1,6 +1,6 @@
 import logging
 
-from .common import OnoffDevice, ST_ACTIVE, ST_TRANSITION
+from .common import OnoffDevice, OnoffState
 from .gobject import spawn_child
 
 logger = logging.getLogger("onoff.command")
@@ -29,14 +29,14 @@ class OnoffCommand(OnoffDevice):
         OnoffDevice.__init__(self)
         self.oncommand = oncommand
         self.offcommand = offcommand
-        self.desired_state = 0 # bit mask of just ST_ACTIVE
+        self.desired_state = OnoffState.inactive
         self.pid = None
-        self.target_state = 0 # state the last command targeted
+        self.target_state = OnoffState.inactive  # last command target state
 
     @property
     def state(self):
         if self.pid is not None:
-            return self.desired_state | ST_TRANSITION
+            return self.desired_state | OnoffState.transition
         return self.desired_state
 
     def transition(self, state):
@@ -51,22 +51,24 @@ class OnoffCommand(OnoffDevice):
     def process_died(self, pid, condition):
         assert self.pid == pid
         self.pid = None
-        logger.info("command %d targeting %d completed", pid, self.target_state)
+        logger.info("command %d targeting %s completed", pid,
+                    self.target_state.name)
         if self.desired_state == self.target_state:
             self.changestate(self.state)
         else:
-            logger.info("desired state changed to %d during invocation " +
-                        "targeting %d", self.desired_state, self.target_state)
+            logger.info("desired state changed to %s during invocation " +
+                        "targeting %s", self.desired_state.name,
+                        self.target_state.name)
             self.transition(self.desired_state)
 
     def activate(self):
-        if self.desired_state != ST_ACTIVE:
-            self.desired_state = ST_ACTIVE
+        if self.desired_state != OnoffState.active:
+            self.desired_state = OnoffState.active
             if self.pid is None:
                 self.transition(self.desired_state)
 
     def deactivate(self):
-        if self.desired_state != 0:
-            self.desired_state = 0
+        if self.desired_state != OnoffState.inactive:
+            self.desired_state = OnoffState.inactive
             if self.pid is None:
                 self.transition(self.desired_state)