3 * 0: The device is inactive.
4 * ST_ACTIVE|ST_TRANSITION: The device is transitioning from inactive to active.
5 * ST_ACTIVE: The device is active.
6 * ST_TRANSITION: The device is transitioning from active to inactive.
12 class OnoffDevice(object):
14 @type notify: {int -> None}
15 @ivar notify: A set of functions taking a changed state.
18 @ivar state: is a read-only attribute to retrieve the current state
23 def changestate(self, state):
24 """Tell interested parties that the state has changed to the given
26 for func in self.notify:
30 """Ask the device to power on."""
31 raise NotImplementedError
34 """Ask the device to power off."""
35 raise NotImplementedError
38 """Release resources acquired by the constructor."""
41 class InvertedDevice(OnoffDevice):
42 def __init__(self, device):
43 OnoffDevice.__init__(self)
45 self.device.activate()
46 self.device.notify.add(self.changestate)
48 def changestate(self, state):
49 OnoffDevice.changestate(self, state ^ ST_ACTIVE)
53 return self.device.state ^ ST_ACTIVE
56 self.device.deactivate()
59 self.device.activate()
62 self.device.notify.remove(self.changestate)