+ if self.transition is None:
+ return self.device.state
+ return self.desired_state | ST_TRANSITION
+
+ def _schedule_transition(self, delay, func):
+ assert self.transition is None
+ self.transition = GObject.timeout_add(int(1000 * delay), func)
+
+ def _cancel_transition(self):
+ assert self.transition is not None
+ ret = GObject.source_remove(self.transition)
+ assert ret
+ self.transition = None
+
+ def changestate(self, state):
+ if state != ST_ACTIVE:
+ OnoffDevice.changestate(self, state)
+ else:
+ if self.desired_state == 0:
+ logger.warn("device became active but we want inactive," +
+ "suppresing signal")
+ elif self.transition is None:
+ logger.debug("scheduling report of activation in %.1fs",
+ self.ondelay)
+ self._schedule_transition(self.ondelay, self._report_active)
+ else:
+ logger.debug("suppressing duplicate activation signal")
+
+ def _report_active(self):
+ assert self.desired_state == ST_ACTIVE
+ assert self.transition is not None
+ self.transition = None
+ logger.debug("delivering activation signal")
+ OnoffDevice.changestate(self, ST_ACTIVE)