From b1ba8369d44ac7472be7109481f4386e893565ce Mon Sep 17 00:00:00 2001 From: Mark Hindess Date: Mon, 8 Sep 2014 21:42:16 +0100 Subject: [PATCH] Remove redundant msg != null checks. --- hardware/blinkstick/76-blinkstick.js | 28 +++++++++++++--------------- hardware/digiRGB/78-digiRGB.js | 6 ++---- hardware/wemo/60-wemo.js | 14 ++++++-------- io/wol/39-wol.js | 18 ++++++++---------- social/music/69-mpd.js | 16 +++++++--------- storage/ddb/69-ddbout.js | 8 +++----- 6 files changed, 39 insertions(+), 51 deletions(-) diff --git a/hardware/blinkstick/76-blinkstick.js b/hardware/blinkstick/76-blinkstick.js index 389dd605..ceaefef5 100644 --- a/hardware/blinkstick/76-blinkstick.js +++ b/hardware/blinkstick/76-blinkstick.js @@ -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"); diff --git a/hardware/digiRGB/78-digiRGB.js b/hardware/digiRGB/78-digiRGB.js index 3c7b49e8..735652b6 100644 --- a/hardware/digiRGB/78-digiRGB.js +++ b/hardware/digiRGB/78-digiRGB.js @@ -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"); } diff --git a/hardware/wemo/60-wemo.js b/hardware/wemo/60-wemo.js index 57415ea2..f11383e0 100644 --- a/hardware/wemo/60-wemo.js +++ b/hardware/wemo/60-wemo.js @@ -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); diff --git a/io/wol/39-wol.js b/io/wol/39-wol.js index e9174560..be475369 100644 --- a/io/wol/39-wol.js +++ b/io/wol/39-wol.js @@ -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); diff --git a/social/music/69-mpd.js b/social/music/69-mpd.js index 8fa4941a..13711775 100644 --- a/social/music/69-mpd.js +++ b/social/music/69-mpd.js @@ -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) { diff --git a/storage/ddb/69-ddbout.js b/storage/ddb/69-ddbout.js index b013cf7a..09d00124 100644 --- a/storage/ddb/69-ddbout.js +++ b/storage/ddb/69-ddbout.js @@ -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);