Updates to sentiment, exec and range to handle missing payload properties

This commit is contained in:
dceejay
2015-03-31 08:35:56 +01:00
parent 9c22a770ef
commit 78d1da5fbc
5 changed files with 74 additions and 33 deletions

View File

@@ -23,10 +23,13 @@ module.exports = function(RED) {
var node = this;
this.on("input", function(msg) {
sentiment(msg.payload, msg.overrides || null, function (err, result) {
msg.sentiment = result;
node.send(msg);
});
if (msg.hasOwnProperty("payload")) {
sentiment(msg.payload, msg.overrides || null, function (err, result) {
msg.sentiment = result;
node.send(msg);
});
}
else { node.send(msg); } // If no payload - just pass it on.
});
}
RED.nodes.registerType("sentiment",SentimentNode);

View File

@@ -66,7 +66,7 @@ module.exports = function(RED) {
}
else {
var cl = node.cmd;
if ((node.addpay === true) && (msg.payload.trim() !== "")) { cl += " "+msg.payload; }
if ((node.addpay === true) && ((msg.payload || "").trim() !== "")) { cl += " "+msg.payload; }
if (node.append.trim() !== "") { cl += " "+node.append; }
if (RED.settings.verbose) { node.log(cl); }
var child = exec(cl, {encoding: 'binary', maxBuffer:10000000}, function (error, stdout, stderr) {

View File

@@ -27,21 +27,24 @@ module.exports = function(RED) {
var node = this;
this.on('input', function (msg) {
var n = Number(msg.payload);
if (!isNaN(n)) {
if (node.action == "clamp") {
if (n < node.minin) { n = node.minin; }
if (n > node.maxin) { n = node.maxin; }
if (msg.hasOwnProperty("payload")) {
var n = Number(msg.payload);
if (!isNaN(n)) {
if (node.action == "clamp") {
if (n < node.minin) { n = node.minin; }
if (n > node.maxin) { n = node.maxin; }
}
if (node.action == "roll") {
if (n >= node.maxin) { n = (n - node.minin) % (node.maxin - node.minin) + node.minin; }
if (n < node.minin) { n = (n - node.minin) % (node.maxin - node.minin) + node.maxin; }
}
msg.payload = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout;
if (node.round) { msg.payload = Math.round(msg.payload); }
node.send(msg);
}
if (node.action == "roll") {
if (n >= node.maxin) { n = (n - node.minin) % (node.maxin - node.minin) + node.minin; }
if (n < node.minin) { n = (n - node.minin) % (node.maxin - node.minin) + node.maxin; }
}
msg.payload = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout;
if (node.round) { msg.payload = Math.round(msg.payload); }
node.send(msg);
else { node.log("Not a number: "+msg.payload); }
}
else { node.log("Not a number: "+msg.payload); }
else { node.send(msg); } // If no payload - just pass it on.
});
}
RED.nodes.registerType("range", RangeNode);