Webserver_Dashboard and basic functionality #1

Merged
Roman_Schenk merged 12 commits from Webserver_Layout into master 2022-08-23 20:28:05 +02:00
5 changed files with 72 additions and 16 deletions
Showing only changes of commit 503b87579b - Show all commits

View File

@ -26,6 +26,12 @@ class Translater:
"switch to manual mode": "Auf Handbetrieb umstellen",
"switch to automatic mode": "Auf Automatikbetrieb umstellen",
"minutes": "Minuten",
"until": "bis",
"irragation is planed for": "Bewässerung ist geplant für",
"planed irrigationjobs": "geplante Bewässerungsaufträge",
"planed duration": "geplante Dauer",
"cancel": "abbrechen",
"delete": "löschen",
}

View File

@ -9,7 +9,7 @@ class Webserver:
self.zoneManager = zoneManager
self.translater_EN = Translater(Language.ENGLISH)
self.translater_DE = Translater(Language.GERMAN)
self.translater = self.translater_EN
self.translater = self.translater_DE
def startWebserver(self):
app = Flask("Bewässerungssystem", template_folder="Webserver/templates", static_folder="Webserver/static")
@ -73,6 +73,14 @@ class Webserver:
zone = self.zoneManager.getZone(index)
zone.desiredHumidity = value
sucess = True
case "delete_jobs_for_zone":
if (index):
zone = self.zoneManager.getZone(index)
self.zoneManager.deleteIrrigationJobsForZone(zone)
case "delete_job_by_id":
if (index):
self.zoneManager.deleteIrrigationJobByID(index)
return render_template('action.html', translater=self.translater, zones=self.zoneManager.zones, sucess=sucess)

13
Zone.py
View File

@ -22,10 +22,11 @@ class Zone:
def refreshStateAutomode(self):
match self.setState:
case 0:
if(self.desiredHumidity > self.actualHumidity):
self.zoneManager.switchZoneState(zone=self, state=True, duration=self.zoneManager.systemSettings.defaultAutoIrrigationDuration, instant=False)
else:
self.state = False
if(self.planedDuration > 0):
self.setState = 3
elif(self.desiredHumidity > self.actualHumidity):
self.zoneManager.switchZoneState(zone=self, state=True, duration=self.zoneManager.systemSettings.defaultAutoIrrigationDuration, instant=False)
case 1:
if(self.timeOver()):
self.setState = 0
@ -45,6 +46,10 @@ class Zone:
def refreshStateManualmode(self):
if(self.setState > 0):
match self.setState:
case 0:
self.state = False
if (self.planedDuration > 0):
self.setState = 3
case 1:
if(self.timeOver()):
self.setState = 0
@ -60,6 +65,7 @@ class Zone:
def refreshState(self):
self.planedDuration = self.zoneManager.getPlanedDurationForZone(zone=self)
if(self.autoMode):
self.refreshStateAutomode()
else:
@ -81,7 +87,6 @@ class Zone:
else:
if(state):
self.setState = 3
self.planedDuration = duration
self.refreshState()

View File

@ -1,13 +1,19 @@
import threading
from random import Random
from time import time
from FileIO import FileIO
class ZoneManager:
def __init__(self, systemSettings, fileIO):
self.random = Random()
self.systemSettings = systemSettings
self.fileIO = FileIO
self.zones = fileIO.loadZones()
for zone in self.zones:
zone.setZoneManager(self)
self.pipeLine = []
self.pipeLine = [] #todo Thread Synchron
#self.lock = threading.Lock()
def getZone(self, number):
for zone in self.zones:
@ -15,8 +21,29 @@ class ZoneManager:
return zone
def addIrrigationJob(self, job):
#with self.lock:
self.pipeLine.append(job)
def deleteIrrigationJobByID(self, id):
#with self.lock:
i = 0
while i < (len(self.pipeLine)):
irrigationJob = self.pipeLine[i]
if(irrigationJob.id == id):
self.pipeLine.pop(i)
else:
i = i + 1
def deleteIrrigationJobsForZone(self, zone):
#with self.lock:
i = 0
while i < (len(self.pipeLine)):
irrigationJob = self.pipeLine[i]
if (irrigationJob.zone == zone):
self.pipeLine.pop(i)
else:
i = i + 1
def isAnyZoneBusy(self):
for zone in self.zones:
if(zone.state):
@ -24,20 +51,29 @@ class ZoneManager:
return False
def switchZoneState(self, zone, state, duration, instant=False):
if(instant or self.systemSettings.multiZoneIrrigation):
if(instant or self.systemSettings.multiZoneIrrigation or state==False or (not self.isAnyZoneBusy())):
zone.switchState(state=state, duration=duration, instant=True)
else:
self.addIrrigationJob(IrrigationJob(zone, duration))
self.addIrrigationJob(IrrigationJob(id=self.random.randint(a=100000000, b=999999999), zone=zone, duration=duration))
def switchZoneIndexState(self, zoneIndex, state, duration, instant=False):
zone = self.getZone(zoneIndex)
self.switchZoneState(zone, state, duration, instant)
def getPlanedDurationForZone(self, zone):
totalDuration = 0
#with self.lock:
for irrigationJob in self.pipeLine:
if(irrigationJob.zone == zone):
totalDuration = totalDuration + irrigationJob.duration
return totalDuration
def refreshStates(self):
for zone in self.zones:
zone.refreshState()
def processPipeline(self):
#with self.lock:
if(len(self.pipeLine) > 0 and (not self.isAnyZoneBusy())):
irrigationJob = self.pipeLine[0]
irrigationJob.process()
@ -46,13 +82,14 @@ class ZoneManager:
def cronJobs(self):
self.refreshStates()
self.processPipeline()
print("Executed Cron Jobs of ZoneManager")
print("Executed Cron Jobs of ZoneManager.\nactual Time: " + str(time()))
class IrrigationJob:
def __init__(self, zone, duration=0):
def __init__(self, id, zone, duration=0):
self.id = id
self.zone = zone
self.duration = duration
self.zone.switchState(state=True, duration=duration, instant=False)

View File

@ -6,7 +6,7 @@ from ZoneManager import ZoneManager
from SystemSettings import SystemSettings
from FileIO import FileIO
systemSettings = SystemSettings(dataDir="/Data", multiZoneIrrigation=False, defaultAutoIrrigationDuration=10, defaultManualIrrigationDuration=10, defaultManualOffDuration=10, webDurationOptions=[5, 10, 15, 20, 25, 30, 45, 60])
systemSettings = SystemSettings(dataDir="/Data", multiZoneIrrigation=False, defaultAutoIrrigationDuration=10, defaultManualIrrigationDuration=10, defaultManualOffDuration=10, webDurationOptions=[1, 5, 10, 15, 20, 25, 30, 45, 60])
fileIO = FileIO(systemSettings)
zoneManager = ZoneManager(systemSettings=systemSettings, fileIO=fileIO)
webserver = Webserver(zoneManager=zoneManager, port=80)