diff --git a/code/build.sh b/code/build.sh
index 1b84bb1c..8d532506 100755
--- a/code/build.sh
+++ b/code/build.sh
@@ -5,7 +5,7 @@ echo "--------------------------------------------------------------"
echo "ESPURNA FIRMWARE BUILDER"
# Available environments
-available=`cat platformio.ini | grep env: | grep -v ota | grep -v ssl | sed 's/\[env://' | sed 's/\]/ /' | sort`
+available=$(grep env: platformio.ini | grep -v ota | grep -v ssl | sed 's/\[env://' | sed 's/\]/ /' | sort)
environments=$@
if [ "$environments" == "list" ]; then
echo "--------------------------------------------------------------"
@@ -22,7 +22,7 @@ if [ $# -eq 0 ]; then
fi
# Get current version
-version=`cat espurna/config/version.h | grep APP_VERSION | awk '{print $3}' | sed 's/"//g'`
+version=$(grep APP_VERSION espurna/config/version.h | awk '{print $3}' | sed 's/"//g')
echo "Building for version $version"
# Create output folder
diff --git a/code/espurna/pwm.c b/code/espurna/pwm.c
index 9a316bb8..0e3794c1 100644
--- a/code/espurna/pwm.c
+++ b/code/espurna/pwm.c
@@ -209,7 +209,6 @@ _pwm_phases_prep(struct pwm_phase* pwm)
{
uint8_t n, phases;
- uint16_t off_mask = 0;
for (n = 0; n < pwm_channels + 2; n++) {
pwm[n].ticks = 0;
pwm[n].on_mask = 0;
diff --git a/code/espurna/sensors/EmonSensor.h b/code/espurna/sensors/EmonSensor.h
index ad12189c..e82e7b05 100644
--- a/code/espurna/sensors/EmonSensor.h
+++ b/code/espurna/sensors/EmonSensor.h
@@ -147,15 +147,16 @@ class EmonSensor : public I2CSensor {
double read(unsigned char channel) {
- int sample;
int max = 0;
int min = _adc_counts;
- double filtered;
double sum = 0;
unsigned long time_span = millis();
for (unsigned long i=0; i<_samples; i++) {
+ int sample;
+ double filtered;
+
// Read analog value
sample = readADC(channel);
if (sample > max) max = sample;
diff --git a/code/gulpfile.js b/code/gulpfile.js
index 5b4db6c5..e78a8942 100644
--- a/code/gulpfile.js
+++ b/code/gulpfile.js
@@ -19,6 +19,9 @@ along with this program. If not, see .
*/
+/*eslint quotes: ["error", "single"]*/
+/*eslint-env es6*/
+
// -----------------------------------------------------------------------------
// File system builder
// -----------------------------------------------------------------------------
diff --git a/code/html/checkboxes.js b/code/html/checkboxes.js
index 42e1441b..115dd4f3 100644
--- a/code/html/checkboxes.js
+++ b/code/html/checkboxes.js
@@ -1,4 +1,7 @@
// Generated by CoffeeScript 1.6.2
+/*eslint quotes: ["error", "single"]*/
+/*eslint-env es6*/
+
(function() {
var iOSCheckbox, matched, userAgent,
__slice = [].slice;
diff --git a/code/html/custom.js b/code/html/custom.js
index 8e6ebacc..486a9af6 100644
--- a/code/html/custom.js
+++ b/code/html/custom.js
@@ -36,7 +36,9 @@ function sensorName(id) {
"Events", "PMSX003", "BMX280", "MHZ19", "SI7021",
"SHT3X I2C", "BH1750"
];
- if (1 <= id && id <= names.length) return names[id-1];
+ if (1 <= id && id <= names.length) {
+ return names[id-1];
+ }
return null;
}
@@ -48,7 +50,9 @@ function magnitudeType(type) {
"Analog", "Digital", "Events",
"PM1.0", "PM2.5", "PM10", "CO2", "Lux"
];
- if (1 <= type && type <= types.length) return types[type-1];
+ if (1 <= type && type <= types.length) {
+ return types[type-1];
+ }
return null;
}
@@ -57,7 +61,9 @@ function magnitudeError(error) {
"OK", "Out of Range", "Warming Up", "Timeout", "Wrong ID",
"CRC Error", "I2C Error", "GPIO Error"
];
- if (0 <= error && error < errors.length) return errors[error];
+ if (0 <= error && error < errors.length) {
+ return errors[error];
+ }
return "Error " + error;
}
@@ -74,7 +80,7 @@ function checkPassword(str) {
}
function zeroPad(number, positions) {
- var zeros = '';
+ var zeros = "";
for (var i = 0; i < positions; i++) zeros += "0";
return (zeros + number).slice(-positions);
}
@@ -89,7 +95,7 @@ function validateForm(form) {
}
var adminPass2 = $("input[name='adminPass']", form).last().val();
- if (adminPass1 != adminPass2) {
+ if (adminPass1 !== adminPass2) {
alert("Passwords are different!");
return false;
}
@@ -118,16 +124,18 @@ function getData(form) {
$("input,select", form).each(function() {
var name = $(this).attr("name");
if (name) {
+ var value = "";
// Do not report these fields
- if (name == "filename") return;
- if (name == "rfbcode") return;
+ if (name === "filename" || name === "rfbcode" ) {
+ return;
+ }
// Grab the value
- if ($(this).attr('type') == 'checkbox') {
- value = $(this).is(':checked') ? 1 : 0;
- } else if ($(this).attr('type') == 'radio') {
- if (!$(this).is(':checked')) return;
+ if ($(this).attr("type") === "checkbox") {
+ value = $(this).is(":checked") ? 1 : 0;
+ } else if ($(this).attr("type") === "radio") {
+ if (!$(this).is(":checked")) {return;}
value = $(this).val();
} else {
value = $(this).val();
@@ -158,20 +166,20 @@ function getData(form) {
}
function randomString(length, chars) {
- var mask = '';
- if (chars.indexOf('a') > -1) mask += 'abcdefghijklmnopqrstuvwxyz';
- if (chars.indexOf('A') > -1) mask += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- if (chars.indexOf('#') > -1) mask += '0123456789';
- if (chars.indexOf('@') > -1) mask += 'ABCDEF';
- if (chars.indexOf('!') > -1) mask += '~`!@#$%^&*()_+-={}[]:";\'<>?,./|\\';
- var result = '';
+ var mask = "";
+ if (chars.indexOf("a") > -1) mask += "abcdefghijklmnopqrstuvwxyz";
+ if (chars.indexOf("A") > -1) mask += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ if (chars.indexOf("#") > -1) mask += "0123456789";
+ if (chars.indexOf("@") > -1) mask += "ABCDEF";
+ if (chars.indexOf("!") > -1) mask += "~`!@#$%^&*()_+-={}[]:\";'<>?,./|\\";
+ var result = "";
for (var i = length; i > 0; --i) result += mask[Math.round(Math.random() * (mask.length - 1))];
return result;
}
function generateAPIKey() {
- var apikey = randomString(16, '@#');
- $("input[name=\"apiKey\"]").val(apikey);
+ var apikey = randomString(16, "@#");
+ $("input[name='apiKey']").val(apikey);
return false;
}
@@ -187,8 +195,15 @@ function getJson(str) {
// Actions
// -----------------------------------------------------------------------------
+function resetOriginals() {
+ $("input,select").each(function() {
+ $(this).attr("original", $(this).val());
+ })
+ numReboot = numReconnect = numReload = 0;
+}
+
function doReload(milliseconds) {
- milliseconds = (typeof milliseconds == 'undefined') ? 0 : parseInt(milliseconds);
+ milliseconds = (typeof milliseconds == "undefined") ? 0 : parseInt(milliseconds);
setTimeout(function() {
window.location.reload();
}, milliseconds);
@@ -201,11 +216,11 @@ function doUpdate() {
// Get data
var data = getData(form);
- websock.send(JSON.stringify({'config': data}));
+ websock.send(JSON.stringify({"config": data}));
// Empty special fields
$(".pwrExpected").val(0);
- $("input[name='pwrResetCalibration']")
+ $("input[name='"pwrResetCalibration"']")
.prop("checked", false)
.iphoneStyle("refresh");
@@ -215,13 +230,13 @@ function doUpdate() {
if (numReboot > 0) {
var response = window.confirm("You have to reboot the board for the changes to take effect, do you want to do it now?");
- if (response == true) doReboot(false);
+ if (response === true) doReboot(false);
} else if (numReconnect > 0) {
var response = window.confirm("You have to reconnect to the WiFi for the changes to take effect, do you want to do it now?");
- if (response == true) doReconnect(false);
+ if (response === true) doReconnect(false);
} else if (numReload > 0) {
var response = window.confirm("You have to reload the page to see the latest changes, do you want to do it now?");
- if (response == true) doReload();
+ if (response === true) doReload();
}
resetOriginals();
@@ -237,20 +252,20 @@ function doUpdate() {
function doUpgrade() {
var contents = $("input[name='upgrade']")[0].files[0];
- if (typeof contents == 'undefined') {
+ if (typeof contents === "undefined") {
alert("First you have to select a file from your computer.");
return false;
}
- var filename = $("input[name='upgrade']").val().split('\\').pop();
+ var filename = $("input[name='upgrade']").val().split("\\").pop();
var data = new FormData();
- data.append('upgrade', contents, filename);
+ data.append("upgrade", contents, filename);
$.ajax({
// Your server script to process the upload
- url: webhost + 'upgrade',
- type: 'POST',
+ url: webhost + "upgrade",
+ type: "POST",
// Form data
data: data,
@@ -261,9 +276,9 @@ function doUpgrade() {
contentType: false,
processData: false,
- success: function(data, text) {
+ success(data, text) {
$("#upgrade-progress").hide();
- if (data == 'OK') {
+ if (data === "OK") {
alert("Firmware image uploaded, board rebooting. This page will be refreshed in 5 seconds.");
doReload(5000);
} else {
@@ -272,14 +287,14 @@ function doUpgrade() {
},
// Custom XMLHttpRequest
- xhr: function() {
+ xhr() {
$("#upgrade-progress").show();
var myXhr = $.ajaxSettings.xhr();
if (myXhr.upload) {
// For handling the progress of the upload
- myXhr.upload.addEventListener('progress', function(e) {
+ myXhr.upload.addEventListener("progress", function(e) {
if (e.lengthComputable) {
- $('progress').attr({ value: e.loaded, max: e.total });
+ $("progress").attr({ value: e.loaded, max: e.total });
}
} , false);
}
@@ -296,71 +311,86 @@ function doUpdatePassword() {
var form = $("#formPassword");
if (validateForm(form)) {
var data = getData(form);
- websock.send(JSON.stringify({'config': data}));
+ websock.send(JSON.stringify({"config": data}));
}
return false;
}
function doReboot(ask) {
- ask = (typeof ask == 'undefined') ? true : ask;
+ var response;
+
+ ask = (typeof ask == "undefined") ? true : ask;
if (numChanged > 0) {
- var response = window.confirm("Some changes have not been saved yet, do you want to save them first?");
- if (response == true) return doUpdate();
+ response = window.confirm("Some changes have not been saved yet, do you want to save them first?");
+ if (response === true) {
+ return doUpdate();
+ }
}
if (ask) {
- var response = window.confirm("Are you sure you want to reboot the device?");
- if (response == false) return false;
+ response = window.confirm("Are you sure you want to reboot the device?");
+ if (response === false) {
+ return false;
+ }
}
- websock.send(JSON.stringify({'action': 'reboot'}));
+ websock.send(JSON.stringify({"action": "reboot"}));
doReload(5000);
return false;
}
function doReconnect(ask) {
+ var response;
- ask = (typeof ask == 'undefined') ? true : ask;
+ ask = (typeof ask == "undefined") ? true : ask;
if (numChanged > 0) {
- var response = window.confirm("Some changes have not been saved yet, do you want to save them first?");
- if (response == true) return doUpdate();
+ response = window.confirm("Some changes have not been saved yet, do you want to save them first?");
+ if (response === true) {
+ return doUpdate();
+ }
}
if (ask) {
- var response = window.confirm("Are you sure you want to disconnect from the current WIFI network?");
- if (response == false) return false;
+ response = window.confirm("Are you sure you want to disconnect from the current WIFI network?");
+ if (response === false) {
+ return false;
+ }
}
- websock.send(JSON.stringify({'action': 'reconnect'}));
+ websock.send(JSON.stringify({"action": "reconnect"}));
doReload(5000);
return false;
}
function doBackup() {
- document.getElementById('downloader').src = webhost + 'config';
+ document.getElementById("downloader").src = webhost + "config";
return false;
}
function onFileUpload(event) {
var inputFiles = this.files;
- if (inputFiles == undefined || inputFiles.length == 0) return false;
+ if (inputFiles === undefined || inputFiles.length === 0) {
+ return false;
+ }
var inputFile = inputFiles[0];
this.value = "";
var response = window.confirm("Previous settings will be overwritten. Are you sure you want to restore this settings?");
- if (response == false) return false;
+ if (response === false) {
+ return false;
+ }
var reader = new FileReader();
reader.onload = function(e) {
var data = getJson(e.target.result);
if (data) {
- websock.send(JSON.stringify({'action': 'restore', 'data': data}));
+ websock.send(JSON.stringify({"action": "restore", "data": data}));
} else {
alert(messages[4]);
}
@@ -372,7 +402,7 @@ function onFileUpload(event) {
}
function doRestore() {
- if (typeof window.FileReader !== 'function') {
+ if (typeof window.FileReader !== "function") {
alert("The file API isn't supported on this browser yet.");
} else {
$("#uploader").click();
@@ -382,7 +412,7 @@ function doRestore() {
function doToggle(element, value) {
var relayID = parseInt(element.attr("data"));
- websock.send(JSON.stringify({'action': 'relay', 'data': { 'id': relayID, 'status': value ? 1 : 0 }}));
+ websock.send(JSON.stringify({"action": "relay", "data": { "id": relayID, "status": value ? 1 : 0 }}));
return false;
}
@@ -393,14 +423,14 @@ function doToggle(element, value) {
function showPanel() {
$(".panel").hide();
$("#" + $(this).attr("data")).show();
- if ($("#layout").hasClass('active')) toggleMenu();
- $("input[type='checkbox']").iphoneStyle("calculateDimensions").iphoneStyle("refresh");
-};
+ if ($("#layout").hasClass("active")) toggleMenu();
+ $("input[type="checkbox"]").iphoneStyle("calculateDimensions").iphoneStyle("refresh");
+}
function toggleMenu() {
- $("#layout").toggleClass('active');
- $("#menu").toggleClass('active');
- $("#menuLink").toggleClass('active');
+ $("#layout").toggleClass("active");
+ $("#menu").toggleClass("active");
+ $("#menuLink").toggleClass("active");
}
// -----------------------------------------------------------------------------
@@ -410,7 +440,9 @@ function toggleMenu() {
function createRelayList(data, container, template) {
var current = $("#" + container + " > div").length;
- if (current > 0) return;
+ if (current > 0) {
+ return;
+ }
var template = $("#" + template + " .pure-g")[0];
for (var i=0; i div").length;
- if (current > 0) return;
+ if (current > 0) {
+ return;
+ }
var template = $("#" + template + " .pure-g")[0];
for (var i=0; i div").length;
- if (current > 0) return;
+ if (current > 0) {
+ return;
+ }
var template = $("#relayTemplate .pure-g")[0];
for (var i=0; i div").length;
- if (current > 0) return;
+ if (current > 0) {
+ return;
+ }
var template = $("#relayConfigTemplate").children();
for (var i=0; i < data.length; i++) {
var line = $(template).clone();
$("span.gpio", line).html(data[i].gpio);
$("span.id", line).html(i);
- $("select[name='relayBoot']", line).val(data[i].boot);
- $("select[name='relayPulse']", line).val(data[i].pulse);
- $("input[name='relayTime']", line).val(data[i].pulse_ms);
- $("input[name='mqttGroup']", line).val(data[i].group);
- $("select[name='mqttGroupInv']", line).val(data[i].group_inv);
+ $("select[name='"relayBoot"']", line).val(data[i].boot);
+ $("select[name='"relayPulse"']", line).val(data[i].pulse);
+ $("input[name='"relayTime"']", line).val(data[i].pulse_ms);
+ $("input[name='"mqttGroup"']", line).val(data[i].group);
+ $("select[name='"mqttGroupInv"']", line).val(data[i].group_inv);
line.appendTo("#relayConfig");
}
@@ -562,7 +600,9 @@ function initMagnitudes(data) {
// check if already initialized
var done = $("#magnitudes > div").length;
- if (done > 0) return;
+ if (done > 0) {
+ return;
+ }
// add templates
var template = $("#magnitudeTemplate").children();
@@ -578,7 +618,9 @@ function initMagnitudes(data) {
function getManifest(sensor_id) {
for (i in manifest) {
- if (manifest[i].sensor_id == sensor_id) return manifest[i];
+ if (manifest[i].sensor_id ===sensor_id) {
+ return manifest[i];
+ }
}
return null;
}
@@ -591,7 +633,9 @@ function initColorRGB() {
// check if already initialized
var done = $("#colors > div").length;
- if (done > 0) return;
+ if (done > 0) {
+ return;
+ }
// add template
var template = $("#colorRGBTemplate").children();
@@ -599,19 +643,19 @@ function initColorRGB() {
line.appendTo("#colors");
// init color wheel
- $('input[name="color"]').wheelColorPicker({
- sliders: 'wrgbp'
- }).on('sliderup', function() {
- var value = $(this).wheelColorPicker('getValue', 'css');
- websock.send(JSON.stringify({'action': 'color', 'data' : {'rgb': value}}));
+ $("input[name='color']").wheelColorPicker({
+ sliders: "wrgbp"
+ }).on("sliderup", function() {
+ var value = $(this).wheelColorPicker("getValue", "css");
+ websock.send(JSON.stringify({"action": "color", "data" : {"rgb": value}}));
});
// init bright slider
- $('#brightness').on("change", function() {
+ $("#brightness").on("change", function() {
var value = $(this).val();
var parent = $(this).parents(".pure-g");
$("span", parent).html(value);
- websock.send(JSON.stringify({'action': 'color', 'data' : {'brightness': value}}));
+ websock.send(JSON.stringify({"action": "color", "data" : {"brightness": value}}));
});
}
@@ -620,7 +664,9 @@ function initColorHSV() {
// check if already initialized
var done = $("#colors > div").length;
- if (done > 0) return;
+ if (done > 0) {
+ return;
+ }
// add template
var template = $("#colorHSVTemplate").children();
@@ -628,12 +674,12 @@ function initColorHSV() {
line.appendTo("#colors");
// init color wheel
- $('input[name="color"]').wheelColorPicker({
- sliders: 'whsvp'
- }).on('sliderup', function() {
- var color = $(this).wheelColorPicker('getColor');
+ $("input[name='color']").wheelColorPicker({
+ sliders: "whsvp"
+ }).on("sliderup", function() {
+ var color = $(this).wheelColorPicker("getColor");
var value = parseInt(color.h * 360) + "," + parseInt(color.s * 100) + "," + parseInt(color.v * 100);
- websock.send(JSON.stringify({'action': 'color', 'data' : {'hsv': value}}));
+ websock.send(JSON.stringify({"action": "color", "data" : {"hsv": value}}));
});
}
@@ -642,7 +688,9 @@ function initChannels(num) {
// check if already initialized
var done = $("#channels > div").length > 0;
- if (done) return;
+ if (done) {
+ return;
+ }
// does it have color channels?
var colors = $("#colors > div").length > 0;
@@ -667,7 +715,7 @@ function initChannels(num) {
var value = $(this).val();
var parent = $(this).parents(".pure-g");
$("span", parent).html(value);
- websock.send(JSON.stringify({'action': 'channel', 'data' : { 'id': id, 'value': value }}));
+ websock.send(JSON.stringify({"action": "channel", "data" : { "id": id, "value": value }}));
});
$("label", line).html("Channel " + (channel_id + 1));
@@ -694,9 +742,9 @@ function addRfbNode() {
$(this).attr("data-status", status ? 1 : 0);
status = !status;
});
- $(line).find(".button-rfb-learn").on('click', rfbLearn);
- $(line).find(".button-rfb-forget").on('click', rfbForget);
- $(line).find(".button-rfb-send").on('click', rfbSend);
+ $(line).find(".button-rfb-learn").on("click", rfbLearn);
+ $(line).find(".button-rfb-forget").on("click", rfbForget);
+ $(line).find(".button-rfb-send").on("click", rfbSend);
line.appendTo("#rfbNodes");
return line;
@@ -705,19 +753,19 @@ function addRfbNode() {
function rfbLearn() {
var parent = $(this).parents(".pure-g");
var input = $("input", parent);
- websock.send(JSON.stringify({'action': 'rfblearn', 'data' : {'id' : input.attr("data-id"), 'status': input.attr("data-status")}}));
+ websock.send(JSON.stringify({"action": "rfblearn", "data" : {"id" : input.attr("data-id"), "status": input.attr("data-status")}}));
}
function rfbForget() {
var parent = $(this).parents(".pure-g");
var input = $("input", parent);
- websock.send(JSON.stringify({'action': 'rfbforget', 'data' : {'id' : input.attr("data-id"), 'status': input.attr("data-status")}}));
+ websock.send(JSON.stringify({"action": "rfbforget", "data" : {"id" : input.attr("data-id"), "status": input.attr("data-status")}}));
}
function rfbSend() {
var parent = $(this).parents(".pure-g");
var input = $("input", parent);
- websock.send(JSON.stringify({'action': 'rfbsend', 'data' : {'id' : input.attr("data-id"), 'status': input.attr("data-status"), 'data': input.val()}}));
+ websock.send(JSON.stringify({"action": "rfbsend", "data" : {"id" : input.attr("data-id"), "status": input.attr("data-status"), "data": input.val()}}));
}
// -----------------------------------------------------------------------------
@@ -747,7 +795,7 @@ function processData(data) {
// Web mode
// ---------------------------------------------------------------------
- if (key == "webMode") {
+ if (key ==="webMode") {
password = data.webMode == 1;
$("#layout").toggle(data.webMode == 0);
$("#password").toggle(data.webMode == 1);
@@ -757,8 +805,8 @@ function processData(data) {
// Actions
// ---------------------------------------------------------------------
- if (key == "action") {
- if (data.action == "reload") doReload(1000);
+ if (key === "action") {
+ if (data.action === "reload") doReload(1000);
return;
}
@@ -766,16 +814,16 @@ function processData(data) {
// RFBridge
// ---------------------------------------------------------------------
- if (key == "rfbCount") {
+ if (key === "rfbCount") {
for (var i=0; i 0 && position == key.length - 7) {
+ if (position > 0 && position === key.length - 7) {
var module = key.slice(0,-7);
$(".module-" + module).show();
return;
}
// Pre-process
- if (key == "network") {
+ if (key === "network") {
data.network = data.network.toUpperCase();
}
- if (key == "mqttStatus") {
+ if (key === "mqttStatus") {
data.mqttStatus = data.mqttStatus ? "CONNECTED" : "NOT CONNECTED";
}
- if (key == "ntpStatus") {
+ if (key === "ntpStatus") {
data.ntpStatus = data.ntpStatus ? "SYNC'D" : "NOT SYNC'D";
}
- if (key == "uptime") {
+ if (key === "uptime") {
var uptime = parseInt(data[key]);
var seconds = uptime % 60; uptime = parseInt(uptime / 60);
var minutes = uptime % 60; uptime = parseInt(uptime / 60);
var hours = uptime % 24; uptime = parseInt(uptime / 24);
var days = uptime;
- data[key] = days + 'd ' + zeroPad(hours, 2) + 'h ' + zeroPad(minutes, 2) + 'm ' + zeroPad(seconds, 2) + 's';
+ data[key] = days + "d " + zeroPad(hours, 2) + "h " + zeroPad(minutes, 2) + "m " + zeroPad(seconds, 2) + "s";
}
// ---------------------------------------------------------------------
@@ -986,13 +1034,13 @@ function processData(data) {
// ---------------------------------------------------------------------
// Look for INPUTs
- var element = $("input[name=" + key + "]");
+ var element = $("input[name='" + key + "']");
if (element.length > 0) {
- if (element.attr('type') == 'checkbox') {
+ if (element.attr("type") === "checkbox") {
element
.prop("checked", data[key])
.iphoneStyle("refresh");
- } else if (element.attr('type') == 'radio') {
+ } else if (element.attr("type") === "radio") {
element.val([data[key]]);
} else {
var pre = element.attr("pre") || "";
@@ -1003,7 +1051,7 @@ function processData(data) {
}
// Look for SPANs
- var element = $("span[name=" + key + "]");
+ var element = $("span[name='" + key + "']");
if (element.length > 0) {
var pre = element.attr("pre") || "";
var post = element.attr("post") || "";
@@ -1012,7 +1060,7 @@ function processData(data) {
}
// Look for SELECTs
- var element = $("select[name=" + key + "]");
+ var element = $("select[name='" + key + "']");
if (element.length > 0) {
element.val(data[key]);
return;
@@ -1021,7 +1069,7 @@ function processData(data) {
});
// Auto generate an APIKey if none defined yet
- if ($("input[name='apiKey']").val() == "") {
+ if ($("input[name='apiKey']").val() === "") {
generateAPIKey();
}
@@ -1032,7 +1080,7 @@ function processData(data) {
function hasChanged() {
var newValue, originalValue;
- if ($(this).attr('type') == 'checkbox') {
+ if ($(this).attr("type") === "checkbox") {
newValue = $(this).prop("checked")
originalValue = $(this).attr("original") == "true";
} else {
@@ -1042,53 +1090,46 @@ function hasChanged() {
var hasChanged = $(this).attr("hasChanged") || 0;
var action = $(this).attr("action");
- if (typeof originalValue == 'undefined') return;
- if (action == 'none') return;
+ if (typeof originalValue === "undefined") {return;}
+ if (action === "none") {return;}
- if (newValue != originalValue) {
- if (hasChanged == 0) {
+ if (newValue !== originalValue) {
+ if (hasChanged === 0) {
++numChanged;
- if (action == "reconnect") ++numReconnect;
- if (action == "reboot") ++numReboot;
- if (action == "reload") ++numReload;
+ if (action === "reconnect") ++numReconnect;
+ if (action === "reboot") ++numReboot;
+ if (action === "reload") ++numReload;
$(this).attr("hasChanged", 1);
}
} else {
- if (hasChanged == 1) {
+ if (hasChanged === 1) {
--numChanged;
- if (action == "reconnect") --numReconnect;
- if (action == "reboot") --numReboot;
- if (action == "reload") --numReload;
+ if (action === "reconnect") --numReconnect;
+ if (action === "reboot") --numReboot;
+ if (action === "reload") --numReload;
$(this).attr("hasChanged", 0);
}
}
}
-function resetOriginals() {
- $("input,select").each(function() {
- $(this).attr("original", $(this).val());
- })
- numReboot = numReconnect = numReload = 0;
-}
-
// -----------------------------------------------------------------------------
// Init & connect
// -----------------------------------------------------------------------------
function connect(host) {
- if (typeof host === 'undefined') {
- host = window.location.href.replace('#', '');
+ if (typeof host === "undefined") {
+ host = window.location.href.replace("#", "");
} else {
- if (host.indexOf("http") != 0) {
- host = 'http://' + host + '/';
+ if (host.indexOf("http") !== 0) {
+ host = "http://" + host + "/";
}
}
- if (host.indexOf("http") != 0) return;
+ if (host.indexOf("http") !== 0) {return;}
webhost = host;
- wshost = host.replace('http', 'ws') + 'ws';
+ wshost = host.replace("http", "ws") + "ws";
if (websock) websock.close();
websock = new WebSocket(wshost);
@@ -1102,37 +1143,37 @@ $(function() {
initMessages();
- $("#menuLink").on('click', toggleMenu);
- $(".pure-menu-link").on('click', showPanel);
- $('progress').attr({ value: 0, max: 100 });
-
- $(".button-update").on('click', doUpdate);
- $(".button-update-password").on('click', doUpdatePassword);
- $(".button-reboot").on('click', doReboot);
- $(".button-reconnect").on('click', doReconnect);
- $(".button-settings-backup").on('click', doBackup);
- $(".button-settings-restore").on('click', doRestore);
- $('#uploader').on('change', onFileUpload);
- $(".button-upgrade").on('click', doUpgrade);
-
- $(".button-apikey").on('click', generateAPIKey);
- $(".button-upgrade-browse").on('click', function() {
+ $("#menuLink").on("click", toggleMenu);
+ $(".pure-menu-link").on("click", showPanel);
+ $("progress").attr({ value: 0, max: 100 });
+
+ $(".button-update").on("click", doUpdate);
+ $(".button-update-password").on("click", doUpdatePassword);
+ $(".button-reboot").on("click", doReboot);
+ $(".button-reconnect").on("click", doReconnect);
+ $(".button-settings-backup").on("click", doBackup);
+ $(".button-settings-restore").on("click", doRestore);
+ $("#uploader").on("change", onFileUpload);
+ $(".button-upgrade").on("click", doUpgrade);
+
+ $(".button-apikey").on("click", generateAPIKey);
+ $(".button-upgrade-browse").on("click", function() {
$("input[name='upgrade']")[0].click();
return false;
});
$("input[name='upgrade']").change(function (){
var fileName = $(this).val();
- $("input[name='filename']").val(fileName.replace(/^.*[\\\/]/, ''));
+ $("input[name='filename']").val(fileName.replace(/^.*[\\\/]/, ""));
});
- $(".button-add-network").on('click', function() {
+ $(".button-add-network").on("click", function() {
$(".more", addNetwork()).toggle();
});
- $(".button-add-schedule").on('click', function() {
+ $(".button-add-schedule").on("click", function() {
$("div.more", addSchedule()).toggle();
});
- $(document).on('change', 'input', hasChanged);
- $(document).on('change', 'select', hasChanged);
+ $(document).on("change", "input", hasChanged);
+ $(document).on("change", "select", hasChanged);
connect();
diff --git a/code/ota.py b/code/ota.py
index ed862f0d..086336af 100644
--- a/code/ota.py
+++ b/code/ota.py
@@ -19,7 +19,7 @@ from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf
try:
# noinspection PyUnresolvedReferences
- input = raw_input # Python2
+ input = raw_input # Python2 *!! redefining build-in input.
except NameError:
pass # Python3
@@ -56,7 +56,7 @@ def on_service_state_change(zeroconf, service_type, name, state_change):
devices.append(device)
-def list():
+def list_devices():
"""
Shows the list of discovered devices
"""
@@ -206,7 +206,7 @@ if __name__ == '__main__':
devices = sorted(devices, key=lambda device: device.get(field, ''))
# List devices
- list()
+ list_devices()
# Flash device
if args.flash > 0: