diff --git a/function/rbe/package.json b/function/rbe/package.json index 82993da4..e9a86991 100644 --- a/function/rbe/package.json +++ b/function/rbe/package.json @@ -1,6 +1,6 @@ { "name" : "node-red-node-rbe", - "version" : "0.0.6", + "version" : "0.0.7", "description" : "A Node-RED node that provides report-by-exception (RBE) and deadband capability.", "dependencies" : { }, diff --git a/function/rbe/rbe.js b/function/rbe/rbe.js index ea7526da..456df05c 100644 --- a/function/rbe/rbe.js +++ b/function/rbe/rbe.js @@ -20,7 +20,7 @@ module.exports = function(RED) { function RbeNode(n) { RED.nodes.createNode(this,n); this.func = n.func || "rbe"; - this.gap = n.gap || 0; + this.gap = n.gap || "0"; this.pc = false; if (this.gap.substr(-1) === "%") { this.pc = true; diff --git a/test/function/rbe/rbe_spec.js b/test/function/rbe/rbe_spec.js index 9a885b52..e5815f94 100644 --- a/test/function/rbe/rbe_spec.js +++ b/test/function/rbe/rbe_spec.js @@ -37,13 +37,13 @@ describe('rbe node', function() { var n1 = helper.getNode("n1"); n1.should.have.property("name", "rbe1"); n1.should.have.property("func", "rbe"); - n1.should.have.property("gap", 0); + n1.should.have.property("gap", "0"); done(); }); }); it('should only send output if payload changes', function(done) { - var flow = [{"id":"n1", "type":"rbe", func:"rbe", gap:0, wires:[["n2"]] }, + 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"); @@ -70,7 +70,7 @@ describe('rbe node', function() { }); it('should only send output if more than x away from original value', function(done) { - var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:10, wires:[["n2"]] }, + var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:"10", wires:[["n2"]] }, {id:"n2", type:"helper"} ]; helper.load(testNode, flow, function() { var n1 = helper.getNode("n1"); @@ -100,8 +100,37 @@ describe('rbe node', function() { }); }); + it('should only send output if more than x% away from original value', function(done) { + var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:"10%", 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", 100); + } + else if (c === 1) { + msg.should.have.a.property("payload", 120); + } + else { + msg.should.have.a.property("payload", 132); + done(); + } + c += 1; + }); + n1.emit("input", {payload:100}); + n1.emit("input", {payload:95}); + n1.emit("input", {payload:105}); + n1.emit("input", {payload:120}); + n1.emit("input", {payload:130}); + n1.emit("input", {payload:132}); + }); + }); + it('should warn if no number found in gap mode', function(done) { - var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:10, wires:[["n2"]] }, + var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:"10", wires:[["n2"]] }, {id:"n2", type:"helper"} ]; helper.load(testNode, flow, function() { var n1 = helper.getNode("n1");