import time class Zone: def __init__(self, number=0, name="", actualHumidity="100", desiredHumidity="0", autoMode=False, state=False, setState=0, endTimeSetState=0, planedDuration=0): self.number = number self.name = name self.actualHumidity = actualHumidity self.desiredHumidity = desiredHumidity self.autoMode = autoMode #False = manual, True = automatic self.state = state #True = on, False = off self.setState = setState #0=default, 1=turned off for time, 2=turned on for time, 3=command in pipeline self.endTimeSetState = endTimeSetState self.planedDuration = planedDuration def timeOver(self): return time.time() > self.endTimeSetState def refreshStateAutomode(self): match self.setState: case 0: if(self.desiredHumidity > self.actualHumidity): self.state = True else: self.state = False case 1: if(self.timeOver()): self.setState = 0 self.refreshStateAutomode() else: self.state = False case 2: if (self.timeOver()): self.setState = 0 self.refreshStateAutomode() else: self.state = True case 3: self.state = False def refreshStateManualmode(self): if(self.setState > 0): match self.setState: case 1: if(self.timeOver()): self.setState = 0 self.state = False case 2: if (self.timeOver()): self.setState = 0 self.state = False else: self.state = True case 3: self.state = False def refreshState(self): if(self.autoMode): self.refreshStateAutomode() else: self.refreshStateManualmode() def switchMode(self, autoMode): if(self.autoMode != autoMode): self.autoMode = autoMode self.state = False self.refreshState() def switchState(self, state, duration, instant): if(instant): if(not state): self.setState = 1 else: self.setState = 2 self.endTimeSetState = time.time() + duration else: if(state): self.setState = 3 self.planedDuration = duration self.refreshState()