ThrottledDevice: speed up quick reactivation
authorHelmut Grohne <helmut@subdivi.de>
Fri, 19 Jul 2013 12:56:05 +0000 (14:56 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Fri, 19 Jul 2013 12:56:05 +0000 (14:56 +0200)
When a deactivation is delayed by offdelay and reactivated before the
timer expires, the device is not powered down at all in between. So we
should not incur the ondelay, but immediately transition to ST_ACTIVE
after cancelling the pending deactivation.

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)