2022-08-15 23:58:07 +02:00
|
|
|
import time
|
|
|
|
|
|
|
|
|
2022-08-15 01:10:34 +02:00
|
|
|
class Zone:
|
2022-08-15 23:58:07 +02:00
|
|
|
def __init__(self, number=0, name="", actualHumidity="100", desiredHumidity="0", autoMode=False, state=False, setState=0, endTimeSetState=0, planedDuration=0):
|
2022-08-15 01:10:34 +02:00
|
|
|
self.number = number
|
|
|
|
self.name = name
|
2022-08-15 23:58:07 +02:00
|
|
|
self.actualHumidity = actualHumidity
|
|
|
|
self.desiredHumidity = desiredHumidity
|
2022-08-15 01:10:34 +02:00
|
|
|
self.autoMode = autoMode #False = manual, True = automatic
|
2022-08-15 23:58:07 +02:00
|
|
|
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
|
2022-08-15 01:10:34 +02:00
|
|
|
|
2022-08-15 23:58:07 +02:00
|
|
|
def timeOver(self):
|
|
|
|
return time.time() > self.endTimeSetState
|
2022-08-15 01:10:34 +02:00
|
|
|
|
2022-08-15 23:58:07 +02:00
|
|
|
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:
|
2022-08-15 01:10:34 +02:00
|
|
|
self.state = False
|
|
|
|
|
|
|
|
|
2022-08-15 23:58:07 +02:00
|
|
|
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()
|
|
|
|
|
|
|
|
|