implemented Action to switch Mode of all Zones.

Fixed Bug #2
This commit is contained in:
schrom01 2022-08-27 13:54:23 +02:00
parent 453542d431
commit 279c9e74be
2 changed files with 36 additions and 23 deletions

View File

@ -34,7 +34,6 @@ class Webserver:
@app.route('/action', methods=['GET', 'POST']) @app.route('/action', methods=['GET', 'POST'])
def executeAction(command=False, index_str=False, value_str=False): def executeAction(command=False, index_str=False, value_str=False):
sucess = False
if(request.method == 'POST'): if(request.method == 'POST'):
try: try:
command = request.form['command'] command = request.form['command']
@ -69,36 +68,45 @@ class Webserver:
case "switch_zone_on": case "switch_zone_on":
if (index and value): if (index and value):
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=True, duration=value) self.zoneManager.switchZoneIndexState(zoneIndex=index, state=True, duration=value)
sucess = True return "True"
elif(index): elif(index):
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=True, duration=self.zoneManager.systemSettings.defaultManualIrrigationDuration) self.zoneManager.switchZoneIndexState(zoneIndex=index, state=True, duration=self.zoneManager.systemSettings.defaultManualIrrigationDuration)
sucess = True return "True"
case "switch_zone_off": case "switch_zone_off":
if (index and value): if (index and value):
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=False, duration=value, instant=True) self.zoneManager.switchZoneIndexState(zoneIndex=index, state=False, duration=value, instant=True)
sucess = True return "True"
elif(index): elif(index):
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=False, duration=self.zoneManager.systemSettings.defaultManualOffDuration, instant=True) self.zoneManager.switchZoneIndexState(zoneIndex=index, state=False, duration=self.zoneManager.systemSettings.defaultManualOffDuration, instant=True)
sucess = True return "True"
case "switch_zone_mode": case "switch_zone_mode":
if (index and value_str): zonesToSwitch = []
zone = self.zoneManager.getZone(index) if(index_str == "all" and value_str):
match value_str: zonesToSwitch = self.zoneManager.zones
case "automatic": elif (index and value_str):
zone.switchMode(autoMode=True) zonesToSwitch.append(self.zoneManager.getZone(index))
sucess = True else:
case "manual": return "False"
zone.switchMode(autoMode=False) automode = False
sucess = True 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": case "set_desired_humidity":
if (index and value): if (index and value):
zone = self.zoneManager.getZone(index) zone = self.zoneManager.getZone(index)
zone.desiredHumidity = value zone.desiredHumidity = value
sucess = True return "True"
case "delete_jobs_for_zone": case "delete_jobs_for_zone":
if (index): if (index):
zone = self.zoneManager.getZone(index) zone = self.zoneManager.getZone(index)
self.zoneManager.deleteIrrigationJobsForZone(zone) self.zoneManager.deleteIrrigationJobsForZone(zone)
return "True"
case "delete_job_by_id": case "delete_job_by_id":
if (index): if (index):
self.zoneManager.deleteIrrigationJobByID(index) self.zoneManager.deleteIrrigationJobByID(index)
@ -116,7 +124,7 @@ class Webserver:
return zone.toJSON(self.translater) return zone.toJSON(self.translater)
case "get_pipeline": case "get_pipeline":
return self.zoneManager.pipelineToJSON(self.translater) 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') @app.route('/dashboard')

View File

@ -92,12 +92,17 @@ class ZoneManager:
def processPipeline(self): def processPipeline(self):
self.piplineMutexLock.acquire() self.piplineMutexLock.acquire()
if(len(self.pipeLine) > 0 and (not self.isAnyZoneBusy())): index = 0
irrigationJob = self.pipeLine[0] while(len(self.pipeLine) > index and (not self.isAnyZoneBusy())):
self.pipeLine.pop(0) irrigationJob = self.pipeLine[index]
if(not irrigationJob.zone.setState == 1):
self.pipeLine.pop(index)
self.piplineMutexLock.release() self.piplineMutexLock.release()
irrigationJob.process() irrigationJob.process()
return
else: else:
index = index + 1
self.piplineMutexLock.release() self.piplineMutexLock.release()