implemented actions get_zone_list and get_pipeline
This commit is contained in:
@@ -6,19 +6,12 @@
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='Styles/switch.css') }}">
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="refresh" content="5" >
|
||||
|
||||
<script>
|
||||
function executeAction(command, index, value) {
|
||||
send_web_request('{{url_for("executeAction")}}/' + command + '/' + index + '/' + value, 'no', 'variable');
|
||||
}
|
||||
function executeActionByValueID(command, index, valueID, valueFactor){
|
||||
var value = document.getElementById(valueID).value * valueFactor;
|
||||
executeAction(command, index, value);
|
||||
}
|
||||
function switchZoneMode(autoMode, zone) {
|
||||
executeAction('switch_zone_mode' ,zone, (autoMode ? 'automatic' : 'manual'))
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function executeAction(command, index, value) {
|
||||
send_web_request('{{url_for("executeAction")}}', 'no', 'command=' + command + '&index=' + index + '&value=' + value);
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
@@ -43,6 +36,7 @@
|
||||
<img src="{{ url_for('static', filename='img/header/blumenbeet.jpg') }}" alt="" class="header-img">
|
||||
|
||||
</header>
|
||||
<script src="{{ url_for('static', filename='js/action.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='js/webhook.js') }}"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+57
-47
@@ -33,57 +33,67 @@ class Webserver:
|
||||
return redirect(url_for('showDashboard'))
|
||||
|
||||
@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
|
||||
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)
|
||||
|
||||
|
||||
if(request.method == 'POST'):
|
||||
try:
|
||||
command = request.form['command']
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
index_str = request.form['index']
|
||||
index = int(index_str)
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
value_str = request.form['value']
|
||||
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
|
||||
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)
|
||||
case "get_zone_list":
|
||||
return self.zoneManager.zonesToJSON()
|
||||
case "get_pipeline":
|
||||
return self.zoneManager.pipelineToJSON()
|
||||
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=self.translater, zoneManager=self.zoneManager)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
function executeActionByValueID(command, index, valueID, valueFactor){
|
||||
var value = document.getElementById(valueID).value * valueFactor;
|
||||
executeAction(command, index, value);
|
||||
}
|
||||
function switchZoneMode(autoMode, zone) {
|
||||
executeAction('switch_zone_mode' ,zone, (autoMode ? 'automatic' : 'manual'))
|
||||
}
|
||||
Reference in New Issue
Block a user