ThrottledDevice: speed up quick reactivation
[~helmut/onoff.git] / onoff / common.py
index b491c6b..4a1fe8c 100644 (file)
@@ -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)