refactoring
This commit is contained in:
parent
777e225d0b
commit
a949f4d261
17
.project
Normal file
17
.project
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>RelayBoxWebApp</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.python.pydev.PyDevBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.python.pydev.pythonNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -7,10 +7,17 @@ from twisted.web.resource import Resource
|
||||
from twisted.web.static import File
|
||||
|
||||
#import paho.mqtt.client as mqtt
|
||||
#import json
|
||||
import json
|
||||
|
||||
logfile = 'laundry.log'
|
||||
|
||||
switchMapping = {
|
||||
'oven': { 'index': 1, 'label': 'Herd' },
|
||||
'laundry': { 'index': 2, 'label': 'Waschkueche' },
|
||||
'kitchen': { 'index': 0, 'label': 'Kueche' },
|
||||
}
|
||||
|
||||
|
||||
loadedSwitchStates = ['x0', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7']
|
||||
|
||||
|
||||
@ -89,6 +96,13 @@ class SwitchStatus(MyResource):
|
||||
return state
|
||||
|
||||
|
||||
class SwitchMapping(MyResource):
|
||||
isLeaf = False
|
||||
|
||||
def render_GET(self, request):
|
||||
return json.dumps(switchMapping,indent=2, separators=(',', ': '))
|
||||
|
||||
|
||||
#mqttClient = mqtt.Client()
|
||||
#mqttClient.on_message = on_message
|
||||
#mqttClient.connect("mqttbroker", 1883, 60)
|
||||
@ -100,6 +114,7 @@ root.putChild("", File("index.html"))
|
||||
root.putChild("Hello", HelloWorld())
|
||||
root.putChild("switchCommand", SwitchCommand())
|
||||
root.putChild("switchStatus", SwitchStatus())
|
||||
root.putChild("switchMapping", SwitchMapping())
|
||||
|
||||
factory = Site(root, logPath='laundryServer.log')
|
||||
|
||||
|
15
index.html
15
index.html
@ -8,11 +8,11 @@
|
||||
<script>
|
||||
$("document").ready(function() {
|
||||
var serverAddress = '127.0.0.1:8080';
|
||||
var switchMapping = {
|
||||
'kitchen': { 'index': 0, 'label': 'Kueche' },
|
||||
'oven': { 'index': 1, 'label': 'Herd' },
|
||||
'laundry': { 'index': 2, 'label': 'Waschkueche' },
|
||||
};
|
||||
|
||||
$.ajaxSetup({
|
||||
async: false
|
||||
});
|
||||
var switchMapping = $.getJSON('http://' + serverAddress + '/switchMapping').responseJSON;
|
||||
var firstListItem = $("li:first", "#switchlist");
|
||||
for (var key in switchMapping) {
|
||||
var newListItem = firstListItem.clone()
|
||||
@ -44,7 +44,6 @@
|
||||
function updateState() {
|
||||
for (var key in switchMapping) {
|
||||
$.ajax({
|
||||
async:false,
|
||||
url: 'http://' + serverAddress + '/switchStatus?target=' + switchMapping[key]['index'],
|
||||
success: function(data) {
|
||||
$('#state' + key).text(data);
|
||||
@ -70,10 +69,6 @@
|
||||
<div data-role="main" class="ui-content">
|
||||
<ul id="switchlist" data-role="listview" data-inset="true" data-count-theme="b">
|
||||
<li><a class="switchlink" id="itemEmpty0" href="#dialog?switch=0"><span id="labelEmpty0">Vorlage</span> <span id="statusEmpty0" class="ui-li-count">on</span></a></li>
|
||||
<!--
|
||||
<li><a class="switchlink" id="oven" href="#dialog?switch=1"><span>Herd</span> <span id="stateHerd" class="ui-li-count">on</span></a></li>
|
||||
<li><a class="switchlink" id="laundry" href="#dialog?switch=2"><span>Waschküche</span> <span id="stateWaschkueche" class="ui-li-count">off</span></a></li>
|
||||
-->
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user