Re-lint a load of nodes

This commit is contained in:
Dave Conway-Jones
2017-01-29 17:45:44 +00:00
parent 603189f123
commit 316a2fd272
42 changed files with 447 additions and 254 deletions

View File

@@ -14,9 +14,11 @@ module.exports = function (RED) {
adjustName = function (pin) {
if (pin === "P8_7") {
pin = "P8_07";
} else if (pin === "P8_8") {
}
else if (pin === "P8_8") {
pin = "P8_08";
} else if (pin === "P8_9") {
}
else if (pin === "P8_9") {
pin = "P8_09";
}
return pin;
@@ -38,7 +40,8 @@ module.exports = function (RED) {
this.averaging = n.averaging;
if (this.averaging) {
this.averages = 10;
} else {
}
else {
this.averages = 1;
}
@@ -54,7 +57,8 @@ module.exports = function (RED) {
count = count - 1;
if (count > 0) {
bonescript.analogRead(node._pin, analogReadCallback);
} else {
}
else {
var msg = {};
msg.topic = node.topic;
sum = sum/node.averages;
@@ -76,7 +80,8 @@ module.exports = function (RED) {
count = node.averages;
bonescript.analogRead(node._pin, analogReadCallback);
});
} else {
}
else {
node.error("Unconfigured input pin");
}
}
@@ -92,18 +97,22 @@ module.exports = function (RED) {
this._pin = adjustName(this.pin); // Adjusted for Octal if necessary
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 || null; // Enable switch contact debouncing algorithm
if (n.outputOn === "rising") {
this.activeEdges = [false, true];
} else if (n.outputOn === "falling") {
}
else if (n.outputOn === "falling") {
this.activeEdges = [true, false];
} else if (n.outputOn === "both") {
}
else if (n.outputOn === "both") {
this.activeEdges = [true, true];
} else {
}
else {
node.error("Invalid edge type: " + n.outputOn);
}
@@ -130,10 +139,12 @@ module.exports = function (RED) {
node.interruptAttached = true;
node.on("input", inputCallback);
node.intervalId = setInterval(timerCallback, node.updateInterval);
} else {
}
else {
node.error("Failed to attach interrupt");
}
} else if (node.currentState !== Number(x)) {
}
else if (node.currentState !== Number(x)) {
if (node.debounce) {
if (node.debouncing === false) {
node.debouncing = true;
@@ -141,7 +152,8 @@ module.exports = function (RED) {
bonescript.digitalRead(node._pin, debounceCallback);
}, Number(node.debounce));
}
} else {
}
else {
sendStateMessage(x);
}
}
@@ -166,7 +178,8 @@ module.exports = function (RED) {
var now = Date.now();
if (node.currentState === node.activeState) {
node.lastActiveTime = now;
} else if (!isNaN(node.lastActiveTime)) {
}
else if (!isNaN(node.lastActiveTime)) {
node.totalActiveTime += now - node.lastActiveTime;
}
if (node.activeEdges[node.currentState]) {
@@ -203,7 +216,8 @@ module.exports = function (RED) {
var inputCallback = function (ipMsg) {
if (String(ipMsg.topic).search(/load/i) < 0 || isFinite(ipMsg.payload) === false) {
node.totalActiveTime = 0;
} else {
}
else {
node.totalActiveTime = Number(ipMsg.payload);
}
if (node.currentState === node.activeState) {
@@ -217,7 +231,8 @@ module.exports = function (RED) {
if (node.activeEdges[0] && node.activeEdges[1]) {
msg = [{topic: node.topic}, {topic: node.topic}];
msg[0].payload = node.currentState;
} else {
}
else {
msg = [null, {topic: node.topic}];
}
msg[1].payload = node.totalActiveTime;
@@ -246,12 +261,14 @@ module.exports = function (RED) {
node.emit("input", {});
}, 50);
});
} else {
}
else {
node.error("Unable to set " + pin + " as input: " + response);
}
});
});
} else {
}
else {
node.error("Unconfigured input pin");
}
}
@@ -286,10 +303,12 @@ module.exports = function (RED) {
node.interruptAttached = true;
node.on("input", inputCallback);
node.intervalId = setInterval(timerCallback, node.updateInterval);
} else {
}
else {
node.error("Failed to attach interrupt");
}
} else {
}
else {
node.pulseTime = [node.pulseTime[1], process.hrtime()];
node.pulseCount = node.pulseCount + 1;
}
@@ -301,7 +320,8 @@ module.exports = function (RED) {
var inputCallback = function (msg) {
if (String(msg.topic).search(/load/i) < 0 || isFinite(msg.payload) === false) {
node.pulseCount = 0;
} else {
}
else {
node.pulseCount = Number(msg.payload);
}
};
@@ -337,19 +357,22 @@ module.exports = function (RED) {
if (node.countType === "pulse") {
// interruptType = bonescript.FALLING; <- doesn't work in v0.2.4
interruptType = bonescript.RISING;
} else {
}
else {
interruptType = bonescript.CHANGE;
}
// Attempt to attach the required interrupt handler to the pin. If we succeed,
// the input event and interval handlers will be installed by interruptCallback
bonescript.attachInterrupt(node._pin, interruptType, interruptCallback)
});
} else {
}
else {
node.error("Unable to set " + pin + " as input: " + response);
}
});
});
} else {
}
else {
node.error("Unconfigured input pin");
}
}
@@ -376,12 +399,15 @@ module.exports = function (RED) {
var newState;
if (node.toggle) {
newState = node.currentState === 0 ? 1 : 0;
} else {
}
else {
if (isFinite(Number(msg.payload))) {
newState = Number(msg.payload) > 0.5;
} else if (msg.payload) {
}
else if (msg.payload) {
newState = true;
} else {
}
else {
newState = false;
}
if (node.inverting) {
@@ -402,7 +428,8 @@ module.exports = function (RED) {
setPinMode(node._pin, bonescript.OUTPUT, function (response, pin) {
if (response) {
node.error("Unable to set " + pin + " as output: " + response.err);
} else {
}
else {
node.on("input", inputCallback);
setTimeout(function () {
bonescript.digitalWrite(node._pin, node.defaultState, function() {});
@@ -410,7 +437,8 @@ module.exports = function (RED) {
}
});
});
} else {
}
else {
node.error("Unconfigured output pin");
}
}
@@ -453,10 +481,12 @@ module.exports = function (RED) {
node.send({topic: node.topic, payload: node.pulseState});
});
}
} else {
}
else {
if (node.pulseTimer !== null) {
clearTimeout(node.pulseTimer);
} else {
}
else {
bonescript.digitalWrite(node._pin, node.pulseState, function() {
node.send({topic: node.topic, payload: node.pulseState});
});
@@ -484,12 +514,14 @@ module.exports = function (RED) {
node.on("input", inputCallback);
// Set the pin to the default state once the dust settles
setTimeout(endPulseCallback, 50);
} else {
}
else {
node.error("Unable to set " + pin + " as output: " + response.err);
}
});
});
} else {
}
else {
node.error("Unconfigured output pin");
}
}

