ThrottledDevice: speed up quick reactivation
[~helmut/onoff.git] / onoff / common.py
index cb27b66..4a1fe8c 100644 (file)
@@ -1,9 +1,9 @@
 """
 Defined states:
* 0: The device is inactive.
* ST_ACTIVE|ST_TRANSITION: The device is transitioning from inactive to active.
* ST_ACTIVE: The device is active.
* ST_TRANSITION: The device is transitioning from active to inactive.
- 0: The device is inactive.
- ST_ACTIVE|ST_TRANSITION: The device is transitioning from inactive to active.
- ST_ACTIVE: The device is active.
- ST_TRANSITION: The device is transitioning from active to inactive.
 """
 
 import logging
@@ -133,6 +133,13 @@ class ThrottledDevice(OnoffDevice):
         if self.desired_state == 0 and self.transition is not None:
             logger.debug("cancelling pending deactivation")
             self._cancel_transition()
+            curstate = self.device.state
+            if curstate == ST_ACTIVE:
+                self.desired_state = ST_ACTIVE
+                OnoffDevice.changestate(self, ST_ACTIVE)
+                return
+            logger.warn("device should be active during delayed deactivation" +
+                        ", but is in state %d", curstate)
         self.desired_state = ST_ACTIVE
         self.device.activate()
         self.changestate(self.device.state)