implemented autorefresh

This commit is contained in:
schrom01 2022-08-25 15:37:54 +02:00
parent 1066adcc63
commit ba3afd129d
10 changed files with 249 additions and 12 deletions

View File

@ -1,7 +1,8 @@
class SystemSettings:
def __init__(self, dataDir="/Data", multiZoneIrrigation=False, defaultAutoIrrigationDuration=10, defaultManualIrrigationDuration=10, defaultManualOffDuration=10, webDurationOptions=[5, 10, 15, 20, 25, 30, 45, 60]):
def __init__(self, cronJobFrequency=2, dataDir="/Data", multiZoneIrrigation=False, defaultAutoIrrigationDuration=10, defaultManualIrrigationDuration=10, defaultManualOffDuration=10, webDurationOptions=[5, 10, 15, 20, 25, 30, 45, 60]):
self.cronJobFrequency = cronJobFrequency
self.dataDir = dataDir
self.multiZoneIrrigation = multiZoneIrrigation
self.defaultAutoIrrigationDuration = defaultAutoIrrigationDuration

View File

@ -0,0 +1,82 @@
<!DOCTYPE html>
<html lang="de">
<head>
<link rel="stylesheet" href="{{ url_for('static', filename='Styles/dashboard.css') }}">
<title>{{ translater.getTranslation("Irrigation") }}{{ translater.getTranslation("system") }}</title>
<style>
@media screen and (min-width: 2051px){
#zones{
grid-template-rows: repeat( {{ (zoneManager.zones|length / 3) + 1 }} , minmax(150px, auto));
}
}
@media screen and (max-width: 2050px) and (min-width: 1351px){
#zones{
grid-template-rows: repeat( {{ (zoneManager.zones|length / 2) + 1 }} , minmax(150px, auto));
}
}
@media screen and (max-width: 1350px){
#zones{
grid-template-rows: repeat( {{ zoneManager.zones|length }} , minmax(150px, auto));
}
}
</style>
<script>
function refreshZone(zone) {
executeAction('get_dashboard_zone_html', zone, '0', 'zone_'+ zone);
}
function refreshPipeline() {
executeAction('get_dashboard_pipeline_html', '0', '0', 'pipeline');
}
function refreshContent() {
refreshPipeline();
{% for zone in zoneManager.zones %}
refreshZone({{zone.number}});
{% endfor %}
}
</script>
</head>
<body>
{% include "header.html" %}
<main>
<h2>{{ translater.getTranslation("Dashboard") }}</h2>
<h3>{{ translater.getTranslation("planed irrigationjobs") }}</h3>
<p>
<button onclick="refreshPipeline()">
refresh
</button>
</p>
<div id="pipeline">
{% include "dashboard/pipeline.html" %}
</div>
<h3>{{ translater.getTranslation("irrigation zones") }}</h3>
<div id="zones">
{% for zone in zoneManager.zones %}
<div id="zone_{{ zone.number }}" class="zone">
{% include "dashboard/zone.html" %}
</div>
{% endfor %}
</div>
</main>
<p><br><br></p>
</body>
</html>

View File

