2022-08-15 23:58:07 +02:00
|
|
|
from FileIO import FileIO
|
|
|
|
|
|
|
|
class ZoneManager:
|
|
|
|
def __init__(self, systemSettings, fileIO):
|
|
|
|
self.systemSettings = systemSettings
|
|
|
|
self.fileIO = FileIO
|
|
|
|
self.zones = fileIO.loadZones()
|
2022-08-16 03:13:10 +02:00
|
|
|
for zone in self.zones:
|
|
|
|
zone.setZoneManager(self)
|
2022-08-15 23:58:07 +02:00
|
|
|
self.pipeLine = []
|
|
|
|
|
|
|
|
def getZone(self, number):
|
|
|
|
for zone in self.zones:
|
|
|
|
if(zone.number == number):
|
|
|
|
return zone
|
|
|
|
|
|
|
|
def addIrrigationJob(self, job):
|
|
|
|
self.pipeLine.append(job)
|
|
|
|
|
|
|
|
def isAnyZoneBusy(self):
|
|
|
|
for zone in self.zones:
|
|
|
|
if(zone.state):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def switchZoneState(self, zone, state, duration, instant=False):
|
|
|
|
if(instant or self.systemSettings.multiZoneIrrigation):
|
|
|
|
zone.switchState(state=state, duration=duration, instant=True)
|
|
|
|
else:
|
|
|
|
self.addIrrigationJob(IrrigationJob(zone, duration))
|
|
|
|
|
|
|
|
def switchZoneIndexState(self, zoneIndex, state, duration, instant=False):
|
|
|
|
zone = self.getZone(zoneIndex)
|
|
|
|
self.switchZoneState(zone, state, duration, instant)
|
|
|
|
|
|
|
|
def refreshStates(self):
|
|
|
|
for zone in self.zones:
|
|
|
|
zone.refreshState()
|
|
|
|
|
|
|
|
def processPipeline(self):
|
|
|
|
if(len(self.pipeLine) > 0 and (not self.isAnyZoneBusy())):
|
|
|
|
irrigationJob = self.pipeLine[0]
|
|
|
|
irrigationJob.process()
|
|
|
|
self.pipeLine.pop(0)
|
|
|
|
|
|
|
|
def cronJobs(self):
|
|
|
|
self.refreshStates()
|
|
|
|
self.processPipeline()
|
2022-08-16 03:13:10 +02:00
|
|
|
print("Executed Cron Jobs of ZoneManager")
|
2022-08-15 23:58:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IrrigationJob:
|
|
|
|
def __init__(self, zone, duration=0):
|
|
|
|
self.zone = zone
|
|
|
|
self.duration = duration
|
|
|
|
self.zone.switchState(state=True, duration=duration, instant=False)
|
|
|
|
|
|
|
|
def process(self):
|
|
|
|
self.zone.switchState(state=True, duration=self.duration, instant=True)
|