61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
from FileIO import FileIO
|
|
|
|
class ZoneManager:
|
|
def __init__(self, systemSettings, fileIO):
|
|
self.systemSettings = systemSettings
|
|
self.fileIO = FileIO
|
|
self.zones = fileIO.loadZones()
|
|
for zone in self.zones:
|
|
zone.setZoneManager(self)
|
|
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()
|
|
print("Executed Cron Jobs of ZoneManager")
|
|
|
|
|
|
|
|
|
|
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) |