@ -0,0 +1,21 @@
<table>
<thead>
<tr>
<td>ID</td>
<td>{{ translater.getTranslation("Zone") }}</td>
<td>{{ translater.getTranslation("planed duration") }}</td>
</tr>
</thead>
<tbody>
{% for job in zoneManager.pipeLine %}
<tr>
<td>{{ job.id }}</td>
<td>{{ job.zone.number|string + ": " + job.zone.name }}</td>
<td>{{ ((job.duration/60)|int)|string + " " + translater.getTranslation("minutes")}}</td>
<td><button onclick="deleteJobById('delete_job_by_id','{{ job.id }}', {{ job.zone.number }})">{{ translater.getTranslation("delete") }}</button></td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@ -0,0 +1,92 @@
<a href="/zones/{{ zone.number}}">
<h4>{{ zone.name }}</h3>
</a>
<table>
<tbody>
<tr>
<td class="icon">
<span class="outer_dot">
<span class="inner_icon {{ 'dot_green' if zone.state else 'dot_red' }}"></span>
</span>
</td>
<td class="property">{{ translater.getTranslation("state") }}:</td>
<td class="value" id="state_text_zone_{{ zone.number }}">
{{ translater.getTranslation("switched on") if zone.state else translater.getTranslation("switched off") }}
</td>
<td>
<select id="duration_zone_{{ zone.number }}">
{% for option in zoneManager.systemSettings.webDurationOptions %}
<option value="{{ option }}">{{ option }} {{ translater.getTranslation("minutes") }}</option>
{% endfor %}
</select>
<button onclick="switchZoneStateByValueID({{'"switch_zone_off"' if zone.state else '"switch_zone_on"'}},'{{ zone.number }}', 'duration_zone_{{ zone.number }}', 60)">{{ translater.getTranslation("turn off") if zone.state else translater.getTranslation("turn on") }}</button>
</td>
<td>
<button onclick="refreshZone({{ zone.number }})">
refresh
</button>
</td>
</tr>
{% if (zone.setState == 1 or zone.setState == 2) %}
<tr>
<td></td>
<td></td>
<td>
{{translater.getTranslation("until") + zone.endTimeSetState|string}}
</td>
<td>
<button onclick="switchZoneState({{'"switch_zone_off"' if zone.state else '"switch_zone_on"'}},'{{ zone.number }}', -1)">{{ translater.getTranslation("cancel") }}</button>
</td>
</tr>
{% endif %}
{% if zone.planedDuration > 0 %}
<tr>
<td></td>
<td></td>
<td>
{{translater.getTranslation("irragation is planed for") + " " + ((zone.planedDuration/60)|int)|string + " " + translater.getTranslation("minutes") + "." }}
</td>
<td>
<button onclick="deleteJobsForZone('delete_jobs_for_zone','{{ zone.number }}')">{{ translater.getTranslation("delete") }}</button>
</td>
</tr>
{% endif %}
<tr>
<td class="icon">
<span class="outer_dot">
<p class="inner_icon">{{'A' if zone.autoMode else 'M'}}</p>
</span>
</td>
<td>
<label class="toggle">
<input type="checkbox" {{ "checked" if zone.autoMode }} onchange="switchZoneMode(this.checked, {{ zone.number }})">
<span class="slider"></span>
<span class="labels" data-on="A" data-off="M"></span>
</label>
</td>
<td class="property">{{ translater.getTranslation("operating mode") }}:</td>
<td class="value">{{translater.getTranslation("automatic mode") if zone.autoMode else translater.getTranslation("manual mode")}}</td>
<td>
<button onclick="executeAction('switch_zone_mode','{{ zone.number }}', '{{ 'manual' if zone.autoMode else 'automatic' }}')">{{translater.getTranslation("switch to manual mode") if zone.autoMode else translater.getTranslation("switch to automatic mode")}}</button>
</td>
</tr>
<tr>
<td class="icon">
<span class="outer_dot">
<span class="inner_icon {{ 'dot_green' if(zone.actualHumidity >= zone.desiredHumidity) else 'dot_red' }}"></span>
</span>
</td>
<td class="property">{{ translater.getTranslation("actual humidity") }}:</td>
<td class="value">{{ zone.actualHumidity}}</td>
</tr>
<tr>
<td class="icon">
</td>
<td class="property">{{ translater.getTranslation("desired humidity") }}:</td>
<td class="value">{{ zone.desiredHumidity }}</td>
</tr>
</tbody>
</table>
<p class="zone_number">{{ zone.number }}</p>

View File

@ -14,6 +14,52 @@
var varString = 'command=' + command + '&index=' + index + '&value=' + value;
send_web_request(url, messageString, varString, elementId);
}
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'));
sleep(1000).then(() => {
refreshZone(zone);
refreshPipeline();
});
}
function switchZoneState(command, zone, value) {
executeAction(command, zone, value);
sleep(1000).then(() => {
refreshZone(zone);
refreshPipeline();
});
}
function switchZoneStateByValueID(command, zone, valueID, valueFactor) {
executeActionByValueID(command, zone, valueID, valueFactor);
sleep(1000).then(() => {
refreshZone(zone);
refreshPipeline();
});
}
function deleteJobsForZone(command, zone) {
executeAction(command, zone);
sleep(1000).then(() => {
refreshZone(zone);
refreshPipeline();
});
}
function deleteJobById(command, jobId, zone) {
executeAction(command, jobId);
sleep(1000).then(() => {
refreshZone(zone);
refreshPipeline();
});
}
setInterval(refreshContent, {{ (zoneManager.systemSettings.cronJobFrequency + 1) * 1000 }})
</script>

View File

@ -91,6 +91,8 @@ class Webserver:
if (index):
zone = self.zoneManager.getZone(index)
return render_template('dashboard/zone.html', translater=self.translater, zoneManager=self.zoneManager, zone=zone)
case "get_dashboard_pipeline_html":
return render_template("dashboard/pipeline.html", translater=self.translater, zoneManager=self.zoneManager)
case "get_zone_list":
return self.zoneManager.zonesToJSON()
case "get_zone_info":
@ -111,9 +113,9 @@ class Webserver:
@app.route('/zones/<zoneNumber>')
def showZones(zoneNumber=False):
if (zoneNumber):
return render_template('zone.html', translater=self.translater, zone=self.zoneManager.getZone(zoneNumber))
return render_template('zones/zone.html', translater=self.translater, zone=self.zoneManager.getZone(zoneNumber))
else:
return render_template('zones.html', translater=self.translater, zones=self.zoneManager.zones)
return render_template('zones/zones.html', translater=self.translater, zones=self.zoneManager.zones)
@app.route('/times')
def showTimes():

View File

@ -1,8 +1 @@
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'))
}

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=[1, 5, 10, 15, 20, 25, 30, 45, 60])
systemSettings = SystemSettings(cronJobFrequency=2, 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)
@ -15,7 +15,7 @@ def cronJobs():
while True:
zoneManager.cronJobs()
print("Cronjobs done\nactual Time: " + str(time.time()))
time.sleep(0.5)
time.sleep(systemSettings.cronJobFrequency)
if __name__ == "__main__":
cronjob_Thread = threading.Thread(target=cronJobs)