implemented autorefresh
This commit is contained in:
parent
ba3afd129d
commit
b1c371d9b3
|
@ -1,7 +1,9 @@
|
||||||
|
{% include "header.html" %}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='Styles/dashboard.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='Styles/dashboard.css') }}">
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='Styles/scrollingTable.css') }}">
|
||||||
|
|
||||||
<title>{{ translater.getTranslation("Irrigation") }}{{ translater.getTranslation("system") }}</title>
|
<title>{{ translater.getTranslation("Irrigation") }}{{ translater.getTranslation("system") }}</title>
|
||||||
|
|
||||||
|
@ -24,26 +26,8 @@
|
||||||
|
|
||||||
</style>
|
</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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% include "header.html" %}
|
|
||||||
|
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
@ -51,15 +35,29 @@
|
||||||
<h2>{{ translater.getTranslation("Dashboard") }}</h2>
|
<h2>{{ translater.getTranslation("Dashboard") }}</h2>
|
||||||
|
|
||||||
|
|
||||||
<h3>{{ translater.getTranslation("planed irrigationjobs") }}</h3>
|
<div id="pipeline" class="scrollingtable">
|
||||||
<p>
|
<div>
|
||||||
<button onclick="refreshPipeline()">
|
<div>
|
||||||
refresh
|
<table>
|
||||||
</button>
|
<caption>{{ translater.getTranslation("planed irrigationjobs") }}</caption>
|
||||||
</p>
|
<thead>
|
||||||
<div id="pipeline">
|
<tr>
|
||||||
|
<th><div label="Nr."></div></th>
|
||||||
|
<th><div label="{{ translater.getTranslation("Zone") }}"></div></th>
|
||||||
|
<th><div label="{{ translater.getTranslation("planed duration") }}"></div></th>
|
||||||
|
<th><div label="{{ translater.getTranslation("delete") }}"></div></th>
|
||||||
|
<th class="scrollbarhead"></th> <!--ALWAYS ADD THIS EXTRA CELL AT END OF HEADER ROW-->
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="jobListBody">
|
||||||
{% include "dashboard/pipeline.html" %}
|
{% include "dashboard/pipeline.html" %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
Text unter Table
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>{{ translater.getTranslation("irrigation zones") }}</h3>
|
<h3>{{ translater.getTranslation("irrigation zones") }}</h3>
|
||||||
|
@ -80,3 +78,42 @@
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
<script>
|
||||||
|
function refreshZone(zone_json) {
|
||||||
|
const zone = JSON.parse(zone_json);
|
||||||
|
document.getElementById("name_zone_" + zone.number).innerHTML = zone.name;
|
||||||
|
document.getElementById("inner_icon_state_zone_" + zone.number).className = 'inner_icon ' + (zone.state ? 'dot_green' : 'dot_red');
|
||||||
|
document.getElementById("state_text_zone_" + zone.number).innerHTML = zone.state_text;
|
||||||
|
document.getElementById("end_time_row_zone_" + zone.number).style.display = ((zone.setState == 1 || zone.setState == 2) ? 'table-row' : 'none');
|
||||||
|
document.getElementById("end_time_zone_" + zone.number).innerHTML = zone.endTimeSetState;
|
||||||
|
document.getElementById("planed_duration_row_zone_" + zone.number).style.display = ((zone.planedDuration > 0) ? 'table-row' : 'none');
|
||||||
|
document.getElementById("planed_duration_zone" + zone.number).innerHTML = zone.planedDuration/60;
|
||||||
|
document.getElementById("inner_icon_mode_zone_" + zone.number).innerHTML = zone.autoMode ? 'A' : 'M';
|
||||||
|
document.getElementById("slider_state_zone_" + zone.number).checked = zone.autoMode ? true : false;
|
||||||
|
document.getElementById("mode_text_zone_" + zone.number).innerHTML = zone.operationMode_text;
|
||||||
|
document.getElementById("inner_icon_humidity_zone_" + zone.number).className = 'inner_icon ' + ((zone.actualHumidity >= zone.desiredHumidity) ? 'dot_green' : 'dot_red');
|
||||||
|
document.getElementById("acutal_humidity_zone_" + zone.number).innerHTML = zone.actualHumidity;
|
||||||
|
document.getElementById("desired_humidity_zone_" + zone.number).innerHTML = zone.desiredHumidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buttonDeleteJobById(jobId) {
|
||||||
|
deleteJobById('delete_job_by_id',jobId);
|
||||||
|
var jobToDelete = document.getElementById("job_" + jobId);
|
||||||
|
document.getElementById("jobListBody").removeChild(jobToDelete);
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshPipeline(pipeline_html) {
|
||||||
|
document.getElementById("jobListBody").innerHTML = pipeline_html;
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshContent() {
|
||||||
|
executeAction('get_dashboard_pipeline_html', '0', '0', refreshPipeline);
|
||||||
|
{% for zone in zoneManager.zones %}
|
||||||
|
executeAction('get_zone_info', {{ zone.number }}, '0', refreshZone);
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
refreshContent();
|
||||||
|
</script>
|
||||||
|
{% include "footer.html" %}
|
|
@ -1,21 +1,9 @@
|
||||||
<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 %}
|
{% for job in zoneManager.pipeLine %}
|
||||||
<tr>
|
{% include "dashboard/irrigationJob.html" %}
|
||||||
<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 %}
|
{% endfor %}
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,91 +1,78 @@
|
||||||
|
|
||||||
<a href="/zones/{{ zone.number}}">
|
<a href="/zones/{{ zone.number}}">
|
||||||
<h4>{{ zone.name }}</h3>
|
<h4 id="name_zone_{{ zone.number }}">{{ zone.name }}</h3>
|
||||||
</a>
|
</a>
|
||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="icon">
|
<td class="icon">
|
||||||
<span class="outer_dot">
|
<span class="outer_dot">
|
||||||
<span class="inner_icon {{ 'dot_green' if zone.state else 'dot_red' }}"></span>
|
<span id="inner_icon_state_zone_{{ zone.number }}"></span>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="property">{{ translater.getTranslation("state") }}:</td>
|
<td class="property">{{ translater.getTranslation("state") }}:</td>
|
||||||
<td class="value" id="state_text_zone_{{ zone.number }}">
|
<td class="value" id="state_text_zone_{{ zone.number }}"></td>
|
||||||
{{ translater.getTranslation("switched on") if zone.state else translater.getTranslation("switched off") }}
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
<select id="duration_zone_{{ zone.number }}">
|
<select id="duration_zone_{{ zone.number }}">
|
||||||
{% for option in zoneManager.systemSettings.webDurationOptions %}
|
{% for option in zoneManager.systemSettings.webDurationOptions %}
|
||||||
<option value="{{ option }}">{{ option }} {{ translater.getTranslation("minutes") }}</option>
|
<option value="{{ option }}">{{ option }} {{ translater.getTranslation("minutes") }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</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>
|
<button onclick="switchZoneStateByValueID('switch_zone_on','{{ zone.number }}', 'duration_zone_{{ zone.number }}', 60)">{{ translater.getTranslation("turn on") }}</button>
|
||||||
</td>
|
<button onclick="switchZoneStateByValueID('switch_zone_off','{{ zone.number }}', 'duration_zone_{{ zone.number }}', 60)">{{ translater.getTranslation("turn off") }}</button>
|
||||||
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
<tr id="end_time_row_zone_{{ zone.number }}">
|
||||||
{% if zone.planedDuration > 0 %}
|
|
||||||
<tr>
|
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td>
|
<td>
|
||||||
{{translater.getTranslation("irragation is planed for") + " " + ((zone.planedDuration/60)|int)|string + " " + translater.getTranslation("minutes") + "." }}
|
{{translater.getTranslation("until") }} <p id="end_time_zone_{{ zone.number }}" class="end_time_value"></p>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button onclick="switchZoneState('switch_zone_off','{{ zone.number }}', -1)">{{ translater.getTranslation("cancel") }}</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr id="planed_duration_row_zone_{{ zone.number }}">
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
<td>
|
||||||
|
{{translater.getTranslation("irragation is planed for") }} <p id="planed_duration_zone{{ zone.number }}" class="planed_duration_value"></p> {{ translater.getTranslation("minutes") + "." }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button onclick="deleteJobsForZone('delete_jobs_for_zone','{{ zone.number }}')">{{ translater.getTranslation("delete") }}</button>
|
<button onclick="deleteJobsForZone('delete_jobs_for_zone','{{ zone.number }}')">{{ translater.getTranslation("delete") }}</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="icon">
|
<td class="icon">
|
||||||
<span class="outer_dot">
|
<span class="outer_dot">
|
||||||
<p class="inner_icon">{{'A' if zone.autoMode else 'M'}}</p>
|
<p id="inner_icon_mode_zone_{{ zone.number }}" class="inner_icon"></p>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<label class="toggle">
|
<label class="toggle">
|
||||||
<input type="checkbox" {{ "checked" if zone.autoMode }} onchange="switchZoneMode(this.checked, {{ zone.number }})">
|
<input type="checkbox" id="slider_state_zone_{{ zone.number }}" onchange="switchZoneMode(this.checked, {{ zone.number }})">
|
||||||
<span class="slider"></span>
|
<span class="slider"></span>
|
||||||
<span class="labels" data-on="A" data-off="M"></span>
|
<span class="labels" data-on="A" data-off="M"></span>
|
||||||
</label>
|
</label>
|
||||||
</td>
|
</td>
|
||||||
<td class="property">{{ translater.getTranslation("operating mode") }}:</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 id="mode_text_zone_{{ zone.number }}" class="value"></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>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="icon">
|
<td class="icon">
|
||||||
<span class="outer_dot">
|
<span class="outer_dot">
|
||||||
<span class="inner_icon {{ 'dot_green' if(zone.actualHumidity >= zone.desiredHumidity) else 'dot_red' }}"></span>
|
<span id="inner_icon_humidity_zone_{{ zone.number }}"></span>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="property">{{ translater.getTranslation("actual humidity") }}:</td>
|
<td class="property">{{ translater.getTranslation("actual humidity") }}:</td>
|
||||||
<td class="value">{{ zone.actualHumidity}}</td>
|
<td id="acutal_humidity_zone_{{ zone.number }}" class="value"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="icon">
|
<td class="icon">
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="property">{{ translater.getTranslation("desired humidity") }}:</td>
|
<td class="property">{{ translater.getTranslation("desired humidity") }}:</td>
|
||||||
<td class="value">{{ zone.desiredHumidity }}</td>
|
<td id="desired_humidity_zone_{{ zone.number }}" class="value"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -5,14 +5,16 @@
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='Styles/main.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='Styles/main.css') }}">
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='Styles/switch.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='Styles/switch.css') }}">
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<!-- <meta http-equiv="refresh" content="5" > -->
|
|
||||||
<script>
|
<script>
|
||||||
|
function sleep (time) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, time));
|
||||||
|
}
|
||||||
|
|
||||||
function executeAction(command, index, value, elementId) {
|
function executeAction(command, index, value, handleResponse) {
|
||||||
var url = '{{url_for("executeAction")}}';
|
var url = '{{url_for("executeAction")}}';
|
||||||
var messageString = 'no';
|
var messageString = 'no';
|
||||||
var varString = 'command=' + command + '&index=' + index + '&value=' + value;
|
var varString = 'command=' + command + '&index=' + index + '&value=' + value;
|
||||||
send_web_request(url, messageString, varString, elementId);
|
send_web_request(url, messageString, varString, handleResponse);
|
||||||
}
|
}
|
||||||
function executeActionByValueID(command, index, valueID, valueFactor){
|
function executeActionByValueID(command, index, valueID, valueFactor){
|
||||||
var value = document.getElementById(valueID).value * valueFactor;
|
var value = document.getElementById(valueID).value * valueFactor;
|
||||||
|
@ -24,42 +26,37 @@
|
||||||
function switchZoneMode(autoMode, zone) {
|
function switchZoneMode(autoMode, zone) {
|
||||||
executeAction('switch_zone_mode' ,zone, (autoMode ? 'automatic' : 'manual'));
|
executeAction('switch_zone_mode' ,zone, (autoMode ? 'automatic' : 'manual'));
|
||||||
sleep(1000).then(() => {
|
sleep(1000).then(() => {
|
||||||
refreshZone(zone);
|
refreshContent();
|
||||||
refreshPipeline();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
function switchZoneState(command, zone, value) {
|
function switchZoneState(command, zone, value) {
|
||||||
executeAction(command, zone, value);
|
executeAction(command, zone, value);
|
||||||
sleep(1000).then(() => {
|
sleep(1000).then(() => {
|
||||||
refreshZone(zone);
|
refreshContent();
|
||||||
refreshPipeline();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function switchZoneStateByValueID(command, zone, valueID, valueFactor) {
|
function switchZoneStateByValueID(command, zone, valueID, valueFactor) {
|
||||||
executeActionByValueID(command, zone, valueID, valueFactor);
|
executeActionByValueID(command, zone, valueID, valueFactor);
|
||||||
sleep(1000).then(() => {
|
sleep(1000).then(() => {
|
||||||
refreshZone(zone);
|
refreshContent();
|
||||||
refreshPipeline();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function deleteJobsForZone(command, zone) {
|
function deleteJobsForZone(command, zone) {
|
||||||
executeAction(command, zone);
|
executeAction(command, zone);
|
||||||
sleep(1000).then(() => {
|
sleep(1000).then(() => {
|
||||||
refreshZone(zone);
|
refreshContent();
|
||||||
refreshPipeline();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function deleteJobById(command, jobId, zone) {
|
function deleteJobById(command, jobId) {
|
||||||
executeAction(command, jobId);
|
executeAction(command, jobId);
|
||||||
sleep(1000).then(() => {
|
sleep(1000).then(() => {
|
||||||
refreshZone(zone);
|
refreshContent();
|
||||||
refreshPipeline();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
setInterval(refreshContent, {{ (zoneManager.systemSettings.cronJobFrequency + 1) * 1000 }})
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,21 @@ class Webserver:
|
||||||
value = int(value_str)
|
value = int(value_str)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
elif(request.method == 'GET'):
|
||||||
|
try:
|
||||||
|
command = request.args['command']
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
index_str = request.args['index']
|
||||||
|
index = int(index_str)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
value_str = request.args['value']
|
||||||
|
value = int(value_str)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
match command:
|
match command:
|
||||||
case "switch_zone_on":
|
case "switch_zone_on":
|
||||||
if (index and value):
|
if (index and value):
|
||||||
|
@ -94,15 +109,14 @@ class Webserver:
|
||||||
case "get_dashboard_pipeline_html":
|
case "get_dashboard_pipeline_html":
|
||||||
return render_template("dashboard/pipeline.html", translater=self.translater, zoneManager=self.zoneManager)
|
return render_template("dashboard/pipeline.html", translater=self.translater, zoneManager=self.zoneManager)
|
||||||
case "get_zone_list":
|
case "get_zone_list":
|
||||||
return self.zoneManager.zonesToJSON()
|
return self.zoneManager.zonesToJSON(self.translater)
|
||||||
case "get_zone_info":
|
case "get_zone_info":
|
||||||
if (index):
|
if (index):
|
||||||
zone = self.zoneManager.getZone(index)
|
zone = self.zoneManager.getZone(index)
|
||||||
return zone.toJSON()
|
return zone.toJSON(self.translater)
|
||||||
case "get_pipeline":
|
case "get_pipeline":
|
||||||
return self.zoneManager.pipelineToJSON()
|
return self.zoneManager.pipelineToJSON(self.translater)
|
||||||
return self.zoneManager.zonesToJSON()
|
return render_template('action.html', translater=self.translater, zones=self.zoneManager.zones, sucess=sucess)
|
||||||
#return render_template('action.html', translater=self.translater, zones=self.zoneManager.zones, sucess=sucess)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/dashboard')
|
@app.route('/dashboard')
|
||||||
|
@ -113,16 +127,16 @@ class Webserver:
|
||||||
@app.route('/zones/<zoneNumber>')
|
@app.route('/zones/<zoneNumber>')
|
||||||
def showZones(zoneNumber=False):
|
def showZones(zoneNumber=False):
|
||||||
if (zoneNumber):
|
if (zoneNumber):
|
||||||
return render_template('zones/zone.html', translater=self.translater, zone=self.zoneManager.getZone(zoneNumber))
|
return render_template('zones/zone.html', translater=self.translater, zoneManager=self.zoneManager, zone=self.zoneManager.getZone(zoneNumber))
|
||||||
else:
|
else:
|
||||||
return render_template('zones/zones.html', translater=self.translater, zones=self.zoneManager.zones)
|
return render_template('zones/zones.html', translater=self.translater, zoneManager=self.zoneManager)
|
||||||
|
|
||||||
@app.route('/times')
|
@app.route('/times')
|
||||||
def showTimes():
|
def showTimes():
|
||||||
return render_template('times.html', translater=self.translater)
|
return render_template('times.html', translater=self.translater, zoneManager=self.zoneManager)
|
||||||
|
|
||||||
@app.route('/system')
|
@app.route('/system')
|
||||||
def showSystem():
|
def showSystem():
|
||||||
return render_template('system.html', translater=self.translater)
|
return render_template('system.html', translater=self.translater, zoneManager=self.zoneManager)
|
||||||
|
|
||||||
app.run(debug=True, port=self.port)
|
app.run(debug=True, host="0.0.0.0", port=self.port)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
|
||||||
|
|
||||||
#zones{
|
#zones{
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(3, 1fr);
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
@ -57,6 +59,10 @@ td.value{
|
||||||
text-align: left;
|
text-align: left;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
p.end_time_value, p.planed_duration_value {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,4 @@
|
||||||
function sleep (time) {
|
function send_web_request(url, messageString, varString, handleResponse) {
|
||||||
|
|
||||||
return new Promise((resolve) => setTimeout(resolve, time));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function send_web_request(url, messageString, varString, elementId) {
|
|
||||||
// Browserkompatibles Request-Objekt erzeugen:
|
// Browserkompatibles Request-Objekt erzeugen:
|
||||||
r = null;
|
r = null;
|
||||||
|
|
||||||
|
@ -40,17 +32,20 @@ function send_web_request(url, messageString, varString, elementId) {
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// HTTP-POST
|
|
||||||
r.onreadystatechange = function() {
|
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
|
||||||
document.getElementById(elementId).innerHTML = this.responseText;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
r.open('POST', url, true);
|
r.open('POST', url, true);
|
||||||
|
|
||||||
r.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
r.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||||
|
|
||||||
|
if(handleResponse != null) {
|
||||||
|
// HTTP-POST
|
||||||
|
r.onreadystatechange = function() {
|
||||||
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
|
handleResponse(this.responseText);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
r.send(varString);
|
r.send(varString);
|
||||||
|
|
||||||
|
|
||||||
|
|
4
Zone.py
4
Zone.py
|
@ -14,14 +14,16 @@ class Zone:
|
||||||
self.endTimeSetState = endTimeSetState
|
self.endTimeSetState = endTimeSetState
|
||||||
self.planedDuration = planedDuration
|
self.planedDuration = planedDuration
|
||||||
|
|
||||||
def toJSON(self):
|
def toJSON(self, translater):
|
||||||
return {
|
return {
|
||||||
"number": self.number,
|
"number": self.number,
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
"actualHumidity": self.actualHumidity,
|
"actualHumidity": self.actualHumidity,
|
||||||
"desiredHumidity": self.desiredHumidity,
|
"desiredHumidity": self.desiredHumidity,
|
||||||
"autoMode": self.autoMode,
|
"autoMode": self.autoMode,
|
||||||
|
"operationMode_text": translater.getTranslation("automatic mode" if self.autoMode else "manual mode"),
|
||||||
"state": self.state,
|
"state": self.state,
|
||||||
|
"state_text": translater.getTranslation("switched on" if self.state else "switched off"),
|
||||||
"setState": self.setState,
|
"setState": self.setState,
|
||||||
"endTimeSetState" : self.endTimeSetState,
|
"endTimeSetState" : self.endTimeSetState,
|
||||||
"planedDuration": self.planedDuration,
|
"planedDuration": self.planedDuration,
|
||||||
|
|
|
@ -16,17 +16,17 @@ class ZoneManager:
|
||||||
self.pipeLine = []
|
self.pipeLine = []
|
||||||
self.piplineMutexLock = threading.Lock()
|
self.piplineMutexLock = threading.Lock()
|
||||||
|
|
||||||
def zonesToJSON(self):
|
def zonesToJSON(self, translater):
|
||||||
zoneList = []
|
zoneList = []
|
||||||
for zone in self.zones:
|
for zone in self.zones:
|
||||||
zoneList.append(zone.toJSON())
|
zoneList.append(zone.toJSON(translater))
|
||||||
return zoneList
|
return zoneList
|
||||||
|
|
||||||
def pipelineToJSON(self):
|
def pipelineToJSON(self, translater):
|
||||||
jobList = []
|
jobList = []
|
||||||
with self.piplineMutexLock:
|
with self.piplineMutexLock:
|
||||||
for irrigationJob in self.pipeLine:
|
for irrigationJob in self.pipeLine:
|
||||||
jobList.append(irrigationJob.toJSON())
|
jobList.append(irrigationJob.toJSON(translater))
|
||||||
return jobList
|
return jobList
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,7 +67,9 @@ class ZoneManager:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def switchZoneState(self, zone, state, duration, instant=False):
|
def switchZoneState(self, zone, state, duration, instant=False):
|
||||||
if(instant or self.systemSettings.multiZoneIrrigation or state==False ): #or (not self.isAnyZoneBusy())
|
if(not duration > 0):
|
||||||
|
zone.switchState(state=False, duration=0, instant=True)
|
||||||
|
elif(instant or self.systemSettings.multiZoneIrrigation or state==False ): #or (not self.isAnyZoneBusy())
|
||||||
zone.switchState(state=state, duration=duration, instant=True)
|
zone.switchState(state=state, duration=duration, instant=True)
|
||||||
else:
|
else:
|
||||||
self.addIrrigationJob(IrrigationJob(id=self.random.randint(a=100000000, b=999999999), zone=zone, duration=duration))
|
self.addIrrigationJob(IrrigationJob(id=self.random.randint(a=100000000, b=999999999), zone=zone, duration=duration))
|
||||||
|
@ -115,10 +117,10 @@ class IrrigationJob:
|
||||||
self.duration = duration
|
self.duration = duration
|
||||||
self.zone.switchState(state=True, duration=duration, instant=False)
|
self.zone.switchState(state=True, duration=duration, instant=False)
|
||||||
|
|
||||||
def toJSON(self):
|
def toJSON(self, translater):
|
||||||
return {
|
return {
|
||||||
"id": self.id,
|
"id": self.id,
|
||||||
"zone": self.zone.toJSON(),
|
"zone": self.zone.toJSON(translater),
|
||||||
"duration": self.duration,
|
"duration": self.duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
main.py
2
main.py
|
@ -6,7 +6,7 @@ from ZoneManager import ZoneManager
|
||||||
from SystemSettings import SystemSettings
|
from SystemSettings import SystemSettings
|
||||||
from FileIO import FileIO
|
from FileIO import FileIO
|
||||||
|
|
||||||
systemSettings = SystemSettings(cronJobFrequency=2, dataDir="/Data", multiZoneIrrigation=False, defaultAutoIrrigationDuration=10, defaultManualIrrigationDuration=10, defaultManualOffDuration=10, webDurationOptions=[1, 5, 10, 15, 20, 25, 30, 45, 60])
|
systemSettings = SystemSettings(cronJobFrequency=0.5, dataDir="/Data", multiZoneIrrigation=False, defaultAutoIrrigationDuration=10, defaultManualIrrigationDuration=10, defaultManualOffDuration=10, webDurationOptions=[1, 5, 10, 15, 20, 25, 30, 45, 60])
|
||||||
fileIO = FileIO(systemSettings)
|
fileIO = FileIO(systemSettings)
|
||||||
zoneManager = ZoneManager(systemSettings=systemSettings, fileIO=fileIO)
|
zoneManager = ZoneManager(systemSettings=systemSettings, fileIO=fileIO)
|
||||||
webserver = Webserver(zoneManager=zoneManager, port=80)
|
webserver = Webserver(zoneManager=zoneManager, port=80)
|
||||||
|
|
Loading…
Reference in New Issue