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

add ignore first message option to rue node

This commit is contained in:
Dave Conway-Jones 2017-05-24 13:14:55 +01:00
parent 8799b1e85b
commit 76e33acae5
No known key found for this signature in database
GPG Key ID: 81B04231572A9A2D
5 changed files with 51 additions and 6 deletions

View File

@ -2,6 +2,7 @@
"rbe": { "rbe": {
"label": { "label": {
"func": "Mode", "func": "Mode",
"init": "Send initial value",
"start": "Start value", "start": "Start value",
"name": "Name" "name": "Name"
}, },
@ -11,6 +12,7 @@
}, },
"opts": { "opts": {
"rbe": "block unless value changes", "rbe": "block unless value changes",
"rbei": "block unless value changes (ignore initial value)",
"deadband": "block unless value change is greater than", "deadband": "block unless value change is greater than",
"deadbandEq": "block unless value change is greater or equal to", "deadbandEq": "block unless value change is greater or equal to",
"narrowband": "block if value change is greater than", "narrowband": "block if value change is greater than",

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-rbe", "name" : "node-red-node-rbe",
"version" : "0.1.8", "version" : "0.1.9",
"description" : "A Node-RED node that provides report-by-exception (RBE) and deadband capability.", "description" : "A Node-RED node that provides report-by-exception (RBE) and deadband capability.",
"dependencies" : { "dependencies" : {
}, },

View File

@ -4,6 +4,7 @@
<label for="node-input-func"><i class="fa fa-wrench"></i> <span data-i18n="rbe.label.func"></span></label> <label for="node-input-func"><i class="fa fa-wrench"></i> <span data-i18n="rbe.label.func"></span></label>
<select type="text" id="node-input-func" style="width:74%;"> <select type="text" id="node-input-func" style="width:74%;">
<option value="rbe" data-i18n="rbe.opts.rbe"></option> <option value="rbe" data-i18n="rbe.opts.rbe"></option>
<option value="rbei" data-i18n="rbe.opts.rbei"></option>
<option value="deadbandEq" data-i18n="rbe.opts.deadbandEq"></option> <option value="deadbandEq" data-i18n="rbe.opts.deadbandEq"></option>
<option value="deadband" data-i18n="rbe.opts.deadband"></option> <option value="deadband" data-i18n="rbe.opts.deadband"></option>
<option value="narrowbandEq" data-i18n="rbe.opts.narrowbandEq"></option> <option value="narrowbandEq" data-i18n="rbe.opts.narrowbandEq"></option>
@ -78,7 +79,7 @@
outputs:1, outputs:1,
icon: "rbe.png", icon: "rbe.png",
label: function() { label: function() {
var ll = (this.func||"").replace("Eq","")||"rbe"; var ll = (this.func||"").replace("Eq","").replace("rbei","rbe")||"rbe";
return this.name||ll||"rbe"; return this.name||ll||"rbe";
}, },
labelStyle: function() { labelStyle: function() {
@ -90,7 +91,7 @@
$("#node-input-inout").val("out"); $("#node-input-inout").val("out");
} }
$("#node-input-func").on("change",function() { $("#node-input-func").on("change",function() {
if ($("#node-input-func").val() === "rbe") { if (($("#node-input-func").val() === "rbe")||($("#node-input-func").val() === "rbei")) {
$("#node-bandgap").hide(); $("#node-bandgap").hide();
} else { } else {
$("#node-bandgap").show(); $("#node-bandgap").show();

View File

@ -13,24 +13,26 @@ module.exports = function(RED) {
this.gap = parseFloat(this.gap); this.gap = parseFloat(this.gap);
} }
this.g = this.gap; this.g = this.gap;
var node = this; var node = this;
node.previous = {}; node.previous = {};
this.on("input",function(msg) { this.on("input",function(msg) {
if (msg.hasOwnProperty("payload")) { if (msg.hasOwnProperty("payload")) {
var t = msg.topic || "_no_topic"; var t = msg.topic || "_no_topic";
if (this.func === "rbe") { if ((this.func === "rbe") || (this.func === "rbei")) {
var doSend = (this.func !== "rbei") || (node.previous.hasOwnProperty(t)) || false;
if (typeof(msg.payload) === "object") { if (typeof(msg.payload) === "object") {
if (typeof(node.previous[t]) !== "object") { node.previous[t] = {}; } if (typeof(node.previous[t]) !== "object") { node.previous[t] = {}; }
if (!RED.util.compareObjects(msg.payload, node.previous[t])) { if (!RED.util.compareObjects(msg.payload, node.previous[t])) {
node.previous[t] = msg.payload; node.previous[t] = msg.payload;
node.send(msg); if (doSend) { node.send(msg); }
} }
} }
else { else {
if (msg.payload !== node.previous[t]) { if (msg.payload !== node.previous[t]) {
node.previous[t] = msg.payload; node.previous[t] = msg.payload;
node.send(msg); if (doSend) { node.send(msg); }
} }
} }
} }

View File

@ -62,6 +62,46 @@ describe('rbe node', function() {
}); });
}); });
it('should only send output if payload changes - ignoring first value (rbei)', function(done) {
var flow = [{"id":"n1", "type":"rbe", func:"rbei", gap:"0", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(testNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var c = 0;
n2.on("input", function(msg) {
if (c === 0) {
msg.should.have.a.property("payload", "b");
msg.should.have.a.property("topic", "a");
c+=1;
}
else if (c === 1) {
msg.should.have.a.property("payload", "b");
msg.should.have.a.property("topic", "b");
c+=1;
}
else if (c === 2) {
msg.should.have.a.property("payload", "c");
msg.should.have.a.property("topic", "a");
c+=1;
}
else {
msg.should.have.a.property("payload", "c");
msg.should.have.a.property("topic", "b");
done();
}
});
n1.emit("input", {payload:"a", topic:"a"});
n1.emit("input", {payload:"a", topic:"b"});
n1.emit("input", {payload:"a", topic:"a"});
n1.emit("input", {payload:"b", topic:"a"});
n1.emit("input", {payload:"b", topic:"b"});
n1.emit("input", {payload:"c", topic:"a"});
n1.emit("input", {payload:"c", topic:"b"});
});
});
it('should only send output if x away from original value (deadbandEq)', function(done) { it('should only send output if x away from original value (deadbandEq)', function(done) {
var flow = [{"id":"n1", "type":"rbe", func:"deadbandEq", gap:"10", inout:"out", wires:[["n2"]] }, var flow = [{"id":"n1", "type":"rbe", func:"deadbandEq", gap:"10", inout:"out", wires:[["n2"]] },
{id:"n2", type:"helper"} ]; {id:"n2", type:"helper"} ];