1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Merge pull request #68 from hindessm/remove-redundant-null-checks

Remove redundant msg != null checks.
This commit is contained in:
Nick O'Leary 2014-09-08 21:53:47 +01:00
commit 01d1eadf65
6 changed files with 39 additions and 51 deletions

View File

@ -32,27 +32,25 @@ module.exports = function(RED) {
var node = this; var node = this;
this.on("input", function(msg) { this.on("input", function(msg) {
if (msg != null) { if (Object.size(node.led) !== 0) {
if (Object.size(node.led) !== 0) { try {
try { if (p2.test(msg.payload)) {
if (p2.test(msg.payload)) { var rgb = msg.payload.split(",");
var rgb = msg.payload.split(","); node.led.setColor(parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255);
node.led.setColor(parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255);
}
else {
node.led.setColor(msg.payload.toLowerCase().replace(/\s+/g,''));
}
} }
catch (err) { else {
node.warn("BlinkStick missing ?"); node.led.setColor(msg.payload.toLowerCase().replace(/\s+/g,''));
node.led = blinkstick.findFirst();
} }
} }
else { catch (err) {
//node.warn("No BlinkStick found"); node.warn("BlinkStick missing ?");
node.led = blinkstick.findFirst(); node.led = blinkstick.findFirst();
} }
} }
else {
//node.warn("No BlinkStick found");
node.led = blinkstick.findFirst();
}
}); });
if (Object.size(node.led) === 0) { if (Object.size(node.led) === 0) {
node.error("No BlinkStick found"); node.error("No BlinkStick found");

View File

@ -42,8 +42,7 @@ module.exports = function(RED) {
var p2 = /[0-9]+,[0-9]+,[0-9]+/ var p2 = /[0-9]+,[0-9]+,[0-9]+/
if (device) { if (device) {
this.on("input", function(msg) { this.on("input", function(msg) {
if (msg != null) {
if (p1.test(msg.payload)) { if (p1.test(msg.payload)) {
var r = parseInt(msg.payload.slice(1,3),16); var r = parseInt(msg.payload.slice(1,3),16);
var g = parseInt(msg.payload.slice(3,5),16); var g = parseInt(msg.payload.slice(3,5),16);
@ -57,8 +56,7 @@ module.exports = function(RED) {
} else { } else {
node.warn("incompatable input - " + msg.payload); node.warn("incompatable input - " + msg.payload);
} }
} });
});
} else { } else {
node.warn("no digispark RGB found"); node.warn("no digispark RGB found");
} }

View File

@ -25,14 +25,12 @@ module.exports = function(RED) {
var node = this; var node = this;
this.on("input", function(msg) { this.on("input", function(msg) {
if (msg != null) { var state = 0;
var state = 0; if ( msg.payload == 1 || msg.payload === true || msg.payload == "on" ) { state = 1; }
if ( msg.payload == 1 || msg.payload === true || msg.payload == "on" ) { state = 1; } node.wemoSwitch.setBinaryState(state, function(err, result) {
node.wemoSwitch.setBinaryState(state, function(err, result) { if (err) { node.warn(err); }
if (err) { node.warn(err); } //else { node.log(result); }
//else { node.log(result); } });
});
}
}); });
} }
RED.nodes.registerType("wemo out",WemoOut); RED.nodes.registerType("wemo out",WemoOut);

View File

@ -25,18 +25,16 @@ module.exports = function(RED) {
var node = this; var node = this;
this.on("input", function(msg) { this.on("input", function(msg) {
if (msg != null) { var mac = this.mac || msg.mac || null;
var mac = this.mac || msg.mac || null; if (mac != null) {
if (mac != null) { if (chk.test(mac)) {
if (chk.test(mac)) { wol.wake(mac, function(error) {
wol.wake(mac, function(error) { if (error) { node.warn(error); }
if (error) { node.warn(error); } });
});
}
else { node.warn('WOL: bad mac address "'+mac+'"'); }
} }
else { node.warn("WOL: no mac address specified"); } else { node.warn('WOL: bad mac address "'+mac+'"'); }
} }
else { node.warn("WOL: no mac address specified"); }
}); });
} }
RED.nodes.registerType("wake on lan",WOLnode); RED.nodes.registerType("wake on lan",WOLnode);

View File

@ -44,15 +44,13 @@ module.exports = function(RED) {
if (mpc != null) { if (mpc != null) {
this.on("input", function(msg) { this.on("input", function(msg) {
if (msg != null) { try {
try { //node.mpc.command(msg.payload);
//node.mpc.command(msg.payload); node.mpc.command(msg.payload, msg.param, function(err, results) {
node.mpc.command(msg.payload, msg.param, function(err, results) { if (err) { node.log("error: "+err); }
if (err) { node.log("error: "+err); } //else { console.log(results); }
//else { console.log(results); } });
}); } catch (err) { node.log("error: "+err); }
} catch (err) { node.log("error: "+err); }
}
}); });
node.mpc.on('error', function(err) { node.mpc.on('error', function(err) {

View File

@ -32,13 +32,11 @@ function DDBOutNode(n) {
var ddb = new aws.DynamoDB(); var ddb = new aws.DynamoDB();
this.on("input", function(msg) { this.on("input", function(msg) {
if (msg != null) { ddb.putItem({ "TableName": this.table,
ddb.putItem({ "TableName": this.table, "Item": attrWrapper.wrap(msg.payload) },
"Item": attrWrapper.wrap(msg.payload) },
function(err, data) { function(err, data) {
if (err) { util.log(err); } if (err) { util.log(err); }
}); });
}
}); });
} }
RED.nodes.registerType("ddb out", DDBOutNode); RED.nodes.registerType("ddb out", DDBOutNode);