mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
lots of little node edits to clean up jsHint "errors"
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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" : {
|
||||
},
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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); }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
**/
|
||||
|
||||
module.exports = function(RED) {
|
||||
//"use strict";
|
||||
"use strict";
|
||||
var HID = require('node-hid');
|
||||
var device;
|
||||
var node;
|
||||
|
||||
@@ -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" :
|
||||
@@ -159,40 +159,40 @@ module.exports = function(RED) {
|
||||
}
|
||||
break;
|
||||
|
||||
// case "holiday" :
|
||||
// if (DEBUG) {
|
||||
// hminnode.log("Hit the holiday case");
|
||||
// }
|
||||
// if (!('enabled' in message.payload[key]) && !('time' in message.payload[key])) {
|
||||
// hminnode.log("Warning: Unsupported 'holiday' value passed!");
|
||||
// return;
|
||||
// }
|
||||
// var time = message.payload[key].time;
|
||||
// // Ensure hminnode time is a date
|
||||
// if (typeof(time) == "string") {
|
||||
// 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(2014, 02, 15, 12, 0, 0);
|
||||
// hminnode.log("Typeof time is now " +typeof(message.payload[key].time));
|
||||
// }
|
||||
// // Also add in away mode (for hot water) if we're on hols
|
||||
// if (message.payload[key].time) {
|
||||
// message.payload.away_mode = 1;
|
||||
// }
|
||||
// else {
|
||||
// message.payload.away_mode = 0;
|
||||
// }
|
||||
// break;
|
||||
//case "holiday" :
|
||||
//if (DEBUG) {
|
||||
//hminnode.log("Hit the holiday case");
|
||||
//}
|
||||
//if (!('enabled' in message.payload[key]) && !('time' in message.payload[key])) {
|
||||
//hminnode.log("Warning: Unsupported 'holiday' value passed!");
|
||||
//eturn;
|
||||
//}
|
||||
//var time = message.payload[key].time;
|
||||
//// Ensure hminnode time is a date
|
||||
//if (typeof(time) == "string") {
|
||||
//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(2014, 02, 15, 12, 0, 0);
|
||||
//hminnode.log("Typeof time is now " +typeof(message.payload[key].time));
|
||||
//}
|
||||
//// Also add in away mode (for hot water) if we're on hols
|
||||
//if (message.payload[key].time) {
|
||||
//message.payload.away_mode = 1;
|
||||
//}
|
||||
//else {
|
||||
//message.payload.away_mode = 0;
|
||||
//}
|
||||
//break;
|
||||
|
||||
// case "hotwater" :
|
||||
// if (DEBUG) {
|
||||
// hminnode.log("Hit the hotwater case");
|
||||
// }
|
||||
// if (message.payload[key] !== "on" && message.payload[key] !== "boost" && message.payload[key] !== "off") {
|
||||
// hminnode.log("Warning: Unsupported 'hotwater' value passed!");
|
||||
// return;
|
||||
// }
|
||||
// break;
|
||||
//case "hotwater" :
|
||||
//if (DEBUG) {
|
||||
//hminnode.log("Hit the hotwater case");
|
||||
//}
|
||||
//if (message.payload[key] !== "on" && message.payload[key] !== "boost" && message.payload[key] !== "off") {
|
||||
//hminnode.log("Warning: Unsupported 'hotwater' value passed!");
|
||||
//return;
|
||||
//}
|
||||
//break;
|
||||
|
||||
case "heating" :
|
||||
// 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
|
||||
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);
|
||||
}
|
||||
// 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) {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -40,17 +40,17 @@ function HueNodeDiscovery(n) {
|
||||
|
||||
//get username from user input
|
||||
this.username = n.username;
|
||||
|
||||
|
||||
|
||||
// Store local copies of the node configuration (as defined in the .html)
|
||||
this.topic = n.topic;
|
||||
|
||||
this.on("input", function(msg){
|
||||
|
||||
|
||||
//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);
|
||||
}
|
||||
@@ -102,4 +101,4 @@ var displayError = function(err) {
|
||||
|
||||
// Register the node by name. This must be called before overriding any of the
|
||||
// Node functions.
|
||||
RED.nodes.registerType("Discover",HueNodeDiscovery);
|
||||
RED.nodes.registerType("Discover",HueNodeDiscovery);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user