lots of little node edits to clean up jsHint "errors"

This commit is contained in:
dceejay 2015-03-26 18:55:03 +00:00
parent 8eca22bdc3
commit d511ee69fb
18 changed files with 478 additions and 328 deletions

View File

@ -49,7 +49,7 @@ module.exports = function (RED) {
setPinMode = function (pin, direction, callback) {
bonescript.pinMode(pin, direction, undefined, undefined, undefined, callback);
}
} catch (e) {
} catch (er) {
throw "Info : Ignoring Beaglebone specific node.";
}
}
@ -119,10 +119,11 @@ module.exports = function (RED) {
this.topic = n.topic; // the topic is not currently used
this.pin = n.pin; // The Beaglebone Black pin identifying string
this._pin = adjustName(this.pin); // Adjusted for Octal if necessary
if (n.activeLow) // Set the 'active' state 0 or 1 as appropriate
if (n.activeLow) { // Set the 'active' state 0 or 1 as appropriate
this.activeState = 0;
else
} else {
this.activeState = 1;
}
this.updateInterval = n.updateInterval*1000; // How often to send totalActiveTime messages
this.debounce = n.debounce; // Enable switch contact debouncing algorithm
if (n.outputOn === "rising") {
@ -229,7 +230,7 @@ module.exports = function (RED) {
// payload, if possible. Otherwise clear the totalActiveTime (so we start counting
// from zero again)
var inputCallback = function (ipMsg) {
if (String(ipMsg.topic).search(/load/i) < 0 || isFinite(ipMsg.payload) == false) {
if (String(ipMsg.topic).search(/load/i) < 0 || isFinite(ipMsg.payload) === false) {
node.totalActiveTime = 0;
} else {
node.totalActiveTime = Number(ipMsg.payload);
@ -327,7 +328,7 @@ module.exports = function (RED) {
// insensitive) and the payload is a valid number, set the count to that
// number, otherwise set it to zero
var inputCallback = function (msg) {
if (String(msg.topic).search(/load/i) < 0 || isFinite(msg.payload) == false) {
if (String(msg.topic).search(/load/i) < 0 || isFinite(msg.payload) === false) {
node.pulseCount = 0;
} else {
node.pulseCount = Number(msg.payload);

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-beaglebone",
"version" : "0.0.6",
"version" : "0.0.7",
"description" : "A set of Node-RED nodes to interface to the GPIO pins of a Beaglebone Black board",
"dependencies" : {
},

View File

@ -147,7 +147,8 @@ module.exports = function(RED) {
this.level = n.level || 0;
this.out = n.out || "out";
var node = this;
(node.out === "pwm") ? (node.op = "pwm") : (node.op = "write");
if (node.out === "pwm") { node.op = "pwm"; }
else { node.op = "write"; }
if (node.pin !== undefined) {
exec(gpioCommand+" mode "+node.pin+" "+node.out, function(err,stdout,stderr) {

View File

@ -101,7 +101,7 @@ module.exports = function(RED) {
node.error("BlinkStick with serial number " + node.serial + " not found");
} else {
node.status({fill:"green",shape:"dot",text:"connected"});
if (callback) callback();
if (callback) { callback(); }
}
});
} else {
@ -112,7 +112,7 @@ module.exports = function(RED) {
node.error("No BlinkStick found");
} else {
node.status({fill:"green",shape:"dot",text:"connected"});
if (callback) callback();
if (callback) { callback(); }
}
}
};
@ -197,26 +197,26 @@ module.exports = function(RED) {
if (Array.isArray(msg.payload)) {
if (Object.size(node.led) !== 0) {
node.led.setMode(2); // put it into ws2812B LED mode
var data = [];
var dat = [];
for (var i = 0; i < msg.payload.length; i++) {
if (typeof msg.payload[i] === "string") { // if string then assume must be colour names
var params = node.led.interpretParameters(msg.payload[i]); // lookup colour code from name
if (params) {
data.push(params.green);
data.push(params.red);
data.push(params.blue);
dat.push(params.green);
dat.push(params.red);
dat.push(params.blue);
}
else { node.warn("invalid colour: "+msg.payload[i]); }
}
else { // otherwise lets use numbers 0-255
data.push(msg.payload[i+1]);
data.push(msg.payload[i]);
data.push(msg.payload[i+2]);
dat.push(msg.payload[i+1]);
dat.push(msg.payload[i]);
dat.push(msg.payload[i+2]);
i += 2;
}
}
if ((data.length % 3) === 0) { // by now length must be a multiple of 3
node.led.setColors(0, data, function(err) {
if ((dat.length % 3) === 0) { // by now length must be a multiple of 3
node.led.setColors(0, dat, function(err) {
if (err) { node.log(err); }
});
}

View File

@ -15,7 +15,7 @@
**/
module.exports = function(RED) {
//"use strict";
"use strict";
var HID = require('node-hid');
var device;
var node;

View File

@ -144,9 +144,9 @@ module.exports = function(RED) {
}
};
this.validateAndWrite = function(message) {
for (var key in message.payload) {
if (message.payload.hasOwnProperty(key)) {
// Ensure our valid keys contain valid values
switch(key) {
case "runmode" :
@ -165,7 +165,7 @@ module.exports = function(RED) {
//}
//if (!('enabled' in message.payload[key]) && !('time' in message.payload[key])) {
//hminnode.log("Warning: Unsupported 'holiday' value passed!");
// return;
//eturn;
//}
//var time = message.payload[key].time;
//// Ensure hminnode time is a date
@ -206,10 +206,14 @@ module.exports = function(RED) {
// Set sane temp and time ranges and sanitise to float/int
var target = parseFloat(message.payload[key].target);
var hold = parseInt(message.payload[key].hold);
(target > 30.0) ? message.payload[key].target = 30.0 : message.payload[key].target = target;
(hold > 1440) ? message.payload[key].hold = 1440 : message.payload[key].hold = hold;
(target <= 10.0) ? message.payload[key].target = 10.0 : message.payload[key].target = target;
(hold <= 0) ? message.payload[key].hold = 0 : message.payload[key].hold = hold;
if (target > 30.0) { message.payload[key].target = 30.0; }
else { message.payload[key].target = target; }
if (hold > 1440) { message.payload[key].hold = 1440; }
else { message.payload[key].hold = hold; }
if (target <= 10.0) { message.payload[key].target = 10.0; }
else { message.payload[key].target = target; }
if (hold <= 0) { message.payload[key].hold = 0; }
else { message.payload[key].hold = hold; }
// Ensure hminnode runmode == heating first
if (hminnode.currentStatus.run_mode === "frost_protection") {
@ -226,13 +230,14 @@ module.exports = function(RED) {
default :
break;
}
}
// Valid set of key messages, construct DCB and write
var dcb = message.payload;
if (DEBUG) {
hminnode.log("Injecting " + JSON.stringify(dcb));
}
hminnode.write(dcb);
}
}
};
this.on("input", function(message) {

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-contrib-heatmiser",
"version" : "0.0.1",
"version" : "0.0.2",
"description" : "A Node-RED node to control and poll a HeatMiser thermostat.",
"dependencies" : {
"heatmiser" : "2.0.0"

View File

@ -50,7 +50,7 @@ function HueNodeDiscovery(n) {
//start with detecting the IP address of the Hue gateway in the local network:
hue.locateBridges(function(err, result) {
var msg = {};
if (err) throw err;
if (err) { throw err; }
//check for found bridges
if(result[0]!=null) {
//save the IP address of the 1st bridge found
@ -61,17 +61,16 @@ function HueNodeDiscovery(n) {
var api = new HueApi(this.gw_ipaddress, node.username);
api.lights(function(err, lights) {
var msg2 = {};
if (err) throw err;
if (err) { throw err; }
var lights_discovered = JSON.stringify(lights, null, 2);
msg2.topic = "Lights";
msg2.payload = lights_discovered;
node.send([msg, msg2]);
});
}
else {
//bridge not found:
var msg = {};
msg = {};
msg.payload = "Bridge not found!";
node.send(msg);
}

View File

@ -91,16 +91,18 @@ function setLights(node, myMsg) {
}
else {
//set lamp according to node settings
if(node.lamp_status=="ON")
if(node.lamp_status=="ON") {
api.setLightState(node.lamp_id, state.on().rgb(hexToRgb(node.color).r,hexToRgb(node.color).g,hexToRgb(node.color).b).brightness(node.brightness)).then(displayResult).fail(displayError).done();
else
} else {
api.setLightState(node.lamp_id, state.off()).then(displayResult).fail(displayError).done();
}
}
if(lamp!=-1)
if(lamp!=-1) {
msg2.payload = 'Light with ID: '+lamp+ ' was set to '+myMsg.payload;
else
} else {
msg2.payload = 'Light with ID: '+node.lamp_id+ ' was set to '+node.lamp_status;
}
node.send(msg2);
}
@ -138,7 +140,7 @@ function HueNode(n) {
hue.locateBridges(function(err, result) {
if (err) throw err;
if (err) { throw err; }
//check for found bridges
if(result[0]!=null) {
//save the IP address of the 1st bridge found

View File

@ -14,7 +14,8 @@
* the License.
*/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
//The Server Definition - this opens (and closes) the connection
function EmoncmsServerNode(n) {
RED.nodes.createNode(this,n);
@ -37,8 +38,9 @@ function Emoncms(n) {
this.nodegroup = n.nodegroup || "";
var node = this;
if (this.baseurl.substring(0,5) === "https") { var http = require("https"); }
else { var http = require("http"); }
var http;
if (this.baseurl.substring(0,5) === "https") { http = require("https"); }
else { http = require("http"); }
this.on("input", function(msg) {
this.url = this.baseurl + '/input/post.json?';
if(msg.payload.indexOf(':') > -1){
@ -48,7 +50,7 @@ function Emoncms(n) {
}
this.url += '&apikey='+this.apikey;
var nodegroup = this.nodegroup || msg.nodegroup;
if(nodegroup != ""){
if(nodegroup !== ""){
this.url += '&node=' + nodegroup;
}
if(typeof msg.time !== 'undefined'){
@ -77,5 +79,5 @@ function Emoncms(n) {
});
});
}
RED.nodes.registerType("emoncms",Emoncms);
}

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-emoncms",
"version" : "0.0.2",
"version" : "0.0.3",
"description" : "A Node-RED node to send energy data to emoncms.org.",
"dependencies" : {
},

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-snmp",
"version" : "0.0.1",
"version" : "0.0.2",
"description" : "A Node-RED node that looks for SNMP oids.",
"dependencies" : {
"net-snmp" : "1.1.13"

View File

@ -15,6 +15,7 @@
**/
module.exports = function(RED) {
"use strict";
var snmp = require ("net-snmp");
function SnmpNode(n) {
@ -67,9 +68,9 @@ module.exports = function(RED) {
var maxRepetitions = 20;
function sortInt (a, b) {
if (a > b) return 1;
else if (b > a) return -1;
else return 0;
if (a > b) { return 1; }
else if (b > a) { return -1; }
else { return 0; }
}
function responseCb (error, table) {
@ -77,11 +78,19 @@ module.exports = function(RED) {
console.error (error.toString ());
} else {
var indexes = [];
for (index in table) { indexes.push (parseInt (index)); }
for (var index in table) {
if (table.hasOwnProperty(index)) {
indexes.push (parseInt (index));
}
}
indexes.sort (sortInt);
for (var i = 0; i < indexes.length; i++) {
var columns = [];
for (column in table[indexes[i]]) { columns.push(parseInt (column)); }
for (var column in table[indexes[i]]) {
if (table[indexes[i]].hasOwnProperty(column)) {
columns.push(parseInt (column));
}
}
columns.sort(sortInt);
console.log ("row index = " + indexes[i]);
for (var j = 0; j < columns.length; j++) {

View File

@ -36,13 +36,13 @@ module.exports = function(RED) {
node.send(msg);
}
else {
var lat = msg.location.lat;
var lon = msg.location.lon;
var len = parseInt(msg.location.precision || msg.location.payload || 9);
if (len < 1) { len = 1; }
if (len > 9) { len = 9; }
if (lat && lon) {
msg.location.geohash = geohash.encode(lat, lon, len);
var lt = msg.location.lat;
var ln = msg.location.lon;
var le = parseInt(msg.location.precision || msg.location.payload || 9);
if (le < 1) { le = 1; }
if (le > 9) { le = 9; }
if (lt && ln) {
msg.location.geohash = geohash.encode(lt, ln, le);
node.send(msg);
}
}
@ -51,9 +51,9 @@ module.exports = function(RED) {
// try to decode it...
var regexp = new RegExp('^[a-z0-9]{1,9}$'); // can only contain a-z or 0-9 and length 1-9
if (regexp.test(msg.payload)) {
var pos = geohash.decode(msg.payload);
msg.payload = { lat:round(pos.latitude,5), lon:round(pos.longitude,5) };
msg.payload.error = { lat:round(pos.error.latitude,5), lon:round(pos.error.longitude,5) };
var po = geohash.decode(msg.payload);
msg.payload = { lat:round(po.latitude,5), lon:round(po.longitude,5) };
msg.payload.error = { lat:round(po.error.latitude,5), lon:round(po.error.longitude,5) };
node.send(msg);
}
else if (msg.payload.indexOf(",") !== -1) {

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-geohash",
"version" : "0.0.2",
"version" : "0.0.3",
"description" : "A Node-RED node to encode and decode lat,lon pairs to a geohash.",
"dependencies" : {
"ngeohash" : "0.6.0"

View File

@ -461,6 +461,7 @@ module.exports = function(RED) {
RED.httpAdmin.get('/pushbullet/:id/devices', function(req, res) {
var config = RED.nodes.getNode(req.params.id);
var cred = RED.nodes.getCredentials(req.params.id);
var pb;
if(config && config.pusher) {
config.pusher.devices(function(err, chans) {
@ -472,7 +473,7 @@ module.exports = function(RED) {
});
}
else if(cred && cred.apikey) {
var pb = new PushBullet(cred.apikey);
pb = new PushBullet(cred.apikey);
pb.devices(function(err, chans) {
if(err) {
res.send("[]");
@ -482,7 +483,7 @@ module.exports = function(RED) {
});
}
else if(req.query.apikey) {
var pb = new PushBullet(req.query.apikey);
pb = new PushBullet(req.query.apikey);
pb.devices(function(err, chans) {
if(err) {
res.send("[]");

View File

@ -0,0 +1,131 @@
/**
* Copyright 2015 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var should = require("should");
var helper = require('../../../test/helper.js');
var testNode = require('../../../function/rbe/rbe.js');
describe('rbe node', function() {
"use strict";
beforeEach(function(done) {
helper.startServer(done);
});
afterEach(function(done) {
helper.unload().then(function() {
helper.stopServer(done);
});
});
it("should be loaded with correct defaults", function(done) {
var flow = [{"id":"n1", "type":"rbe", "name":"rbe1", "wires":[[]]}];
helper.load(testNode, flow, function() {
var n1 = helper.getNode("n1");
n1.should.have.property("name", "rbe1");
n1.should.have.property("func", "rbe");
n1.should.have.property("gap", 0);
done();
});
});
it('should only send output if payload changes', function(done) {
var flow = [{"id":"n1", "type":"rbe", func:"rbe", gap:0, wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(testNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var c = 0;
n2.on("input", function(msg) {
if (c === 0) {
msg.should.have.a.property("payload", "a");
c+=1;
}
else {
msg.should.have.a.property("payload", "b");
done();
}
});
n1.emit("input", {payload:"a"});
n1.emit("input", {payload:"a"});
n1.emit("input", {payload:"a"});
n1.emit("input", {payload:"a"});
n1.emit("input", {payload:"a"});
n1.emit("input", {payload:"b"});
n1.emit("input", {payload:"b"});
});
});
it('should only send output if more than x away from original value', function(done) {
var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:10, wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(testNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var c = 0;
n2.on("input", function(msg) {
if (c === 0) {
msg.should.have.a.property("payload", 0);
}
else if (c === 1) {
msg.should.have.a.property("payload", 20);
}
else {
msg.should.have.a.property("payload", "5 deg");
done();
}
c += 1;
});
n1.emit("input", {payload:0});
n1.emit("input", {payload:2});
n1.emit("input", {payload:4});
n1.emit("input", {payload:"6 deg"});
n1.emit("input", {payload:8});
n1.emit("input", {payload:20});
n1.emit("input", {payload:15});
n1.emit("input", {payload:"5 deg"});
});
});
it('should warn if no number found in gap mode', function(done) {
var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:10, wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(testNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var c = 0;
n2.on("input", function(msg) {
c += 1;
});
setTimeout( function() {
c.should.equal(0);
helper.log().called.should.be.true;
var logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "rbe";
});
logEvents.should.have.length(1);
var msg = logEvents[0][0];
msg.should.have.property('level', helper.log().WARN);
msg.should.have.property('id', 'n1');
msg.should.have.property('type', 'rbe');
msg.should.have.property('msg', 'no number found in payload');
done();
},50);
n1.emit("input", {payload:"banana"});
});
});
});

View File

@ -605,6 +605,7 @@ describe('pushbullet node', function() {
done();
});
});
});
describe('tickle', function() {
it('note', function(done) {
@ -777,7 +778,5 @@ describe('pushbullet node', function() {
}, 100);
});
});
});
});
});