implemented Webhooks
This commit is contained in:
@@ -25,6 +25,7 @@ class Translater:
|
||||
"automatic mode": "Automatikbetrieb",
|
||||
"switch to manual mode": "Auf Handbetrieb umstellen",
|
||||
"switch to automatic mode": "Auf Automatikbetrieb umstellen",
|
||||
"minutes": "Minuten",
|
||||
}
|
||||
|
||||
|
||||
|
||||
+83
-63
@@ -1,79 +1,99 @@
|
||||
from flask import Flask, render_template, request, redirect, url_for
|
||||
from flask_navigation import Navigation
|
||||
from Webserver.Translater import Translater, Language
|
||||
from Zone import Zone
|
||||
|
||||
|
||||
def startWebserver(port, zoneManager):
|
||||
translater_EN = Translater(Language.ENGLISH)
|
||||
translater_DE = Translater(Language.GERMAN)
|
||||
translater = translater_EN
|
||||
class Webserver:
|
||||
def __init__(self, zoneManager, port=80):
|
||||
self.port = port
|
||||
self.zoneManager = zoneManager
|
||||
self.translater_EN = Translater(Language.ENGLISH)
|
||||
self.translater_DE = Translater(Language.GERMAN)
|
||||
self.translater = self.translater_EN
|
||||
|
||||
app = Flask("Bewässerungssystem", template_folder="Webserver/templates", static_folder="Webserver/static")
|
||||
nav = Navigation(app)
|
||||
def startWebserver(self):
|
||||
app = Flask("Bewässerungssystem", template_folder="Webserver/templates", static_folder="Webserver/static")
|
||||
nav = Navigation(app)
|
||||
|
||||
nav.Bar('top', [
|
||||
nav.Item(translater.getTranslation('Dashboard'), 'showDashboard'),
|
||||
nav.Item(translater.getTranslation('irrigation zones'), 'showZones'),
|
||||
nav.Item(translater.getTranslation('blocking times'), 'showTimes'),
|
||||
nav.Item(translater.getTranslation('system settings'), 'showSystem')
|
||||
# nav.Item('Gfg', 'gfg', {'page': 5}), #(example with pages)
|
||||
])
|
||||
nav.Bar('top', [
|
||||
nav.Item(self.translater.getTranslation('Dashboard'), 'showDashboard'),
|
||||
nav.Item(self.translater.getTranslation('irrigation zones'), 'showZones'),
|
||||
nav.Item(self.translater.getTranslation('blocking times'), 'showTimes'),
|
||||
nav.Item(self.translater.getTranslation('system settings'), 'showSystem')
|
||||
# nav.Item('Gfg', 'gfg', {'page': 5}), #(example with pages)
|
||||
])
|
||||
|
||||
# Example Route with pages:
|
||||
# @app.route('/gfg/<int:page>')
|
||||
# def gfg(page):
|
||||
# return render_template('gfg.html', page=page)
|
||||
# Example Route with pages:
|
||||
# @app.route('/gfg/<int:page>')
|
||||
# def gfg(page):
|
||||
# return render_template('gfg.html', page=page)
|
||||
|
||||
@app.route('/')
|
||||
def startPage():
|
||||
return redirect(url_for('showDashboard'))
|
||||
@app.route('/')
|
||||
def startPage():
|
||||
return redirect(url_for('showDashboard'))
|
||||
|
||||
@app.route('/action/<command>/<index_str>/<value_str>')
|
||||
def executeAction(command=False, index_str=False, value_str=False):
|
||||
sucess = False
|
||||
index = int(index_str)
|
||||
value = int(value_str)
|
||||
match command:
|
||||
case "switch_zone_on":
|
||||
if (index and value):
|
||||
zoneManager.switchZoneIndexState(zoneIndex=index, state=True, duration=value)
|
||||
case "switch_zone_off":
|
||||
if (index and value):
|
||||
zoneManager.switchZoneIndexState(zoneIndex=index, state=False, duration=value)
|
||||
case "switch_zone_mode":
|
||||
if (index and value):
|
||||
zone = zoneManager.getZone(index)
|
||||
match value:
|
||||
case "automatic":
|
||||
zone.switchMode(autoMode=True)
|
||||
case "manual":
|
||||
zone.switchMode(autoMode=False)
|
||||
case "set_desired_humidity":
|
||||
if (index and value):
|
||||
zone = zoneManager.getZone(index)
|
||||
zone.desiredHumidity = value
|
||||
@app.route('/action', methods=['GET', 'POST'])
|
||||
@app.route('/action/<command>', methods=['GET', 'POST'])
|
||||
@app.route('/action/<command>/<index_str>', methods=['GET', 'POST'])
|
||||
@app.route('/action/<command>/<index_str>/<value_str>', methods=['GET', 'POST'])
|
||||
def executeAction(command=False, index_str=False, value_str=False):
|
||||
sucess = False
|
||||
try:
|
||||
index = int(index_str)
|
||||
value = int(value_str)
|
||||
except:
|
||||
pass
|
||||
match command:
|
||||
case "switch_zone_on":
|
||||
if (index and value):
|
||||
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=True, duration=value)
|
||||
sucess = True
|
||||
elif(index):
|
||||
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=True, duration=self.zoneManager.systemSettings.defaultManualIrrigationDuration)
|
||||
sucess = True
|
||||
case "switch_zone_off":
|
||||
if (index and value):
|
||||
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=False, duration=value, instant=True)
|
||||
sucess = True
|
||||
elif(index):
|
||||
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=False, duration=self.zoneManager.systemSettings.defaultManualOffDuration, instant=True)
|
||||
sucess = 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
|
||||
case "set_desired_humidity":
|
||||
if (index and value):
|
||||
zone = self.zoneManager.getZone(index)
|
||||
zone.desiredHumidity = value
|
||||
sucess = True
|
||||
|
||||
return render_template('action.html', translater=translater, zones=zoneManager.zones)
|
||||
return render_template('action.html', translater=self.translater, zones=self.zoneManager.zones, sucess=sucess)
|
||||
|
||||
@app.route('/dashboard')
|
||||
def showDashboard():
|
||||
return render_template('dashboard.html', translater=translater, zones=zoneManager.zones)
|
||||
@app.route('/dashboard')
|
||||
def showDashboard():
|
||||
return render_template('dashboard.html', translater=self.translater, zoneManager=self.zoneManager)
|
||||
|
||||
@app.route('/zones')
|
||||
@app.route('/zones/<zoneNumber>')
|
||||
def showZones(zoneNumber=False):
|
||||
if (zoneNumber):
|
||||
return render_template('zone.html', translater=translater, zone=zoneManager.getZone(zoneNumber))
|
||||
else:
|
||||
return render_template('zones.html', translater=translater, zones=zoneManager.zones)
|
||||
@app.route('/zones')
|
||||
@app.route('/zones/<zoneNumber>')
|
||||
def showZones(zoneNumber=False):
|
||||
if (zoneNumber):
|
||||
return render_template('zone.html', translater=self.translater, zone=self.zoneManager.getZone(zoneNumber))
|
||||
else:
|
||||
return render_template('zones.html', translater=self.translater, zones=self.zoneManager.zones)
|
||||
|
||||
@app.route('/times')
|
||||
def showTimes():
|
||||
return render_template('times.html', translater=translater)
|
||||
@app.route('/times')
|
||||
def showTimes():
|
||||
return render_template('times.html', translater=self.translater)
|
||||
|
||||
@app.route('/system')
|
||||
def showSystem():
|
||||
return render_template('system.html', translater=translater)
|
||||
@app.route('/system')
|
||||
def showSystem():
|
||||
return render_template('system.html', translater=self.translater)
|
||||
|
||||
app.run(debug=True, port=port)
|
||||
app.run(debug=True, port=self.port)
|
||||
|
||||
Reference in New Issue
Block a user