Skip to content

Commit b25c62d

Browse files
committed
Further codacy changes
1 parent 9a65a1e commit b25c62d

File tree

7 files changed

+186
-172
lines changed

7 files changed

+186
-172
lines changed

homemon-server/homemon-server.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ io.sockets.on("connection", function (socket) {
7878
var length = 0;
7979
var emitted = 0;
8080
// since this is a new subscription, emit all historised messages to setup client with initial values
81-
for (i in topicHistory) {
81+
for (var i in topicHistory) {
8282
length++;
8383
// only emit if less that 30 seconds old
8484
if (((time - topicHistoryTimeStamp[i]) / 1000) < 300) {
@@ -139,46 +139,58 @@ mqttclient.on("connect", function() {
139139

140140
if (topic.beginsWith("sensors/power")) {
141141
var name = null;
142-
if (names[topic] != undefined) name = names[topic].name;
142+
if (names[topic] != undefined) {
143+
name = names[topic].name;
144+
}
143145
messageString = value.toFixed(0);
144-
io.sockets.in("power").emit("data", { topic: topic, value: messageString, name: name });
146+
io.sockets.in("power").emit("data", { topic: topic, value: messageString, name: name1 });
145147
}
146148

147149
if (topic.beginsWith("sensors/power") || topic.beginsWith("rate/sensors/snmp/router/total")
148150
|| topic.beginsWith("sensors/power") || topic.beginsWith("sensors/co/") || topic.beginsWith("sensors/co2/")
149151
|| topic.beginsWith("sensors/no2") || topic.beginsWith("sensors/pressure")) {
150-
var name = null;
151-
if (names[topic] != undefined) name = names[topic].name;
152+
var name1 = null;
153+
if (names[topic] != undefined) {
154+
name = names[topic].name;
155+
}
152156
io.sockets.in("sensors").emit("data", { topic: topic, value: messageString, name: name });
153157
}
154158

155159
if (topic.beginsWith("sensors/co/") || topic.beginsWith("sensors/co2/")
156160
|| topic.beginsWith("sensors/temperature/") || topic.beginsWith("sensors/humidity/")
157161
|| topic.beginsWith("sensors/no2") || topic.beginsWith("sensors/pressure")) {
158162
var name = null;
159-
if (names[topic] != undefined) name = names[topic].name;
163+
if (names[topic] != undefined) {
164+
name = names[topic].name;
165+
}
160166
io.sockets.in("sensors2").emit("data", { topic: topic, value: messageString, name: name });
161167
}
162168

163169
if (topic.beginsWith("sensors/iosbattery")) {
164170
var name = null;
165-
if (names[topic] != undefined) name = names[topic].name;
171+
if (names[topic] != undefined) {
172+
name = names[topic].name;
173+
}
166174
var p = value * 100;
167175
messageString = p.toFixed(0);
168176
io.sockets.in("sensors").emit("data", { topic: topic, value: messageString, name: name });
169177
}
170178

171179
if (topic.beginsWith("sensors/humidity")) {
172180
var name = null;
173-
if (names[topic] != undefined) name = names[topic].name;
181+
if (names[topic] != undefined) {
182+
name = names[topic].name;
183+
}
174184
messageString = value.toFixed(0) + "%";
175185
io.sockets.in("sensors").emit("data", { topic: topic, value: messageString, name: name });
176186
io.sockets.in("humidity").emit("data", { topic: topic, value: messageString, name: name });
177187
}
178188

179189
if (topic.beginsWith("sensors/temperature") || topic.beginsWith("sensors/boiler")) {
180190
var name = null;
181-
if (names[topic] != undefined) name = names[topic].name;
191+
if (names[topic] != undefined) {
192+
name = names[topic].name;
193+
}
182194
messageString = value.toFixed(1);
183195
io.sockets.in("sensors").emit("data", { topic: topic, value: messageString, name: name });
184196
io.sockets.in("temperature").emit("data", { topic: topic, value: messageString, name: name });

homemon-server/public/javascripts/powerbar.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
ElementExists = function(id) {
2-
return !!document.getElementById(id);
2+
return !!document.getElementById(id);
33
};
44
BeginsWith = function(needle, haystack) {
55
return (haystack.substr(0, needle.length) == needle);
66
}
77

88
// Load the Visualization API and the piechart package.
9-
google.load('visualization', '1.0', {'packages':['corechart','table']});
9+
google.load("visualization", "1.0", {"packages":["corechart","table"]});
1010

1111
// Set a callback to run when the Google Visualization API is loaded.
1212
google.setOnLoadCallback(drawChart);
1313

1414

1515
function drawChart() {
16-
var data = new google.visualization.DataTable();
16+
var data = new google.visualization.DataTable();
1717

18-
data.addColumn('string', 'Label');
19-
data.addRow();
18+
data.addColumn("string", "Label");
19+
data.addRow();
2020

2121
// Instantiate and draw our chart
2222
var options = {height: 300,
23-
legend: {position: 'none'},
24-
animation: { duration: 250, easing: 'linear'},
25-
isStacked: true};
23+
legend: {position: "none"},
24+
animation: { duration: 250, easing: "linear"},
25+
isStacked: true};
2626

27-
var chart = new google.visualization.BarChart(document.getElementById('powerbar'));
28-
// var table = new google.visualization.Table(document.getElementById('powertable'));
27+
var chart = new google.visualization.BarChart(document.getElementById("powerbar"));
28+
// var table = new google.visualization.Table(document.getElementById("powertable"));
2929

30-
data.addColumn('number', 'Unknown');
30+
data.addColumn("number", "Unknown");
3131
data.setCell(0, 1, 0);
3232

3333

3434
var updates = 0;
3535
var socket = io.connect("http://homemon.trease.eu:8500/");
3636
socket.emit("subscribe", { room: "power" });
37-
socket.on('data', function(message) {
38-
37+
socket.on("data", function(message) {
38+
3939
var done = false;
4040
for (var i = 0; i < data.getNumberOfColumns(); i++) {
4141
if (data.getColumnLabel(i) == message.name) {
@@ -45,17 +45,17 @@ function drawChart() {
4545
}
4646
}
4747
if (done == false) {
48-
data.addColumn('number', message.name);
48+
data.addColumn("number", message.name);
4949
for (var i = 0; i < data.getNumberOfColumns(); i++) {
5050
if (data.getColumnLabel(i) == message.name) {
5151
data.setCell(0, i, parseInt(message.value, 10));
5252
break;
5353
}
5454
}
55-
}
55+
}
5656
chart.draw(data, options);
5757

58-
var dt = new Date();
58+
var dt = new Date();
5959
document.getElementById("time").innerHTML= dt.toLocaleTimeString();
6060
document.getElementById("updates").innerHTML= ++updates;
6161
});

homemon-server/public/javascripts/pushmessage.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
ElementExists = function(id) {
2-
return !document.getElementById(id);
3-
}
4-
2+
return !document.getElementById(id);
3+
};
4+
55
var updates = 0;
66

77
var socket = io.connect("http://homemon.trease.eu:8500");
88
socket.emit("subscribe", { room: "pushmessage" });
99
socket.on('data', function(data) {
1010
var dt = new Date();
1111
var table=document.getElementById("messagetable");
12-
12+
1313
var row = table.insertRow(0);
1414

1515
var cell = row.insertCell(0);
1616
cell.innerHTML = data.topic;
1717
var cell = row.insertCell(0);
1818
cell.style.width="15%";
1919
cell.innerHTML = dt.toLocaleTimeString();
20-
20+
2121
// print the time the refresh happened
2222
document.getElementById("time").innerHTML = dt.toLocaleTimeString();
2323
document.getElementById("updates").innerHTML = ++updates;

homemon-server/public/javascripts/sensors.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
ElementExists = function(id) {
2-
return !!document.getElementById(id);
2+
return !!document.getElementById(id);
33
};
44

55
// function to if a string starts with nother one
66
String.prototype.beginsWith = function (string) {
7-
return(this.indexOf(string) === 0);
7+
return(this.indexOf(string) === 0);
88
};
99

1010

@@ -14,60 +14,60 @@ var updates = 0;
1414

1515
var socket = io.connect("http://homemon.trease.eu:8500");
1616
socket.emit("subscribe", { room: "sensors" });
17-
socket.on('data', function(data) {
17+
socket.on("data", function(data) {
1818
// console.log("Message received " + data.topic + " of " + data.value);
1919

2020
// check the target topic exisits & if not create a target table entry
2121
if (!ElementExists (data.topic)) {
2222
// console.log("Creating target " + data.topic);
2323
if (data.topic.beginsWith("sensors/power/")) {
24-
var table=document.getElementById("myTablePower").getElementsByTagName('tbody')[0];
24+
var table=document.getElementById("myTablePower").getElementsByTagName("tbody")[0];
2525
} else if (data.topic.beginsWith("sensors/boiler/")) {
26-
var table=document.getElementById("myTableTemp").getElementsByTagName('tbody')[0];
26+
var table=document.getElementById("myTableTemp").getElementsByTagName("tbody")[0];
2727
} else if (data.topic.beginsWith("rate/sensors/snmp/router/")) {
28-
var table=document.getElementById("myRouterRate").getElementsByTagName('tbody')[0];
28+
var table=document.getElementById("myRouterRate").getElementsByTagName("tbody")[0];
2929
} else if (data.topic.beginsWith("sensors/iosbattery/")) {
30-
var table=document.getElementById("myBattery").getElementsByTagName('tbody')[0];
30+
var table=document.getElementById("myBattery").getElementsByTagName("tbody")[0];
3131
} else if (data.topic.beginsWith("sensors/temperature/")) {
32-
var table=document.getElementById("myTableTemp").getElementsByTagName('tbody')[0];
32+
var table=document.getElementById("myTableTemp").getElementsByTagName("tbody")[0];
3333
} else if (data.topic.beginsWith("sensors/humidity/")) {
34-
var table=document.getElementById("myTableHumidity").getElementsByTagName('tbody')[0];
34+
var table=document.getElementById("myTableHumidity").getElementsByTagName("tbody")[0];
3535
} else if (data.topic.beginsWith("sensors/co/")) {
36-
var table=document.getElementById("myTableCO").getElementsByTagName('tbody')[0];
36+
var table=document.getElementById("myTableCO").getElementsByTagName("tbody")[0];
3737
} else if (data.topic.beginsWith("sensors/co2/")) {
38-
var table=document.getElementById("myTableCO2").getElementsByTagName('tbody')[0];
38+
var table=document.getElementById("myTableCO2").getElementsByTagName("tbody")[0];
3939
} else if (data.topic.beginsWith("sensors/no2/")) {
40-
var table=document.getElementById("myTableNO2").getElementsByTagName('tbody')[0];
40+
var table=document.getElementById("myTableNO2").getElementsByTagName("tbody")[0];
4141
} else if (data.topic.beginsWith("sensors/pressure/")) {
42-
var table=document.getElementById("myTablePressure").getElementsByTagName('tbody')[0];
42+
var table=document.getElementById("myTablePressure").getElementsByTagName("tbody")[0];
4343
} else {
4444
console.log ("topic " + data.topic + " not known");
4545
}
46-
46+
4747
// var row=table.insertRow(count);
4848
var row=table.insertRow(table.rows.length);
4949
var cell=row.insertCell(0);
5050
cell.id = data.topic;
5151
var cell=row.insertCell(0);
5252
cell.id = data.topic + "name";
53-
53+
5454
document.getElementById(data.topic).style.textAlign="right";
5555
document.getElementById(data.topic).style.width="25%";
5656
if(data.name != undefined) { // label cell based on emitted friendly name
5757
document.getElementById(data.topic + "name").innerHTML = data.name;
5858
} else { // label ce;; based on topic name
59-
document.getElementById(data.topic + "name").innerHTML = data.topic.slice(data.topic.lastIndexOf('/')+1);
59+
document.getElementById(data.topic + "name").innerHTML = data.topic.slice(data.topic.lastIndexOf("/")+1);
6060
}
6161
document.getElementById(data.topic + "name").style.textAlign="left";
6262
document.getElementById(data.topic + "name").style.width="65%";
6363
}
6464
// new we know there is a target, update it
6565
// console.log("Setting target " + data.topic + " to " + data.value);
66-
66+
6767
if (ElementExists (data.topic)) {
6868
document.getElementById(data.topic).innerHTML= data.value;
6969
}
70-
70+
7171
// print the time the refresh happened
7272
var dt = new Date();
7373
document.getElementById("time").innerHTML= dt.toLocaleTimeString();

homemon-server/public/javascripts/sensors2.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,65 @@ ElementExists = function(id) {
44

55
// function to if a string starts with nother one
66
String.prototype.beginsWith = function (string) {
7-
return(this.indexOf(string) === 0);
7+
return(this.indexOf(string) === 0);
88
};
99

1010

11-
var myvalues = [];
1211
var updates = 0;
1312

1413

1514
var socket = io.connect("http://homemon.trease.eu:8500");
1615
socket.emit("subscribe", { room: "sensors2" });
17-
socket.on('data', function(data) {
16+
socket.on("data", function(data) {
1817
// console.log("Message received " + data.topic + " of " + data.value);
1918

2019

2120
// check the target topic exisits & if not create a target table entry
2221
if (!ElementExists (data.topic)) {
23-
var table=document.getElementById("myTable").getElementsByTagName('tbody')[0];
24-
22+
var table=document.getElementById("myTable").getElementsByTagName("tbody")[0];
23+
2524
// var row=table.insertRow(count);
26-
device = data.topic.substring(data.topic.lastIndexOf('/')+1);
25+
device = data.topic.substring(data.topic.lastIndexOf("/")+1);
2726
console.log("creating new row for " + device + " as " + data.name);
28-
27+
2928
var row=table.insertRow(table.rows.length);
30-
29+
3130
var cell=row.insertCell(0);
3231
cell.id = "sensors/co2/" + device;
33-
32+
3433
var cell=row.insertCell(0);
3534
cell.id = "sensors/co/" + device;
36-
35+
3736
var cell=row.insertCell(0);
3837
cell.id = "sensors/no2/" + device;
39-
38+
4039
var cell=row.insertCell(0);
4140
cell.id = "sensors/humidity/" + device;
42-
41+
4342
var cell=row.insertCell(0);
4443
cell.id = "sensors/pressure/" + device;
45-
44+
4645
var cell=row.insertCell(0);
4746
cell.id = "sensors/temperature/" + device;
48-
47+
4948
var cell=row.insertCell(0);
5049
cell.id = device + "name";
51-
52-
50+
51+
5352
if(data.name != undefined) { // label cell based on emitted friendly name
5453
document.getElementById(device + "name").innerHTML = data.name;
5554
} else { // label ce;; based on topic name
56-
document.getElementById(device + "name").innerHTML = data.topic.slice(data.topic.lastIndexOf('/')+1);
55+
document.getElementById(device + "name").innerHTML = data.topic.slice(data.topic.lastIndexOf("/")+1);
5756
}
5857
}
59-
58+
6059
if (ElementExists (data.topic)) {
6160
document.getElementById(data.topic).style.textAlign="center";
6261
document.getElementById(data.topic).innerHTML= data.value;
6362
}
64-
63+
6564
// print the time the refresh happened
66-
var dt = new Date();
65+
var dt = new Date();
6766
document.getElementById("time").innerHTML= dt.toLocaleTimeString();
6867
document.getElementById("updates").innerHTML= ++updates;
6968
});

0 commit comments

Comments
 (0)