From 279c9e74beddb9006ff9d88db6085fb2aab050d6 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sat, 27 Aug 2022 13:54:23 +0200 Subject: [PATCH] implemented Action to switch Mode of all Zones. Fixed Bug #2 --- Webserver/__init__.py | 40 ++++++++++++++++++++++++---------------- ZoneManager.py | 19 ++++++++++++------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/Webserver/__init__.py b/Webserver/__init__.py index bc90e53..fe397f0 100644 --- a/Webserver/__init__.py +++ b/Webserver/__init__.py @@ -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') diff --git a/ZoneManager.py b/ZoneManager.py index 114567a..181bc91 100644 --- a/ZoneManager.py +++ b/ZoneManager.py @@ -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()