parent
453542d431
commit
279c9e74be
|
@ -34,7 +34,6 @@ class Webserver:
|
|||
|
||||
@app.route('/action', methods=['GET', 'POST'])
|
||||
def executeAction(command=False, index_str=False, value_str=False):
|
||||
sucess = False
|
||||
if(request.method == 'POST'):
|
||||
try:
|
||||
command = request.form['command']
|
||||
|
@ -69,36 +68,45 @@ class Webserver:
|
|||
case "switch_zone_on":
|
||||
if (index and value):
|
||||
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=True, duration=value)
|
||||
sucess = True
|
||||
return "True"
|
||||
elif(index):
|
||||
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=True, duration=self.zoneManager.systemSettings.defaultManualIrrigationDuration)
|
||||
sucess = True
|
||||
return "True"
|
||||
case "switch_zone_off":
|
||||
if (index and value):
|
||||
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=False, duration=value, instant=True)
|
||||
sucess = True
|
||||
return "True"
|
||||
elif(index):
|
||||
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=False, duration=self.zoneManager.systemSettings.defaultManualOffDuration, instant=True)
|
||||
sucess = True
|
||||
return "True"
|
||||
case "switch_zone_mode":
|
||||
if (index and value_str):
|
||||
zone = self.zoneManager.getZone(index)
|
||||
match value_str:
|
||||
case "automatic":
|
||||
zone.switchMode(autoMode=True)
|
||||
sucess = True
|
||||
case "manual":
|
||||
zone.switchMode(autoMode=False)
|
||||
sucess = True
|
||||
zonesToSwitch = []
|
||||
if(index_str == "all" and value_str):
|
||||
zonesToSwitch = self.zoneManager.zones
|
||||
elif (index and value_str):
|
||||
zonesToSwitch.append(self.zoneManager.getZone(index))
|
||||
else:
|
||||
return "False"
|
||||
automode = False
|
||||
if(value_str == "automatic"):
|
||||
automode = True
|
||||
elif(value_str == "manual"):
|
||||
automode = False
|
||||
else:
|
||||
return "False"
|
||||
for zone in zonesToSwitch:
|
||||
zone.switchMode(autoMode=automode)
|
||||
return "True"
|
||||
case "set_desired_humidity":
|
||||
if (index and value):
|
||||
zone = self.zoneManager.getZone(index)
|
||||
zone.desiredHumidity = value
|
||||
sucess = True
|
||||
return "True"
|
||||
case "delete_jobs_for_zone":
|
||||
if (index):
|
||||
zone = self.zoneManager.getZone(index)
|
||||
self.zoneManager.deleteIrrigationJobsForZone(zone)
|
||||
return "True"
|
||||
case "delete_job_by_id":
|
||||
if (index):
|
||||
self.zoneManager.deleteIrrigationJobByID(index)
|
||||
|
@ -116,7 +124,7 @@ class Webserver:
|
|||
return zone.toJSON(self.translater)
|
||||
case "get_pipeline":
|
||||
return self.zoneManager.pipelineToJSON(self.translater)
|
||||
return render_template('action.html', translater=self.translater, zones=self.zoneManager.zones, sucess=sucess)
|
||||
return "False"
|
||||
|
||||
|
||||
@app.route('/dashboard')
|
||||
|
|
|
@ -92,13 +92,18 @@ class ZoneManager:
|
|||
|
||||
def processPipeline(self):
|
||||
self.piplineMutexLock.acquire()
|
||||
if(len(self.pipeLine) > 0 and (not self.isAnyZoneBusy())):
|
||||
irrigationJob = self.pipeLine[0]
|
||||
self.pipeLine.pop(0)
|
||||
self.piplineMutexLock.release()
|
||||
irrigationJob.process()
|
||||
else:
|
||||
self.piplineMutexLock.release()
|
||||
index = 0
|
||||
while(len(self.pipeLine) > index and (not self.isAnyZoneBusy())):
|
||||
irrigationJob = self.pipeLine[index]
|
||||
if(not irrigationJob.zone.setState == 1):
|
||||
self.pipeLine.pop(index)
|
||||
self.piplineMutexLock.release()
|
||||
irrigationJob.process()
|
||||
return
|
||||
else:
|
||||
index = index + 1
|
||||
|
||||
self.piplineMutexLock.release()
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue