def __init__(self, name=None, parent=None): self._pos = 0 # Closed super(HemiCover, self).__init__(name=name, parent=parent) self.changed = Signal() self.opened = Signal() self.closed = Signal()
class HemiCover(ConnectableDevice): STATES = [0,1] NAMES = {'OPEN': 1, 'CLOSED': 0} def __init__(self, name=None, parent=None): self._pos = 0 # Closed super(HemiCover, self).__init__(name=name, parent=parent) self.changed = Signal() self.opened = Signal() self.closed = Signal() def set(self, pos): if pos not in self.STATES: raise ValueError('%d is not a valid state' % pos) if pos != self._pos: # We have to move self.flip() def open(self): if self._pos == 0: self._pos = 1 self.changed.emit(self._pos) self.opened.emit() def close(self): if self._pos == 1: self._pos = 0 self.changed.emit(self._pos) self.closed.emit() def flip(self): self._pos += 1 self._pos %= 2 self.changed.emit(self._pos) if self._pos == 1: self.opened.emit() else: self.closed.emit() def pos(self): return self._pos def config_info(self): return {'name': self.name, 'position': self._pos, 'label': self.NAMES[self._pos]}