mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
add reset capability to rue node
This commit is contained in:
parent
51124f456d
commit
032a9d6435
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-rbe",
|
||||
"version" : "0.1.13",
|
||||
"version" : "0.1.14",
|
||||
"description" : "A Node-RED node that provides report-by-exception (RBE) and deadband capability.",
|
||||
"dependencies" : {
|
||||
},
|
||||
|
@ -41,6 +41,9 @@
|
||||
<dt class="optional">topic <span class="property-type">string</span>
|
||||
</dt>
|
||||
<dd>if specified the function will work on a per topic basis.</dd>
|
||||
<dt class="optional">reset<span class="property-type">any</span></dt>
|
||||
<dd>if set clears the stored value for the specified msg.topic, or
|
||||
all topics if msg.topic is not specified.</dd>
|
||||
</dl>
|
||||
<h3>Outputs</h3>
|
||||
<dl class="message-properties">
|
||||
|
@ -18,6 +18,12 @@ module.exports = function(RED) {
|
||||
|
||||
node.previous = {};
|
||||
this.on("input",function(msg) {
|
||||
if (msg.hasOwnProperty("reset")) {
|
||||
if (msg.hasOwnProperty("topic") && (typeof msg.topic === "string") && (msg.topic !== "")) {
|
||||
delete node.previous[msg.topic];
|
||||
}
|
||||
else { node.previous = {}; }
|
||||
}
|
||||
if (msg.hasOwnProperty("payload")) {
|
||||
var t = msg.topic || "_no_topic";
|
||||
if ((this.func === "rbe") || (this.func === "rbei")) {
|
||||
|
@ -102,6 +102,67 @@ describe('rbe node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should send output if queue is reset (rbe)', function(done) {
|
||||
var flow = [{"id":"n1", "type":"rbe", func:"rbe", 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", "a");
|
||||
c+=1;
|
||||
}
|
||||
else if (c === 1) {
|
||||
msg.should.have.a.property("payload", "b");
|
||||
c+=1;
|
||||
}
|
||||
else if (c === 2) {
|
||||
msg.should.have.a.property("payload", "a");
|
||||
c+=1;
|
||||
}
|
||||
else if (c === 3) {
|
||||
msg.should.have.a.property("payload", "b");
|
||||
c+=1;
|
||||
}
|
||||
else if (c === 4) {
|
||||
msg.should.have.a.property("payload", "b");
|
||||
c+=1;
|
||||
}
|
||||
else if (c === 5) {
|
||||
msg.should.have.a.property("payload", "b");
|
||||
c+=1;
|
||||
}
|
||||
else if (c === 6) {
|
||||
msg.should.have.a.property("payload", "a");
|
||||
c+=1;
|
||||
}
|
||||
else {
|
||||
msg.should.have.a.property("payload", "c");
|
||||
done();
|
||||
}
|
||||
});
|
||||
n1.emit("input", {topic:"a", payload:"a"});
|
||||
n1.emit("input", {topic:"a", payload:"a"});
|
||||
n1.emit("input", {topic:"b", payload:"b"});
|
||||
n1.emit("input", {reset:true}); // reset all
|
||||
n1.emit("input", {topic:"a", payload:"a"});
|
||||
n1.emit("input", {topic:"b", payload:"b"});
|
||||
n1.emit("input", {topic:"b", payload:"b"});
|
||||
n1.emit("input", {topic:"b", reset:""}); // reset b
|
||||
n1.emit("input", {topic:"b", payload:"b"});
|
||||
n1.emit("input", {topic:"a", payload:"a"});
|
||||
n1.emit("input", {reset:""}); // reset all
|
||||
n1.emit("input", {topic:"b", payload:"b"});
|
||||
n1.emit("input", {topic:"a", payload:"a"});
|
||||
n1.emit("input", {topic:"c"}); // don't reset a non topic
|
||||
n1.emit("input", {topic:"b", payload:"b"});
|
||||
n1.emit("input", {topic:"a", payload:"a"});
|
||||
n1.emit("input", {topic:"c", payload:"c"});
|
||||
});
|
||||
});
|
||||
|
||||
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"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
|
Loading…
Reference in New Issue
Block a user