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

View File

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

View File

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

View File

@ -25,18 +25,16 @@ module.exports = function(RED) {
var node = this;
this.on("input", function(msg) {
if (msg != null) {
var mac = this.mac || msg.mac || null;
if (mac != null) {
if (chk.test(mac)) {
wol.wake(mac, function(error) {
if (error) { node.warn(error); }
});
}
else { node.warn('WOL: bad mac address "'+mac+'"'); }
var mac = this.mac || msg.mac || null;
if (mac != null) {
if (chk.test(mac)) {
wol.wake(mac, function(error) {
if (error) { node.warn(error); }
});
}
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);

View File

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

View File

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