mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
lots of little node edits to clean up jsHint "errors"
This commit is contained in:
parent
8eca22bdc3
commit
d511ee69fb
@ -49,7 +49,7 @@ module.exports = function (RED) {
|
|||||||
setPinMode = function (pin, direction, callback) {
|
setPinMode = function (pin, direction, callback) {
|
||||||
bonescript.pinMode(pin, direction, undefined, undefined, undefined, callback);
|
bonescript.pinMode(pin, direction, undefined, undefined, undefined, callback);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (er) {
|
||||||
throw "Info : Ignoring Beaglebone specific node.";
|
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.topic = n.topic; // the topic is not currently used
|
||||||
this.pin = n.pin; // The Beaglebone Black pin identifying string
|
this.pin = n.pin; // The Beaglebone Black pin identifying string
|
||||||
this._pin = adjustName(this.pin); // Adjusted for Octal if necessary
|
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;
|
this.activeState = 0;
|
||||||
else
|
} else {
|
||||||
this.activeState = 1;
|
this.activeState = 1;
|
||||||
|
}
|
||||||
this.updateInterval = n.updateInterval*1000; // How often to send totalActiveTime messages
|
this.updateInterval = n.updateInterval*1000; // How often to send totalActiveTime messages
|
||||||
this.debounce = n.debounce; // Enable switch contact debouncing algorithm
|
this.debounce = n.debounce; // Enable switch contact debouncing algorithm
|
||||||
if (n.outputOn === "rising") {
|
if (n.outputOn === "rising") {
|
||||||
@ -229,7 +230,7 @@ module.exports = function (RED) {
|
|||||||
// payload, if possible. Otherwise clear the totalActiveTime (so we start counting
|
// payload, if possible. Otherwise clear the totalActiveTime (so we start counting
|
||||||
// from zero again)
|
// from zero again)
|
||||||
var inputCallback = function (ipMsg) {
|
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;
|
node.totalActiveTime = 0;
|
||||||
} else {
|
} else {
|
||||||
node.totalActiveTime = Number(ipMsg.payload);
|
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
|
// insensitive) and the payload is a valid number, set the count to that
|
||||||
// number, otherwise set it to zero
|
// number, otherwise set it to zero
|
||||||
var inputCallback = function (msg) {
|
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;
|
node.pulseCount = 0;
|
||||||
} else {
|
} else {
|
||||||
node.pulseCount = Number(msg.payload);
|
node.pulseCount = Number(msg.payload);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-beaglebone",
|
"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",
|
"description" : "A set of Node-RED nodes to interface to the GPIO pins of a Beaglebone Black board",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
},
|
},
|
||||||
|
@ -147,7 +147,8 @@ module.exports = function(RED) {
|
|||||||
this.level = n.level || 0;
|
this.level = n.level || 0;
|
||||||
this.out = n.out || "out";
|
this.out = n.out || "out";
|
||||||
var node = this;
|
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) {
|
if (node.pin !== undefined) {
|
||||||
exec(gpioCommand+" mode "+node.pin+" "+node.out, function(err,stdout,stderr) {
|
exec(gpioCommand+" mode "+node.pin+" "+node.out, function(err,stdout,stderr) {
|
||||||
|
@ -101,7 +101,7 @@ module.exports = function(RED) {
|
|||||||
node.error("BlinkStick with serial number " + node.serial + " not found");
|
node.error("BlinkStick with serial number " + node.serial + " not found");
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:"green",shape:"dot",text:"connected"});
|
node.status({fill:"green",shape:"dot",text:"connected"});
|
||||||
if (callback) callback();
|
if (callback) { callback(); }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -112,7 +112,7 @@ module.exports = function(RED) {
|
|||||||
node.error("No BlinkStick found");
|
node.error("No BlinkStick found");
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:"green",shape:"dot",text:"connected"});
|
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 (Array.isArray(msg.payload)) {
|
||||||
if (Object.size(node.led) !== 0) {
|
if (Object.size(node.led) !== 0) {
|
||||||
node.led.setMode(2); // put it into ws2812B LED mode
|
node.led.setMode(2); // put it into ws2812B LED mode
|
||||||
var data = [];
|
var dat = [];
|
||||||
for (var i = 0; i < msg.payload.length; i++) {
|
for (var i = 0; i < msg.payload.length; i++) {
|
||||||
if (typeof msg.payload[i] === "string") { // if string then assume must be colour names
|
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
|
var params = node.led.interpretParameters(msg.payload[i]); // lookup colour code from name
|
||||||
if (params) {
|
if (params) {
|
||||||
data.push(params.green);
|
dat.push(params.green);
|
||||||
data.push(params.red);
|
dat.push(params.red);
|
||||||
data.push(params.blue);
|
dat.push(params.blue);
|
||||||
}
|
}
|
||||||
else { node.warn("invalid colour: "+msg.payload[i]); }
|
else { node.warn("invalid colour: "+msg.payload[i]); }
|
||||||
}
|
}
|
||||||
else { // otherwise lets use numbers 0-255
|
else { // otherwise lets use numbers 0-255
|
||||||
data.push(msg.payload[i+1]);
|
dat.push(msg.payload[i+1]);
|
||||||
data.push(msg.payload[i]);
|
dat.push(msg.payload[i]);
|
||||||
data.push(msg.payload[i+2]);
|
dat.push(msg.payload[i+2]);
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((data.length % 3) === 0) { // by now length must be a multiple of 3
|
if ((dat.length % 3) === 0) { // by now length must be a multiple of 3
|
||||||
node.led.setColors(0, data, function(err) {
|
node.led.setColors(0, dat, function(err) {
|
||||||
if (err) { node.log(err); }
|
if (err) { node.log(err); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
//"use strict";
|
"use strict";
|
||||||
var HID = require('node-hid');
|
var HID = require('node-hid');
|
||||||
var device;
|
var device;
|
||||||
var node;
|
var node;
|
||||||
|
@ -144,9 +144,9 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.validateAndWrite = function(message) {
|
this.validateAndWrite = function(message) {
|
||||||
for (var key in message.payload) {
|
for (var key in message.payload) {
|
||||||
|
if (message.payload.hasOwnProperty(key)) {
|
||||||
// Ensure our valid keys contain valid values
|
// Ensure our valid keys contain valid values
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case "runmode" :
|
case "runmode" :
|
||||||
@ -159,40 +159,40 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// case "holiday" :
|
//case "holiday" :
|
||||||
// if (DEBUG) {
|
//if (DEBUG) {
|
||||||
// hminnode.log("Hit the holiday case");
|
//hminnode.log("Hit the holiday case");
|
||||||
// }
|
//}
|
||||||
// if (!('enabled' in message.payload[key]) && !('time' in message.payload[key])) {
|
//if (!('enabled' in message.payload[key]) && !('time' in message.payload[key])) {
|
||||||
// hminnode.log("Warning: Unsupported 'holiday' value passed!");
|
//hminnode.log("Warning: Unsupported 'holiday' value passed!");
|
||||||
// return;
|
//eturn;
|
||||||
// }
|
//}
|
||||||
// var time = message.payload[key].time;
|
//var time = message.payload[key].time;
|
||||||
// // Ensure hminnode time is a date
|
//// Ensure hminnode time is a date
|
||||||
// if (typeof(time) == "string") {
|
//if (typeof(time) == "string") {
|
||||||
// hminnode.log("Typeof time was " +typeof(message.payload[key].time));
|
//hminnode.log("Typeof time was " +typeof(message.payload[key].time));
|
||||||
// // message.payload[key].time = new Date(message.payload[key].time);
|
//// message.payload[key].time = new Date(message.payload[key].time);
|
||||||
// message.payload[key].time = new Date(2014, 02, 15, 12, 0, 0);
|
//message.payload[key].time = new Date(2014, 02, 15, 12, 0, 0);
|
||||||
// hminnode.log("Typeof time is now " +typeof(message.payload[key].time));
|
//hminnode.log("Typeof time is now " +typeof(message.payload[key].time));
|
||||||
// }
|
//}
|
||||||
// // Also add in away mode (for hot water) if we're on hols
|
//// Also add in away mode (for hot water) if we're on hols
|
||||||
// if (message.payload[key].time) {
|
//if (message.payload[key].time) {
|
||||||
// message.payload.away_mode = 1;
|
//message.payload.away_mode = 1;
|
||||||
// }
|
//}
|
||||||
// else {
|
//else {
|
||||||
// message.payload.away_mode = 0;
|
//message.payload.away_mode = 0;
|
||||||
// }
|
//}
|
||||||
// break;
|
//break;
|
||||||
|
|
||||||
// case "hotwater" :
|
//case "hotwater" :
|
||||||
// if (DEBUG) {
|
//if (DEBUG) {
|
||||||
// hminnode.log("Hit the hotwater case");
|
//hminnode.log("Hit the hotwater case");
|
||||||
// }
|
//}
|
||||||
// if (message.payload[key] !== "on" && message.payload[key] !== "boost" && message.payload[key] !== "off") {
|
//if (message.payload[key] !== "on" && message.payload[key] !== "boost" && message.payload[key] !== "off") {
|
||||||
// hminnode.log("Warning: Unsupported 'hotwater' value passed!");
|
//hminnode.log("Warning: Unsupported 'hotwater' value passed!");
|
||||||
// return;
|
//return;
|
||||||
// }
|
//}
|
||||||
// break;
|
//break;
|
||||||
|
|
||||||
case "heating" :
|
case "heating" :
|
||||||
// Ensure heating stays last! It's got a multi write scenario
|
// Ensure heating stays last! It's got a multi write scenario
|
||||||
@ -206,10 +206,14 @@ module.exports = function(RED) {
|
|||||||
// Set sane temp and time ranges and sanitise to float/int
|
// Set sane temp and time ranges and sanitise to float/int
|
||||||
var target = parseFloat(message.payload[key].target);
|
var target = parseFloat(message.payload[key].target);
|
||||||
var hold = parseInt(message.payload[key].hold);
|
var hold = parseInt(message.payload[key].hold);
|
||||||
(target > 30.0) ? message.payload[key].target = 30.0 : message.payload[key].target = target;
|
if (target > 30.0) { message.payload[key].target = 30.0; }
|
||||||
(hold > 1440) ? message.payload[key].hold = 1440 : message.payload[key].hold = hold;
|
else { message.payload[key].target = target; }
|
||||||
(target <= 10.0) ? message.payload[key].target = 10.0 : message.payload[key].target = target;
|
if (hold > 1440) { message.payload[key].hold = 1440; }
|
||||||
(hold <= 0) ? message.payload[key].hold = 0 : message.payload[key].hold = hold;
|
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
|
// Ensure hminnode runmode == heating first
|
||||||
if (hminnode.currentStatus.run_mode === "frost_protection") {
|
if (hminnode.currentStatus.run_mode === "frost_protection") {
|
||||||
@ -226,13 +230,14 @@ module.exports = function(RED) {
|
|||||||
default :
|
default :
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Valid set of key messages, construct DCB and write
|
// Valid set of key messages, construct DCB and write
|
||||||
var dcb = message.payload;
|
var dcb = message.payload;
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
hminnode.log("Injecting " + JSON.stringify(dcb));
|
hminnode.log("Injecting " + JSON.stringify(dcb));
|
||||||
}
|
}
|
||||||
hminnode.write(dcb);
|
hminnode.write(dcb);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.on("input", function(message) {
|
this.on("input", function(message) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-contrib-heatmiser",
|
"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.",
|
"description" : "A Node-RED node to control and poll a HeatMiser thermostat.",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"heatmiser" : "2.0.0"
|
"heatmiser" : "2.0.0"
|
||||||
|
@ -50,7 +50,7 @@ function HueNodeDiscovery(n) {
|
|||||||
//start with detecting the IP address of the Hue gateway in the local network:
|
//start with detecting the IP address of the Hue gateway in the local network:
|
||||||
hue.locateBridges(function(err, result) {
|
hue.locateBridges(function(err, result) {
|
||||||
var msg = {};
|
var msg = {};
|
||||||
if (err) throw err;
|
if (err) { throw err; }
|
||||||
//check for found bridges
|
//check for found bridges
|
||||||
if(result[0]!=null) {
|
if(result[0]!=null) {
|
||||||
//save the IP address of the 1st bridge found
|
//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);
|
var api = new HueApi(this.gw_ipaddress, node.username);
|
||||||
api.lights(function(err, lights) {
|
api.lights(function(err, lights) {
|
||||||
var msg2 = {};
|
var msg2 = {};
|
||||||
if (err) throw err;
|
if (err) { throw err; }
|
||||||
var lights_discovered = JSON.stringify(lights, null, 2);
|
var lights_discovered = JSON.stringify(lights, null, 2);
|
||||||
msg2.topic = "Lights";
|
msg2.topic = "Lights";
|
||||||
msg2.payload = lights_discovered;
|
msg2.payload = lights_discovered;
|
||||||
node.send([msg, msg2]);
|
node.send([msg, msg2]);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//bridge not found:
|
//bridge not found:
|
||||||
var msg = {};
|
msg = {};
|
||||||
msg.payload = "Bridge not found!";
|
msg.payload = "Bridge not found!";
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
|
@ -91,16 +91,18 @@ function setLights(node, myMsg) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//set lamp according to node settings
|
//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();
|
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();
|
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;
|
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;
|
msg2.payload = 'Light with ID: '+node.lamp_id+ ' was set to '+node.lamp_status;
|
||||||
|
}
|
||||||
node.send(msg2);
|
node.send(msg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +140,7 @@ function HueNode(n) {
|
|||||||
hue.locateBridges(function(err, result) {
|
hue.locateBridges(function(err, result) {
|
||||||
|
|
||||||
|
|
||||||
if (err) throw err;
|
if (err) { throw err; }
|
||||||
//check for found bridges
|
//check for found bridges
|
||||||
if(result[0]!=null) {
|
if(result[0]!=null) {
|
||||||
//save the IP address of the 1st bridge found
|
//save the IP address of the 1st bridge found
|
||||||
|
@ -14,20 +14,21 @@
|
|||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
module.exports = function(RED) {
|
||||||
//The Server Definition - this opens (and closes) the connection
|
"use strict";
|
||||||
function EmoncmsServerNode(n) {
|
//The Server Definition - this opens (and closes) the connection
|
||||||
|
function EmoncmsServerNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.server = n.server;
|
this.server = n.server;
|
||||||
this.name = n.name;
|
this.name = n.name;
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("emoncms-server",EmoncmsServerNode,{
|
RED.nodes.registerType("emoncms-server",EmoncmsServerNode,{
|
||||||
credentials: {
|
credentials: {
|
||||||
apikey: {type:"text"}
|
apikey: {type:"text"}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function Emoncms(n) {
|
function Emoncms(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.emonServer = n.emonServer;
|
this.emonServer = n.emonServer;
|
||||||
var sc = RED.nodes.getNode(this.emonServer);
|
var sc = RED.nodes.getNode(this.emonServer);
|
||||||
@ -37,8 +38,9 @@ function Emoncms(n) {
|
|||||||
|
|
||||||
this.nodegroup = n.nodegroup || "";
|
this.nodegroup = n.nodegroup || "";
|
||||||
var node = this;
|
var node = this;
|
||||||
if (this.baseurl.substring(0,5) === "https") { var http = require("https"); }
|
var http;
|
||||||
else { var http = require("http"); }
|
if (this.baseurl.substring(0,5) === "https") { http = require("https"); }
|
||||||
|
else { http = require("http"); }
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
this.url = this.baseurl + '/input/post.json?';
|
this.url = this.baseurl + '/input/post.json?';
|
||||||
if(msg.payload.indexOf(':') > -1){
|
if(msg.payload.indexOf(':') > -1){
|
||||||
@ -48,7 +50,7 @@ function Emoncms(n) {
|
|||||||
}
|
}
|
||||||
this.url += '&apikey='+this.apikey;
|
this.url += '&apikey='+this.apikey;
|
||||||
var nodegroup = this.nodegroup || msg.nodegroup;
|
var nodegroup = this.nodegroup || msg.nodegroup;
|
||||||
if(nodegroup != ""){
|
if(nodegroup !== ""){
|
||||||
this.url += '&node=' + nodegroup;
|
this.url += '&node=' + nodegroup;
|
||||||
}
|
}
|
||||||
if(typeof msg.time !== 'undefined'){
|
if(typeof msg.time !== 'undefined'){
|
||||||
@ -76,6 +78,6 @@ function Emoncms(n) {
|
|||||||
node.send(msg);
|
node.send(msg);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
RED.nodes.registerType("emoncms",Emoncms);
|
||||||
}
|
}
|
||||||
|
|
||||||
RED.nodes.registerType("emoncms",Emoncms);
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-emoncms",
|
"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.",
|
"description" : "A Node-RED node to send energy data to emoncms.org.",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-snmp",
|
"name" : "node-red-node-snmp",
|
||||||
"version" : "0.0.1",
|
"version" : "0.0.2",
|
||||||
"description" : "A Node-RED node that looks for SNMP oids.",
|
"description" : "A Node-RED node that looks for SNMP oids.",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"net-snmp" : "1.1.13"
|
"net-snmp" : "1.1.13"
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
|
"use strict";
|
||||||
var snmp = require ("net-snmp");
|
var snmp = require ("net-snmp");
|
||||||
|
|
||||||
function SnmpNode(n) {
|
function SnmpNode(n) {
|
||||||
@ -67,9 +68,9 @@ module.exports = function(RED) {
|
|||||||
var maxRepetitions = 20;
|
var maxRepetitions = 20;
|
||||||
|
|
||||||
function sortInt (a, b) {
|
function sortInt (a, b) {
|
||||||
if (a > b) return 1;
|
if (a > b) { return 1; }
|
||||||
else if (b > a) return -1;
|
else if (b > a) { return -1; }
|
||||||
else return 0;
|
else { return 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function responseCb (error, table) {
|
function responseCb (error, table) {
|
||||||
@ -77,11 +78,19 @@ module.exports = function(RED) {
|
|||||||
console.error (error.toString ());
|
console.error (error.toString ());
|
||||||
} else {
|
} else {
|
||||||
var indexes = [];
|
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);
|
indexes.sort (sortInt);
|
||||||
for (var i = 0; i < indexes.length; i++) {
|
for (var i = 0; i < indexes.length; i++) {
|
||||||
var columns = [];
|
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);
|
columns.sort(sortInt);
|
||||||
console.log ("row index = " + indexes[i]);
|
console.log ("row index = " + indexes[i]);
|
||||||
for (var j = 0; j < columns.length; j++) {
|
for (var j = 0; j < columns.length; j++) {
|
||||||
|
@ -36,13 +36,13 @@ module.exports = function(RED) {
|
|||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var lat = msg.location.lat;
|
var lt = msg.location.lat;
|
||||||
var lon = msg.location.lon;
|
var ln = msg.location.lon;
|
||||||
var len = parseInt(msg.location.precision || msg.location.payload || 9);
|
var le = parseInt(msg.location.precision || msg.location.payload || 9);
|
||||||
if (len < 1) { len = 1; }
|
if (le < 1) { le = 1; }
|
||||||
if (len > 9) { len = 9; }
|
if (le > 9) { le = 9; }
|
||||||
if (lat && lon) {
|
if (lt && ln) {
|
||||||
msg.location.geohash = geohash.encode(lat, lon, len);
|
msg.location.geohash = geohash.encode(lt, ln, le);
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,9 +51,9 @@ module.exports = function(RED) {
|
|||||||
// try to decode it...
|
// 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
|
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)) {
|
if (regexp.test(msg.payload)) {
|
||||||
var pos = geohash.decode(msg.payload);
|
var po = geohash.decode(msg.payload);
|
||||||
msg.payload = { lat:round(pos.latitude,5), lon:round(pos.longitude,5) };
|
msg.payload = { lat:round(po.latitude,5), lon:round(po.longitude,5) };
|
||||||
msg.payload.error = { lat:round(pos.error.latitude,5), lon:round(pos.error.longitude,5) };
|
msg.payload.error = { lat:round(po.error.latitude,5), lon:round(po.error.longitude,5) };
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
else if (msg.payload.indexOf(",") !== -1) {
|
else if (msg.payload.indexOf(",") !== -1) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-geohash",
|
"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.",
|
"description" : "A Node-RED node to encode and decode lat,lon pairs to a geohash.",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"ngeohash" : "0.6.0"
|
"ngeohash" : "0.6.0"
|
||||||
|
@ -461,6 +461,7 @@ module.exports = function(RED) {
|
|||||||
RED.httpAdmin.get('/pushbullet/:id/devices', function(req, res) {
|
RED.httpAdmin.get('/pushbullet/:id/devices', function(req, res) {
|
||||||
var config = RED.nodes.getNode(req.params.id);
|
var config = RED.nodes.getNode(req.params.id);
|
||||||
var cred = RED.nodes.getCredentials(req.params.id);
|
var cred = RED.nodes.getCredentials(req.params.id);
|
||||||
|
var pb;
|
||||||
|
|
||||||
if(config && config.pusher) {
|
if(config && config.pusher) {
|
||||||
config.pusher.devices(function(err, chans) {
|
config.pusher.devices(function(err, chans) {
|
||||||
@ -472,7 +473,7 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if(cred && cred.apikey) {
|
else if(cred && cred.apikey) {
|
||||||
var pb = new PushBullet(cred.apikey);
|
pb = new PushBullet(cred.apikey);
|
||||||
pb.devices(function(err, chans) {
|
pb.devices(function(err, chans) {
|
||||||
if(err) {
|
if(err) {
|
||||||
res.send("[]");
|
res.send("[]");
|
||||||
@ -482,7 +483,7 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if(req.query.apikey) {
|
else if(req.query.apikey) {
|
||||||
var pb = new PushBullet(req.query.apikey);
|
pb = new PushBullet(req.query.apikey);
|
||||||
pb.devices(function(err, chans) {
|
pb.devices(function(err, chans) {
|
||||||
if(err) {
|
if(err) {
|
||||||
res.send("[]");
|
res.send("[]");
|
||||||
|
131
test/function/rbe/rbe_spec.js
Normal file
131
test/function/rbe/rbe_spec.js
Normal 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"});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -605,6 +605,7 @@ describe('pushbullet node', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('tickle', function() {
|
describe('tickle', function() {
|
||||||
it('note', function(done) {
|
it('note', function(done) {
|
||||||
@ -777,7 +778,5 @@ describe('pushbullet node', function() {
|
|||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user