Compare commits

..
21 changed files with 732 additions and 254 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
class SystemSettings: 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.dataDir = dataDir
self.multiZoneIrrigation = multiZoneIrrigation self.multiZoneIrrigation = multiZoneIrrigation
self.defaultAutoIrrigationDuration = defaultAutoIrrigationDuration self.defaultAutoIrrigationDuration = defaultAutoIrrigationDuration
+23
View File
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="de">
<head>
<title>{{ translater.getTranslation("Irrigation") }}{{ translater.getTranslation("system") }}</title>
</head>
<body>
{% include "header.html" %}
<main>
<h2>Action</h2>
<div>
<p>
Sucess: {{ sucess }}
</p>
</div>
</main>
</body>
</html>
-161
View File
@@ -1,161 +0,0 @@
<!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>
</head>
<body>
{% include "header.html" %}
<main>
<h2>{{ translater.getTranslation("Dashboard") }}</h2>
<h3>{{ translater.getTranslation("planed irrigationjobs") }}</h3>
<div id="pipeline">
<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="executeAction('delete_job_by_id','{{ job.id }}', 0)">{{ translater.getTranslation("delete") }}</button></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<h3>{{ translater.getTranslation("irrigation zones") }}</h3>
<div id="zones">
{% for zone in zoneManager.zones %}
<div id="zone_{{ zone.number }}" class="zone">
<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">
{{ 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="executeActionByValueID({{'"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>
</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="executeAction({{'"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="executeAction('delete_jobs_for_zone','{{ zone.number }}', 0)">{{ translater.getTranslation("delete") }}</button>
</td>
</tr>
{% endif %}
<tr>
<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="H"></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>
</div>
{% endfor %}
</div>
</main>
<p><br><br></p>
</body>
</html>
@@ -0,0 +1,109 @@
{% include "header.html" %}
<!DOCTYPE html>
<html lang="de">
<head>
<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>
<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 src="{{ url_for('static', filename='js/dashboard.js') }}"></script>
<script>
function refreshContent() {
executeAction('get_dashboard_pipeline_html', '0', '0', refreshPipeline);
{% for zone in zoneManager.zones %}
executeAction('get_zone_info', {{ zone.number }}, '0', refreshZone);
{% endfor %}
}
function buttonDeleteJobById(jobId) {
if(jobId == "all") {
if(confirm('{{ translater.getTranslation("delete all planed and cancel running jobs?")}}')){
document.getElementById("jobListBody").innerHTML = "";
} else {
return
}
} else {
var jobToDelete = document.getElementById("job_" + jobId);
document.getElementById("jobListBody").removeChild(jobToDelete);
}
deleteJobById('delete_job_by_id',jobId);
}
</script>
</head>
<body>
<main>
<h2>{{ translater.getTranslation("Dashboard") }}</h2>
<div id="pipeline" class="scrollingtable">
<div id="jobListTable">
<div>
<table>
<caption>{{ translater.getTranslation("planed irrigationjobs") }}</caption>
<thead id="jobListHead">
<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" %}
</tbody>
</table>
</div>
<p id="text_no_jobs">{{ translater.getTranslation("currently there are no planned jobs.")}}</p>
<button id="button_delete_all_jobs" onclick="buttonDeleteJobById('all')">{{ translater.getTranslation("delete and cancel all jobs")}}</button>
</div>
</div>
<h3>{{ translater.getTranslation("irrigation zones") }}</h3>
<button onclick="switchZoneMode(false, 'all')">{{ translater.getTranslation("switch all to")}} {{ translater.getTranslation("manual mode") }}</button>
<button onclick="switchZoneMode(true, 'all')">{{ translater.getTranslation("switch all to")}} {{ translater.getTranslation("automatic mode") }}</button>
<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>
{% include "footer.html" %}
@@ -0,0 +1,7 @@
<tr id="job_{{ job.id }}">
<!-- <td>{{ job.id }}</td> -->
<td>{{ job.zone.number|string}}</td>
<td>{{job.zone.name }}</td>
<td>{{ ((job.duration/60))|string + " " + translater.getTranslation("minutes")}}</td>
<td><button onclick="buttonDeleteJobById('{{ job.id }}')">{{ translater.getTranslation("delete") }}</button></td>
</tr>
@@ -0,0 +1,9 @@
{% for job in zoneManager.pipeLine %}
{% include "dashboard/irrigationJob.html" %}
{% endfor %}
+79
View File
@@ -0,0 +1,79 @@
<a href="/zones/{{ zone.number}}">
<h4 id="name_zone_{{ zone.number }}">{{ zone.name }}</h3>
</a>
<table>
<tbody>
<tr>
<td class="icon">
<span class="outer_dot">
<span id="inner_icon_state_zone_{{ zone.number }}"></span>
</span>
</td>
<td class="property">{{ translater.getTranslation("state") }}:</td>
<td class="value" id="state_text_zone_{{ zone.number }}"></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_on','{{ zone.number }}', 'duration_zone_{{ zone.number }}', 60)">{{ translater.getTranslation("turn on") }}</button>
<button onclick="switchZoneStateByValueID('switch_zone_off','{{ zone.number }}', 'duration_zone_{{ zone.number }}', 60)">{{ translater.getTranslation("turn off") }}</button>
</td>
</tr>
<tr id="end_time_row_zone_{{ zone.number }}">
<td></td>
<td></td>
<td>
{{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("irrigation is planed.") }}<br>{{ translater.getTranslation("planed duration")}}: <p id="planed_duration_zone{{ zone.number }}" class="planed_duration_value"></p> {{ translater.getTranslation("minutes") + "." }}
</td>
<td>
<button onclick="deleteJobsForZone('delete_jobs_for_zone','{{ zone.number }}')">{{ translater.getTranslation("delete") }}</button>
</td>
</tr>
<tr>
<td class="icon">
<span class="outer_dot">
<p id="inner_icon_mode_zone_{{ zone.number }}" class="inner_icon"></p>
</span>
</td>
<td>
<label class="toggle">
<input type="checkbox" id="slider_state_zone_{{ zone.number }}" 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 id="mode_text_zone_{{ zone.number }}" class="value"></td>
</tr>
<tr>
<td class="icon">
<span class="outer_dot">
<span id="inner_icon_humidity_zone_{{ zone.number }}"></span>
</span>
</td>
<td class="property">{{ translater.getTranslation("actual humidity") }}:</td>
<td id="acutal_humidity_zone_{{ zone.number }}" class="value"></td>
</tr>
<tr>
<td class="icon">
</td>
<td class="property">{{ translater.getTranslation("desired humidity") }}:</td>
<td id="desired_humidity_zone_{{ zone.number }}" class="value"></td>
</tr>
</tbody>
</table>
<p class="zone_number">{{ zone.number }}</p>
+15
View File
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
</head>
<body>
</body>
</html>
<script>
refreshContent();
setInterval(refreshContent, {{ (zoneManager.systemSettings.cronJobFrequency + 5) * 1000 }})
</script>
+45 -40
View File
@@ -1,49 +1,54 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="de"> <html lang="de">
<head> <head>
<link rel="stylesheet" href="{{ url_for('static', filename='Styles/header.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='Styles/header.css') }}">
<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 src="{{ url_for('static', filename='js/action.js') }}"></script>
<script src="{{ url_for('static', filename='js/webhook.js') }}"></script>
<script>
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
<script> function executeAction(command, index, value, handleResponse) {
function executeAction(command, index, value) { var url = '{{url_for("executeAction")}}';
send_web_request('{{url_for("executeAction")}}/' + command + '/' + index + '/' + value, 'no', 'variable'); var messageString = 'no';
} var varString = 'command=' + command + '&index=' + index + '&value=' + value;
function executeActionByValueID(command, index, valueID, valueFactor){ send_web_request(url, messageString, varString, handleResponse);
var value = document.getElementById(valueID).value * valueFactor; }
executeAction(command, index, value); function executeActionByValueID(command, index, valueID, valueFactor){
} var value = document.getElementById(valueID).value * valueFactor;
function switchZoneMode(autoMode, zone) { executeAction(command, index, value);
executeAction('switch_zone_mode' ,zone, (autoMode ? 'automatic' : 'manual')) }
} </script>
</script>
</head>
<body>
<header>
<nav>
<ul>
{% for item in nav.top %}
<li {{ 'class=active' if item.is_active else '' }}>
<a href="{{ item.url }}">
{{ item.label }}
</a>
</li>
{% endfor %}
</ul>
</nav>
<a class="heading" href="{{ url_for('startPage')}}">
<img src="{{ url_for('static', filename='img/header/wassertropfen.png') }}" alt="" class="title-img">
<h1>{{ translater.getTranslation("Irrigation") }}-<br>{{ translater.getTranslation("system") }}</h1> </head>
</a> <body>
<header>
<nav>
<ul>
{% for item in nav.top %}
<li {{ 'class=active' if item.is_active else '' }}>
<a href="{{ item.url }}">
{{ item.label }}
</a>
</li>
{% endfor %}
</ul>
</nav>
<img src="{{ url_for('static', filename='img/header/blumenbeet.jpg') }}" alt="" class="header-img"> <a class="heading" href="{{ url_for('startPage')}}">
<img src="{{ url_for('static', filename='img/header/wassertropfen.png') }}" alt="" class="title-img">
</header> <h1>{{ translater.getTranslation("Irrigation") }}-<br>{{ translater.getTranslation("system") }}</h1>
<script src="{{ url_for('static', filename='js/webhook.js') }}"></script> </a>
</body>
<img src="{{ url_for('static', filename='img/header/blumenbeet.jpg') }}" alt="" class="header-img">
</header>
</body>
</html> </html>
+18 -1
View File
@@ -1,4 +1,6 @@
from enum import Enum from enum import Enum
from time import strftime
from time import gmtime
class Language(Enum): class Language(Enum):
ENGLISH = 1 ENGLISH = 1
GERMAN = 2 GERMAN = 2
@@ -27,11 +29,15 @@ class Translater:
"switch to automatic mode": "Auf Automatikbetrieb umstellen", "switch to automatic mode": "Auf Automatikbetrieb umstellen",
"minutes": "Minuten", "minutes": "Minuten",
"until": "bis", "until": "bis",
"irragation is planed for": "Bewässerung ist geplant für", "irrigation is planed.": "Bewässerung ist geplant.",
"planed irrigationjobs": "geplante Bewässerungsaufträge", "planed irrigationjobs": "geplante Bewässerungsaufträge",
"planed duration": "geplante Dauer", "planed duration": "geplante Dauer",
"cancel": "abbrechen", "cancel": "abbrechen",
"delete": "löschen", "delete": "löschen",
"delete and cancel all jobs": "alle Aufträge löschen und abbrechen",
"switch all to": "stelle alle um auf",
"currently there are no planned jobs.": "momentan sind keine Aufträge geplant.",
"delete all planed and cancel running jobs?": "Sollen alle geplanten Aufträge gelöscht und laufende abgerochen werden?",
} }
@@ -43,3 +49,14 @@ class Translater:
return self.dict_german[english_String] return self.dict_german[english_String]
case _: case _:
return "no translations for these language" return "no translations for these language"
def formatTime(self, timeInt):
format = ""
match self.language:
case Language.ENGLISH:
format = "%I.%S %p"
case Language.GERMAN:
format = "%H:%M:%S"
case _:
format = ""
return strftime(format, gmtime(timeInt))
+78 -31
View File
@@ -33,75 +33,122 @@ class Webserver:
return redirect(url_for('showDashboard')) return redirect(url_for('showDashboard'))
@app.route('/action', methods=['GET', 'POST']) @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): def executeAction(command=False, index_str=False, value_str=False):
sucess = False if(request.method == 'POST'):
try: try:
index = int(index_str) command = request.form['command']
value = int(value_str) except:
except: pass
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
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):
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=True, duration=value) self.zoneManager.switchZoneIndexState(zoneIndex=index, state=True, duration=value)
sucess = True return "True"
elif(index): elif(index):
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=True, duration=self.zoneManager.systemSettings.defaultManualIrrigationDuration) self.zoneManager.switchZoneIndexState(zoneIndex=index, state=True, duration=self.zoneManager.systemSettings.defaultManualIrrigationDuration)
sucess = True return "True"
case "switch_zone_off": case "switch_zone_off":
if (index and value): if (index and value):
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=False, duration=value, instant=True) self.zoneManager.switchZoneIndexState(zoneIndex=index, state=False, duration=value, instant=True)
sucess = True return "True"
elif(index): elif(index):
self.zoneManager.switchZoneIndexState(zoneIndex=index, state=False, duration=self.zoneManager.systemSettings.defaultManualOffDuration, instant=True) self.zoneManager.switchZoneIndexState(zoneIndex=index, state=False, duration=self.zoneManager.systemSettings.defaultManualOffDuration, instant=True)
sucess = True return "True"
case "switch_zone_mode": case "switch_zone_mode":
if (index and value_str): zonesToSwitch = []
zone = self.zoneManager.getZone(index) if(index_str == "all" and value_str):
match value_str: zonesToSwitch = self.zoneManager.zones
case "automatic": elif (index and value_str):
zone.switchMode(autoMode=True) zonesToSwitch.append(self.zoneManager.getZone(index))
sucess = True else:
case "manual": return "False"
zone.switchMode(autoMode=False) automode = False
sucess = True if(value_str == "automatic"):
automode = True
elif(value_str == "manual"):
automode = False
else:
return "False"
for zone in zonesToSwitch:
zone.switchMode(autoMode=automode)
return "True"
case "set_desired_humidity": case "set_desired_humidity":
if (index and value): if (index and value):
zone = self.zoneManager.getZone(index) zone = self.zoneManager.getZone(index)
zone.desiredHumidity = value zone.desiredHumidity = value
sucess = True return "True"
case "delete_jobs_for_zone": case "delete_jobs_for_zone":
if (index): if (index):
zone = self.zoneManager.getZone(index) zone = self.zoneManager.getZone(index)
self.zoneManager.deleteIrrigationJobsForZone(zone) self.zoneManager.deleteIrrigationJobsForZone(zone)
return "True"
case "delete_job_by_id": case "delete_job_by_id":
if(index_str == "all"):
self.zoneManager.clearIrrigationJobs()
return "True"
if (index): if (index):
self.zoneManager.deleteIrrigationJobByID(index) self.zoneManager.deleteIrrigationJobByID(index)
return "True"
case "get_dashboard_zone_html":
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(self.translater)
case "get_zone_info":
if (index):
zone = self.zoneManager.getZone(index)
return zone.toJSON(self.translater)
case "get_pipeline":
return self.zoneManager.pipelineToJSON(self.translater)
return "False"
return render_template('action.html', translater=self.translater, zones=self.zoneManager.zones, sucess=sucess)
@app.route('/dashboard') @app.route('/dashboard')
def showDashboard(): def showDashboard():
return render_template('dashboard.html', translater=self.translater, zoneManager=self.zoneManager) return render_template('dashboard/dashboard.html', translater=self.translater, zoneManager=self.zoneManager)
@app.route('/zones') @app.route('/zones')
@app.route('/zones/<zoneNumber>') @app.route('/zones/<zoneNumber>')
def showZones(zoneNumber=False): def showZones(zoneNumber=False):
if (zoneNumber): if (zoneNumber):
return render_template('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.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)
+6
View File
@@ -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;
}
+121
View File
@@ -0,0 +1,121 @@
.scrollingtable {
box-sizing: border-box;
display: inline-block;
vertical-align: middle;
overflow: hidden;
width: auto; /*set table width here if using fixed value*/
min-width: 100%; /*set table width here if using %*/
height: 300px; /*set table height here; can be fixed value or %*/
min-height: 104px; /*if using % height, make this at least large enough to fit scrollbar arrows + captions + thead */
font-family: Verdana, Tahoma, sans-serif;
font-size: 15px;
line-height: 25px;
padding-top: 25px; /*this determines top caption height*/
padding-bottom: 25px; /*this determines bottom caption height*/
text-align: left;
}
#button_delete_all_jobs{
margin-top: 25px;
}
.scrollingtable * {box-sizing: border-box;}
.scrollingtable > div {
position: relative;
border-top: 1px solid black; /*top table border*/
height: 100%;
padding-top: 25px; /*this determines column header height*/
}
.scrollingtable > div:before {
top: 0;
background: cornflowerblue; /*column header background color*/
}
.scrollingtable > div:before,
.scrollingtable > div > div:after {
content: "";
position: absolute;
z-index: -1;
width: 100%;
height: 50%;
left: 0;
}
.scrollingtable > div > div {
/*min-height: 43px;*/ /*if using % height, make this at least large enough to fit scrollbar arrows*/
max-height: 200px;
overflow: scroll; /*set to auto if using fixed or % width; else scroll*/
overflow-x: hidden;
border: 1px solid black; /*border around table body*/
}
.scrollingtable > div > div:after {background: white;} /*match page background color*/
.scrollingtable > div > div > table {
width: 100%;
border-spacing: 0;
margin-top: -25px; /*inverse of column header height*/
/*margin-right: 17px;*/ /*uncomment if using % width*/
}
.scrollingtable > div > div > table > caption {
position: absolute;
top: -25px; /*inverse of caption height*/
margin-top: -1px; /*inverse of border-width*/
width: 100%;
font-weight: bold;
text-align: left;
}
.scrollingtable > div > div > table > * > tr > * {padding: 0;}
.scrollingtable > div > div > table > thead {
vertical-align: bottom;
white-space: nowrap;
text-align: left;
}
.scrollingtable > div > div > table > thead > tr > * > div {
display: inline-block;
padding: 0 6px 0 6px; /*header cell padding*/
}
.scrollingtable > div > div > table > thead > tr > :first-child:before {
content: "";
position: absolute;
top: 0;
left: 0;
height: 25px; /*match column header height*/
border-left: 1px solid black; /*leftmost header border*/
}
.scrollingtable > div > div > table > thead > tr > * > div[label]:before,
.scrollingtable > div > div > table > thead > tr > * > div > div:first-child,
.scrollingtable > div > div > table > thead > tr > * + :before {
position: absolute;
top: 0;
white-space: pre-wrap;
color: white; /*header row font color*/
}
.scrollingtable > div > div > table > thead > tr > * > div[label]:before,
.scrollingtable > div > div > table > thead > tr > * > div[label]:after {content: attr(label);}
.scrollingtable > div > div > table > thead > tr > * + :before {
content: "";
display: block;
min-height: 25px; /*match column header height*/
padding-top: 1px;
border-left: 1px solid black; /*borders between header cells*/
}
.scrollingtable .scrollbarhead {float: right;}
.scrollingtable .scrollbarhead:before {
position: absolute;
width: 100px;
top: -1px; /*inverse border-width*/
background: white; /*match page background color*/
}
.scrollingtable > div > div > table > tbody > tr:after {
content: "";
display: table-cell;
position: relative;
padding: 0;
border-top: 1px solid black;
top: -1px; /*inverse of border width*/
}
.scrollingtable > div > div > table > tbody {vertical-align: top;}
.scrollingtable > div > div > table > tbody > tr {background: white;}
.scrollingtable > div > div > table > tbody > tr > * {
border-bottom: 1px solid black;
padding: 0 6px 0 6px;
height: 25px; /*match column header height*/
}
.scrollingtable > div > div > table > tbody:last-of-type > tr:last-child > * {border-bottom: none;}
.scrollingtable > div > div > table > tbody > tr:nth-child(even) {background: gainsboro;} /*alternate row color*/
.scrollingtable > div > div > table > tbody > tr > * + * {border-left: 1px solid black;} /*borders between body cells*/
+32
View File
@@ -0,0 +1,32 @@
function switchZoneMode(autoMode, zone) {
executeAction('switch_zone_mode' ,zone, (autoMode ? 'automatic' : 'manual'));
sleep(1000).then(() => {
refreshContent();
});
}
function switchZoneState(command, zone, value) {
executeAction(command, zone, value);
sleep(1000).then(() => {
refreshContent();
});
}
function switchZoneStateByValueID(command, zone, valueID, valueFactor) {
executeActionByValueID(command, zone, valueID, valueFactor);
sleep(1000).then(() => {
refreshContent();
});
}
function deleteJobsForZone(command, zone) {
executeAction(command, zone);
sleep(1000).then(() => {
refreshContent();
});
}
function deleteJobById(command, jobId) {
executeAction(command, jobId);
sleep(1000).then(() => {
refreshContent();
});
}
+32
View File
@@ -0,0 +1,32 @@
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.endTimeSetStateFormated;
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 refreshPipeline(pipeline_html) {
//alert("refreshing Pipeline");
var jobListBody = document.getElementById("jobListBody");
jobListBody.innerHTML = pipeline_html;
if(!jobListBody.childElementCount){
document.getElementById("button_delete_all_jobs").style.display = 'none';
document.getElementById("text_no_jobs").style.display = 'block';
} else {
document.getElementById("button_delete_all_jobs").style.display = 'block';
document.getElementById("text_no_jobs").style.display = 'none';
}
}
+70
View File
@@ -0,0 +1,70 @@
function send_web_request(url, messageString, varString, handleResponse) {
// Browserkompatibles Request-Objekt erzeugen:
r = null;
if(window.XMLHttpRequest)
{
r = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
try
{
r = new ActiveXObject('Msxml2.XMLHTTP');
}
catch(e1)
{
try
{
r = new ActiveXObject('Microsoft.XMLHTTP');
}
catch(e2)
{
alert("Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.");
}
}
}
// Wenn Request-Objekt vorhanden, dann Anfrage senden:
if(r != null)
{
r.open('POST', url, true);
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);
if(messageString != 'no')
{
alert(messageString);
}
sleep(500).then(() => {
//window.location.href = window.location.href;
//document.location.reload();
});
}
else
{
alert("Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.");
}
}
+36 -5
View File
@@ -1,4 +1,5 @@
import time import time
import json
class Zone: class Zone:
@@ -13,6 +14,22 @@ class Zone:
self.endTimeSetState = endTimeSetState self.endTimeSetState = endTimeSetState
self.planedDuration = planedDuration self.planedDuration = planedDuration
def toJSON(self, translater):
return {
"number": self.number,
"name": self.name,
"actualHumidity": self.actualHumidity,
"desiredHumidity": self.desiredHumidity,
"autoMode": self.autoMode,
"operationMode_text": translater.getTranslation("automatic mode" if self.autoMode else "manual mode"),
"state": self.state,
"state_text": translater.getTranslation("switched on" if self.state else "switched off"),
"setState": self.setState,
"endTimeSetState" : self.endTimeSetState,
"endTimeSetStateFormated" : translater.formatTime(self.endTimeSetState),
"planedDuration": self.planedDuration,
}
def setZoneManager(self, zoneManager): def setZoneManager(self, zoneManager):
self.zoneManager = zoneManager self.zoneManager = zoneManager
@@ -29,13 +46,19 @@ class Zone:
self.zoneManager.switchZoneState(zone=self, state=True, duration=self.zoneManager.systemSettings.defaultAutoIrrigationDuration, instant=False) self.zoneManager.switchZoneState(zone=self, state=True, duration=self.zoneManager.systemSettings.defaultAutoIrrigationDuration, instant=False)
case 1: case 1:
if(self.timeOver()): if(self.timeOver()):
self.setState = 0 if (self.planedDuration > 0):
self.setState = 3
else:
self.setState = 0
self.refreshStateAutomode() self.refreshStateAutomode()
else: else:
self.state = False self.state = False
case 2: case 2:
if (self.timeOver()): if (self.timeOver()):
self.setState = 0 if (self.planedDuration > 0):
self.setState = 3
else:
self.setState = 0
self.refreshStateAutomode() self.refreshStateAutomode()
else: else:
self.state = True self.state = True
@@ -54,11 +77,17 @@ class Zone:
self.setState = 3 self.setState = 3
case 1: case 1:
if(self.timeOver()): if(self.timeOver()):
self.setState = 0 if (self.planedDuration > 0):
self.setState = 3
else:
self.setState = 0
self.state = False self.state = False
case 2: case 2:
if (self.timeOver()): if (self.timeOver()):
self.setState = 0 if (self.planedDuration > 0):
self.setState = 3
else:
self.setState = 0
self.state = False self.state = False
else: else:
self.state = True self.state = True
@@ -89,7 +118,9 @@ class Zone:
self.setState = 2 self.setState = 2
self.endTimeSetState = time.time() + duration self.endTimeSetState = time.time() + duration
else: else:
if(state): if(self.setState == 1 or self.setState == 2):
pass
elif(state):
self.setState = 3 self.setState = 3
self.refreshState() self.refreshState()
+45 -10
View File
@@ -1,6 +1,7 @@
import json
import threading import threading
from random import Random from random import Random
from time import time
from FileIO import FileIO from FileIO import FileIO
@@ -15,6 +16,20 @@ class ZoneManager:
self.pipeLine = [] self.pipeLine = []
self.piplineMutexLock = threading.Lock() self.piplineMutexLock = threading.Lock()
def zonesToJSON(self, translater):
zoneList = []
for zone in self.zones:
zoneList.append(zone.toJSON(translater))
return zoneList
def pipelineToJSON(self, translater):
jobList = []
with self.piplineMutexLock:
for irrigationJob in self.pipeLine:
jobList.append(irrigationJob.toJSON(translater))
return jobList
def getZone(self, number): def getZone(self, number):
for zone in self.zones: for zone in self.zones:
if(zone.number == number): if(zone.number == number):
@@ -45,6 +60,12 @@ class ZoneManager:
else: else:
i = i + 1 i = i + 1
def clearIrrigationJobs(self):
with self.piplineMutexLock:
self.pipeLine = []
for zone in self.zones:
self.switchZoneState(zone=zone, state=False, duration=-1, instant=True)
def isAnyZoneBusy(self): def isAnyZoneBusy(self):
for zone in self.zones: for zone in self.zones:
if(zone.state): if(zone.state):
@@ -52,14 +73,16 @@ 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))
def switchZoneIndexState(self, zoneIndex, state, duration, instant=False): def switchZoneIndexState(self, zoneIndex, state, duration, instant=False):
zone = self.getZone(zoneIndex) zone = self.getZone(zoneIndex)
self.switchZoneState(zone, state, duration, instant) self.switchZoneState(zone=zone, state=state, duration=duration, instant=instant)
def getPlanedDurationForZone(self, zone): def getPlanedDurationForZone(self, zone):
totalDuration = 0 totalDuration = 0
@@ -75,13 +98,18 @@ class ZoneManager:
def processPipeline(self): def processPipeline(self):
self.piplineMutexLock.acquire() self.piplineMutexLock.acquire()
if(len(self.pipeLine) > 0 and (not self.isAnyZoneBusy())): index = 0
irrigationJob = self.pipeLine[0] while(len(self.pipeLine) > index and (not self.isAnyZoneBusy())):
self.pipeLine.pop(0) irrigationJob = self.pipeLine[index]
self.piplineMutexLock.release() if(not irrigationJob.zone.setState == 1):
irrigationJob.process() self.pipeLine.pop(index)
else: self.piplineMutexLock.release()
self.piplineMutexLock.release() irrigationJob.process()
return
else:
index = index + 1
self.piplineMutexLock.release()
@@ -100,5 +128,12 @@ 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, translater):
return {
"id": self.id,
"zone": self.zone.toJSON(translater),
"duration": self.duration,
}
def process(self): def process(self):
self.zone.switchState(state=True, duration=self.duration, instant=True) self.zone.switchState(state=True, duration=self.duration, instant=True)
+2 -2
View File
@@ -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(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)
@@ -15,7 +15,7 @@ def cronJobs():
while True: while True:
zoneManager.cronJobs() zoneManager.cronJobs()
print("Cronjobs done\nactual Time: " + str(time.time())) print("Cronjobs done\nactual Time: " + str(time.time()))
time.sleep(0.5) time.sleep(systemSettings.cronJobFrequency)
if __name__ == "__main__": if __name__ == "__main__":
cronjob_Thread = threading.Thread(target=cronJobs) cronjob_Thread = threading.Thread(target=cronJobs)