View File

@@ -1,9 +1,9 @@
{
"name" : "node-red-node-beaglebone",
"version" : "0.1.8",
"version" : "0.1.9",
"description" : "A set of Node-RED nodes to interface to the GPIO pins of a Beaglebone Black board",
"dependencies" : {
"octalbonescript":"^1.2.*"
"octalbonescript":"^1.2.2"
},
"repository" : {
"type":"git",

View File

@@ -12,7 +12,8 @@ module.exports = function(RED) {
try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
if (cpuinfo.indexOf(": BCM") === -1) { throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); }
} catch(err) {
}
catch(err) {
throw "Info : "+RED._("rpi-gpio.errors.ignorenode");
}

View File

@@ -164,10 +164,12 @@ module.exports = function(RED) {
if (node.pin !== undefined) {
if (node.pin === "12") {
node.child = spawn(gpioCommand, ["buzz",node.pin]);
} else {
}
else {
if (node.set && (node.out === "out")) {
node.child = spawn(gpioCommand, [node.out,node.pin,node.level]);
} else {
}
else {
node.child = spawn(gpioCommand, [node.out,node.pin]);
}
}

View File

@@ -32,7 +32,7 @@ module.exports = function(RED) {
return typeof (value) === "undefined" || value === null ? value = defaultValue : value;
}
function validateArray(value, defaultValue){
function validateArray(value, defaultValue) {
return typeof (value) === "undefined" || Array.isArray(value) ? value : defaultValue;
}
@@ -66,7 +66,7 @@ module.exports = function(RED) {
this.name = n.name;
this.serial = n.serial;
this.mode = n.mode || "normal";
this.mode = n.mode || "normal";
this.task = n.task || "set_color";
this.delay = n.delay || 500;
this.repeats = n.repeats || 1;
@@ -95,25 +95,28 @@ module.exports = function(RED) {
if (Object.size(node.led) === 0) {
node.status({fill:"red",shape:"ring",text:"not found"});
node.error("BlinkStick with serial number " + node.serial + " not found");
} else {
}
else {
node.status({fill:"green",shape:"dot",text:"connected"});
if(node.mode == "normal"){node.led.setMode(0);}
else if(node.mode == "inverted"){node.led.setMode(1);}
else if(node.mode == "neopixel"){node.led.setMode(2);}
if (node.mode == "normal") {node.led.setMode(0);}
else if (node.mode == "inverted") {node.led.setMode(1);}
else if (node.mode == "neopixel") {node.led.setMode(2);}
if (callback) { callback(); }
}
});
} else {
}
else {
node.led = blinkstick.findFirst();
if (Object.size(node.led) === 0) {
node.status({fill:"red",shape:"ring",text:"not found"});
node.error("No BlinkStick found");
} else {
}
else {
node.status({fill:"green",shape:"dot",text:"connected"});
if(node.mode == "normal"){node.led.setMode(0);}
else if(node.mode == "inverted"){node.led.setMode(1);}
else if(node.mode == "neopixel"){node.led.setMode(2);}
if (node.mode == "normal") {node.led.setMode(0);}
else if (node.mode == "inverted") {node.led.setMode(1);}
else if (node.mode == "neopixel") {node.led.setMode(2);}
if (callback) { callback(); }
}
}
@@ -159,12 +162,15 @@ module.exports = function(RED) {
//Select animation to perform
if (node.task == "pulse") {
node.led.pulse(node.color, {'duration': node.duration, 'steps': node.steps, 'channel': node.channel, 'index': node.index }, blinkstickAnimationComplete);
} else if (node.task == "morph") {
}
else if (node.task == "morph") {
node.led.morph(node.color, {'duration': node.duration, 'steps': node.steps, 'channel': node.channel, 'index': node.index }, blinkstickAnimationComplete);
} else if (node.task == "blink") {
}
else if (node.task == "blink") {
node.led.blink(node.color,{'repeats': node.repeats, 'delay': node.delay, 'channel': node.channel, 'index': node.index }, blinkstickAnimationComplete);
} else {
if(node.row.length > 0){
}
else {
if (node.row.length > 0) {
var dat = [];
for (var i = 0; i < node.row.length; i++) {
if (typeof node.row[i] === "string") { // if string then assume must be colour names
@@ -187,14 +193,15 @@ module.exports = function(RED) {
node.led.setColors(node.channel, dat, blinkstickAnimationComplete);
}
else {
node.warn("Colour array length not / 3");
node.warn("Colour array length not / 3");
}
}
else {
node.led.setColor(node.color, {'channel': node.channel, 'index': node.index}, blinkstickAnimationComplete);
}
}
} catch (err) {
}
catch (err) {
if (err.toString().indexOf("setColor") !== -1) {
node.led.setColour(node.color, blinkstickAnimationComplete);
node.warn("Old version - please upgrade Blinkstick npm");
@@ -269,19 +276,22 @@ module.exports = function(RED) {
node.channel = typeof(data.channel) !== 'undefined' ? data.channel : node.channel;
node.index = data.index ? data.index : node.index;
node.row = data.row ? data.row : node.row;
} else {
}
else {
node.error(data);
return;
}
}
} else if (p1.test(msg.payload)) {
}
else if (p1.test(msg.payload)) {
//Color value is represented as "red,green,blue" string of bytes
var rgb = msg.payload.split(",");
//Convert color value back to HEX string for easier implementation
node.color = "#" + decimalToHex(parseInt(rgb[0])&255) +
decimalToHex(parseInt(rgb[1])&255) + decimalToHex(parseInt(rgb[2])&255);
} else {
}
else {
//Sanitize color value
node.color = msg.payload.toLowerCase().replace(/\s+/g,'');
if (node.color === "amber") { node.color = "#FFBF00"; }
@@ -293,7 +303,8 @@ module.exports = function(RED) {
if (animationComplete) {
applyColor();
}
} else {
}
else {
//Attempt to find BlinkStick and start animation if it's found
findBlinkStick(function() {
if (animationComplete) {

View File

@@ -16,7 +16,8 @@ module.exports = function(RED) {
try {
device = new HID.HID(devices[i].path);
break;
} catch (e) {
}
catch (e) {
node.log(e)
}
}
@@ -32,16 +33,19 @@ module.exports = function(RED) {
var g = parseInt(msg.payload.slice(3,5),16);
var b = parseInt(msg.payload.slice(5),16);
device.sendFeatureReport([115,r,g,b]);
} else if (p2.test(msg.payload)) {
}
else if (p2.test(msg.payload)) {
var args = msg.payload.split(',');
if (args.length == 3) {
device.sendFeatureReport([115,parseInt(args[0]),parseInt(args[1]),parseInt(args[2])]);
}
} else {
}
else {
node.warn("incompatable input - " + msg.payload);
}
});
} else {
}
else {
node.warn("no digispark RGB found");
}

View File

@@ -16,31 +16,37 @@ module.exports = function(RED) {
var g = node.x.read();
var msg = { payload:g, topic:node.board+"/D"+node.pin };
switch (g) {
case 0:
case 0: {
node.status({fill:"green",shape:"ring",text:"low"});
if (node.interrupt=== "f" || node.interrupt === "b") {
node.send(msg);
}
break;
case 1:
}
case 1: {
node.status({fill:"green",shape:"dot",text:"high"});
if (node.interrupt=== "r" || node.interrupt === "b") {
node.send(msg);
}
break;
default:
}
default: {
node.status({fill:"grey",shape:"ring",text:"unknown"});
}
}
});
switch (node.x.read()) {
case 0:
case 0: {
node.status({fill:"green",shape:"ring",text:"low"});
break;
case 1:
}
case 1: {
node.status({fill:"green",shape:"dot",text:"high"});
break;
default:
}
default: {
node.status({});
}
}
this.on('close', function() {
node.x.isr(m.EDGE_BOTH, null);

View File

@@ -10,7 +10,8 @@ module.exports = function(RED) {
var node = this;
if (node.pin === 14) {
node.p = new m.Gpio(3,false,true); // special for onboard LED v1
} else {
}
else {
node.p = new m.Gpio(node.pin);
}
node.p.mode(m.PIN_GPIO);
@@ -21,7 +22,8 @@ module.exports = function(RED) {
node.on("input", function(msg) {
if (msg.payload == "1") {
node.p.write(1);
} else {
}
else {
node.p.write(0);
}
});

View File

@@ -56,7 +56,8 @@ module.exports = function(RED) {
}
else { console.log(key); }
});
} catch(err) { node.warn("can't open MakeyMakey: Do you need root access ?"); }
}
catch(err) { node.warn("can't open MakeyMakey: Do you need root access ?"); }
}
else {
findmakey();

View File

@@ -6,7 +6,8 @@ module.exports = function(RED) {
try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
if (cpuinfo.indexOf(": BCM") === -1) { throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); }
} catch(err) {
}
catch(err) {
throw "Info : "+RED._("rpi-gpio.errors.ignorenode");
}

View File

@@ -10,7 +10,8 @@ module.exports = function(RED) {
try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
if (cpuinfo.indexOf(": BCM") === -1) { throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); }
} catch(err) {
}
catch(err) {
throw "Info : "+RED._("rpi-gpio.errors.ignorenode");
}
@@ -57,7 +58,8 @@ module.exports = function(RED) {
if (node.mode.indexOf("need") >= 0) {
needle = colors.getRGB(parts[0],node.rgb);
pay = "0,"+(l-1)+","+node.fgnd+"\n"+l+","+needle+"\n"+(l+1)+","+(node.pixels-1)+","+node.bgnd;
} else {
}
else {
node.fgnd = colors.getRGB(parts[0],node.rgb);
pay = "0,"+l+","+node.fgnd+"\n"+(l+1)+","+(node.pixels-1)+","+node.bgnd;
}
@@ -78,7 +80,8 @@ module.exports = function(RED) {
ll = ll - 1;
if (node.mode.indexOf("need") >= 0) {
pay = "0,"+(ll-1)+","+node.fgnd+"\n"+ll+","+needle+"\n"+(ll+1)+","+(node.pixels-1)+","+node.bgnd;
} else {
}
else {
pay = "0,"+ll+","+node.fgnd+"\n"+(ll+1)+","+(node.pixels-1)+","+node.bgnd;
}
}

View File

@@ -7,42 +7,49 @@ module.exports = function(RED) {
var checkLength = function(text) {
var l = text.length;
switch(true) {
case /^http:\/\/www./.test(text):
l -= 10;
break;
case /^https:\/\/www./.test(text):
l -= 11;
break;
case /^http:\/\//.test(text):
l -= 6;
break;
case /^https:\/\//.test(text):
l -= 7;
break;
switch (true) {
case /^http:\/\/www./.test(text): {
l -= 10;
break;
}
case /^https:\/\/www./.test(text): {
l -= 11;
break;
}
case /^http:\/\//.test(text): {
l -= 6;
break;
}
case /^https:\/\//.test(text): {
l -= 7;
break;
}
}
switch(true) {
case /.*\.info\/.*/.test(text):
l -= 5;
break;
switch (true) {
case /.*\.info\/.*/.test(text): {
l -= 5;
break;
}
case /.*\.com\/.*/.test(text):
case /.*\.net\/.*/.test(text):
case /.*\.org\/.*/.test(text):
case /.*\.edu\/.*/.test(text):
case /.*\.biz\/.*/.test(text):
case /.*\.gov\/.*/.test(text):
case /.*\.info.*/.test(text):
l -= 4;
break;
case /.*\.info.*/.test(text): {
l -= 4;
break;
}
case /.*\.com.*/.test(text):
case /.*\.net.*/.test(text):
case /.*\.org.*/.test(text):
case /.*\.edu.*/.test(text):
case /.*\.biz.*/.test(text):
case /.*\.gov.*/.test(text):
l -= 3;
break;
case /.*\.gov.*/.test(text): {
l -= 3;
break;
}
}
return l;
}
@@ -70,7 +77,8 @@ module.exports = function(RED) {
try {
eddystoneBeacon.advertiseUrl(node.url, node.options);
node.status({fill:"green",shape:"dot",text:node.url});
} catch(e) {
}
catch(e) {
node.error('Error setting beacon URL', e);
}
}
@@ -83,7 +91,8 @@ module.exports = function(RED) {
try {
eddystoneBeacon.advertiseUid(node.namespace, node.instance, node.options);
node.status({fill:"green",shape:"dot",text:node.namespace});
} catch(e) {
}
catch(e) {
node.error('Error setting beacon information', e);
}
}
@@ -96,7 +105,8 @@ module.exports = function(RED) {
try {
eddystoneBeacon.stop();
node.status({fill:"red",shape:"dot",text:"Stopped"});
} catch(e) {
}
catch(e) {
node.error('error shutting down beacon', e);
}
return;
@@ -107,7 +117,8 @@ module.exports = function(RED) {
try {
eddystoneBeacon.advertiseUrl(node.url, node.options);
node.status({fill:"green",shape:"dot",text:node.url});
} catch(e) {
}
catch(e) {
node.error('Error setting beacon URL', e);
}
return;
@@ -116,7 +127,8 @@ module.exports = function(RED) {
try {
eddystoneBeacon.advertiseUid(node.namespace, node.instance, node.options);
node.status({fill:"green",shape:"dot",text:node.namespace});
} catch(e) {
}
catch(e) {
node.error('Error setting beacon information', e);
}
return;
@@ -124,30 +136,33 @@ module.exports = function(RED) {
}
// url mode
if (node.mode === "url") {
if (checkLength(msg.payload) <= 18) {
try {
node.url = msg.payload;
eddystoneBeacon.advertiseUrl(node.url, node.options);
node.status({fill:"green",shape:"dot",text:node.url});
} catch(e) {
node.status({fill:"red",shape:"dot",text:"Error setting URL"});
node.error('error updating beacon URL', e);
}
} else {
node.status({fill:"red",shape:"dot",text:"URL too long"});
}
if (checkLength(msg.payload) <= 18) {
try {
node.url = msg.payload;
eddystoneBeacon.advertiseUrl(node.url, node.options);
node.status({fill:"green",shape:"dot",text:node.url});
}
catch(e) {
node.status({fill:"red",shape:"dot",text:"Error setting URL"});
node.error('error updating beacon URL', e);
}
}
else {
node.status({fill:"red",shape:"dot",text:"URL too long"});
}
}
// uid mode
else {
try {
node.namespace = msg.payload;
node.instance = msg.topic;
eddystoneBeacon.advertiseUid(node.namespace, node.instance, node.options);
node.status({fill:"green",shape:"dot",text:msg.payload});
} catch(e) {
node.status({fill:"red",shape:"dot",text:"Error setting beacon information"});
node.error('Error setting beacon information', e);
}
try {
node.namespace = msg.payload;
node.instance = msg.topic;
eddystoneBeacon.advertiseUid(node.namespace, node.instance, node.options);
node.status({fill:"green",shape:"dot",text:msg.payload});
}
catch(e) {
node.status({fill:"red",shape:"dot",text:"Error setting beacon information"});
node.error('Error setting beacon information', e);
}
}
});
@@ -157,7 +172,8 @@ module.exports = function(RED) {
node.status({});
eddystoneBeacon.stop();
done();
} catch(e) {
}
catch(e) {
node.error('error shutting down beacon', e);
}
});

View File

@@ -100,7 +100,8 @@ module.exports = function(RED) {
},node.uuid);
}
},15000);
} else {
}
else {
console.log("reconfig",node.uuid);
enable(node);
}
@@ -114,46 +115,54 @@ module.exports = function(RED) {
var enable = function(node) {
if (node.temperature) {
node.stag.notifyIrTemperature(function() {});
} else {
}
else {
node.stag.unnotifyIrTemperature(function() {});
}
if (node.pressure) {
node.stag.notifyBarometricPressure(function() {});
} else {
}
else {
node.stag.unnotifyBarometricPressure(function() {});
}
if (node.humidity) {
node.stag.notifyHumidity(function() {});
} else {
}
else {
node.stag.unnotifyHumidity(function() {});
}
if (node.accelerometer) {
node.stag.notifyAccelerometer(function() {});
} else {
}
else {
node.stag.unnotifyAccelerometer(function() {});
}
if (node.magnetometer) {
node.stag.notifyMagnetometer(function() {});
} else {
}
else {
node.stag.unnotifyMagnetometer(function() {});
}
if (node.gyroscope) {
node.stag.notifyGyroscope(function() {});
} else {
}
else {
node.stag.unnotifyGyroscope(function() {});
}
if (node.stag.type === "cc2650") {
if (node.luxometer) {
node.stag.enableLuxometer(function() {});
node.stag.notifyLuxometer(function() {});
} else {
}
else {
node.stag.unnotifyLuxometer(function() {});
node.stag.disableLuxometer(function() {});
}
}
if (node.keys) {
node.stag.notifySimpleKey(function() {});
} else {
}
else {
node.stag.unnotifySimpleKey(function() {});
}
}

View File

@@ -48,7 +48,8 @@ module.exports = function(RED) {
delete subscriptions[dev];
delete sub2dev[sub.sid];
subscribe({dev: subs[s]});
} else {
}
else {
// console.log("resubscription good %s", res.statusCode);
// console.log("dev - %s", util.inspect(dev));
}
@@ -78,7 +79,8 @@ module.exports = function(RED) {
if (subscriptions[dev]) {
//exists
subscriptions[dev].count++;
} else {
}
else {
//new
var ipAddr;
@@ -97,7 +99,8 @@ module.exports = function(RED) {
break;
}
}
} else {
}
else {
//node 0.10 not great but best we can do
if (!addrs[add].internal && addrs[add].family == 'IPv4') {
ipAddr = addrs[add].address;
@@ -143,7 +146,8 @@ module.exports = function(RED) {
if (res.statusCode == 200) {
subscriptions[dev] = {'count': 1, 'sid': res.headers.sid};
sub2dev[res.headers.sid] = dev;
} else {
}
else {
console.log('failed to subsrcibe');
}
});
@@ -181,10 +185,12 @@ module.exports = function(RED) {
unSubreq.end();
} else {
}
else {
subscriptions[dev].count--;
}
} else {
}
else {
//shouldn't ever get here
}
}
@@ -210,7 +216,8 @@ module.exports = function(RED) {
node.status({fill: 'green',shape: 'dot',text: 'found'});
}
});
} else {
}
else {
node.status({fill: 'green',shape: 'dot',text: 'found'});
}
@@ -227,27 +234,32 @@ module.exports = function(RED) {
if (typeof msg.payload === 'string') {
if (msg.payload == 'on' || msg.payload == '1' || msg.payload == 'true') {
on = 1;
} else if (msg.payload === 'toggle') {
}
else if (msg.payload === 'toggle') {
on = 2;
}
} else if (typeof msg.payload === 'number') {
}
else if (typeof msg.payload === 'number') {
if (msg.payload >= 0 && msg.payload < 3) {
on = msg.payload;
}
} else if (typeof msg.payload === 'object') {
}
else if (typeof msg.payload === 'object') {
//object need to get complicated here
if (msg.payload.state && typeof msg.payload.state === 'number') {
if (dev.type === 'socket') {
if (msg.payload >= 0 && msg.payload < 2) {
on = msg.payload.state;
}
} else if (dev.type === 'light' || dev.type === 'group') {
}
else if (dev.type === 'light' || dev.type === 'group') {
if (msg.payload >= 0 && msg.payload < 3) {
on = msg.payload.state;
}
}
}
} else if (typeof msg.payload === 'boolean') {
}
else if (typeof msg.payload === 'boolean') {
if (msg.payload) {
on = 1;
}
@@ -256,10 +268,12 @@ module.exports = function(RED) {
if (dev.type === 'socket') {
//console.log("socket");
wemo.toggleSocket(dev, on);
} else if (dev.type === 'light`') {
}
else if (dev.type === 'light`') {
//console.log("light");
wemo.setStatus(dev,'10006', on);
} else {
}
else {
console.log('group');
wemo.setStatus(dev, '10006', on);
}
@@ -295,17 +309,18 @@ module.exports = function(RED) {
switch (notification.type){
case 'light':
case 'group':
case 'group': {
if (dd.id === notification.id) {
node.send(msg);
}
break;
case 'socket':
}
case 'socket': {
node.send(msg);
break;
default:
}
default: {}
}
}
};
@@ -316,7 +331,8 @@ module.exports = function(RED) {
if (wemo.get(node.dev)) {
node.status({fill: 'green',shape: 'dot',text: 'found'});
subscribe(node);
} else {
}
else {
wemo.on('discovered', function(d) {
if (node.dev === d) {
node.status({fill: 'green',shape: 'dot',text: 'found'});
@@ -324,7 +340,8 @@ module.exports = function(RED) {
}
});
}
} else if (node.ipaddr) {
}
else if (node.ipaddr) {
//legacy
var devices = Object.keys(wemo.devices);
for (var d in devices) {