mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
RBE node - let topic handling be optional (#751)
* let rbe handle topics optional and add tests * fix text formatting * Update package.json
This commit is contained in:
parent
68e0b121ec
commit
9db89f3ea1
@ -5,7 +5,8 @@
|
||||
"func": "Mode",
|
||||
"init": "Send initial value",
|
||||
"start": "Start value",
|
||||
"name": "Name"
|
||||
"name": "Name",
|
||||
"septopics": "Apply mode for each msg.topic separately"
|
||||
},
|
||||
"placeholder":{
|
||||
"bandgap": "e.g. 10 or 5%",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-rbe",
|
||||
"version" : "0.2.9",
|
||||
"version" : "0.3.0",
|
||||
"description" : "A Node-RED node that provides report-by-exception (RBE) and deadband capabilities.",
|
||||
"dependencies" : {
|
||||
},
|
||||
|
@ -27,6 +27,11 @@
|
||||
<label for="node-input-property"><i class="fa fa-ellipsis-h"></i> <span data-i18n="node-red:common.label.property"></span></label>
|
||||
<input type="text" id="node-input-property" style="width:70%;"/>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label> </label>
|
||||
<input type="checkbox" id="node-input-septopics" style="display:inline-block; width:20px; vertical-align:baseline;">
|
||||
<span data-i18n="rbe.label.septopics"></span>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="rbe.label.name"></span></label>
|
||||
<input type="text" id="node-input-name" data-i18n="[placeholder]rbe.label.name" style="width:70%;">
|
||||
@ -43,6 +48,7 @@
|
||||
gap: {value:"",validate:RED.validators.regex(/^(\d*[.]*\d*|)(%|)$/)},
|
||||
start: {value:""},
|
||||
inout: {value:"out"},
|
||||
septopics: {value:true},
|
||||
property: {value:"payload",required:true}
|
||||
},
|
||||
inputs:1,
|
||||
@ -59,6 +65,9 @@
|
||||
if (this.property === undefined) {
|
||||
$("#node-input-property").val("payload");
|
||||
}
|
||||
if (this.septopics === undefined) {
|
||||
$("#node-input-septopics").prop('checked', true);
|
||||
}
|
||||
$("#node-input-property").typedInput({default:'msg',types:['msg']});
|
||||
//$( "#node-input-gap" ).spinner({min:0});
|
||||
if ($("#node-input-inout").val() === null) {
|
||||
|
@ -14,20 +14,25 @@ module.exports = function(RED) {
|
||||
}
|
||||
this.g = this.gap;
|
||||
this.property = n.property||"payload";
|
||||
this.septopics = true;
|
||||
if (n.septopics !== undefined && n.septopics === false) {
|
||||
this.septopics = false;
|
||||
}
|
||||
|
||||
var node = this;
|
||||
|
||||
node.previous = {};
|
||||
this.on("input",function(msg) {
|
||||
if (msg.hasOwnProperty("reset")) {
|
||||
if (msg.hasOwnProperty("topic") && (typeof msg.topic === "string") && (msg.topic !== "")) {
|
||||
if (node.septopics && msg.hasOwnProperty("topic") && (typeof msg.topic === "string") && (msg.topic !== "")) {
|
||||
delete node.previous[msg.topic];
|
||||
}
|
||||
else { node.previous = {}; }
|
||||
}
|
||||
var value = RED.util.getMessageProperty(msg,node.property);
|
||||
if (value !== undefined) {
|
||||
var t = msg.topic || "_no_topic";
|
||||
var t = "_no_topic";
|
||||
if (node.septopics) { t = msg.topic || t; }
|
||||
if ((this.func === "rbe") || (this.func === "rbei")) {
|
||||
var doSend = (this.func !== "rbei") || (node.previous.hasOwnProperty(t)) || false;
|
||||
if (typeof(value) === "object") {
|
||||
|
@ -26,10 +26,5 @@
|
||||
"name": "Dave Conway-Jones",
|
||||
"email": "ceejay@vnet.ibm.com",
|
||||
"url": "http://nodered.org"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "@tweek"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ describe('rbe node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should only send output if payload changes (rbe)', function(done) {
|
||||
it('should only send output if payload changes - with multiple topics (rbe)', function(done) {
|
||||
var flow = [{"id":"n1", "type":"rbe", func:"rbe", gap:"0", wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(testNode, flow, function() {
|
||||
@ -57,8 +57,24 @@ describe('rbe node', function() {
|
||||
msg.should.have.a.property("payload",false);
|
||||
c+=1;
|
||||
}
|
||||
else {
|
||||
else if (c == 5) {
|
||||
msg.should.have.a.property("payload",true);
|
||||
c+=1;
|
||||
}
|
||||
else if (c == 6) {
|
||||
msg.should.have.a.property("topic","a");
|
||||
msg.should.have.a.property("payload",1);
|
||||
c+=1;
|
||||
}
|
||||
else if (c == 7) {
|
||||
msg.should.have.a.property("topic","b");
|
||||
msg.should.have.a.property("payload",1);
|
||||
c+=1;
|
||||
}
|
||||
else {
|
||||
c += 1;
|
||||
msg.should.have.a.property("topic","c");
|
||||
msg.should.have.a.property("payload",1);
|
||||
done();
|
||||
}
|
||||
});
|
||||
@ -74,6 +90,80 @@ describe('rbe node', function() {
|
||||
n1.emit("input", {payload:false});
|
||||
n1.emit("input", {payload:false});
|
||||
n1.emit("input", {payload:true});
|
||||
|
||||
n1.emit("input", {topic:"a",payload:1});
|
||||
n1.emit("input", {topic:"b",payload:1});
|
||||
n1.emit("input", {topic:"b",payload:1});
|
||||
n1.emit("input", {topic:"a",payload:1});
|
||||
n1.emit("input", {topic:"c",payload:1});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore multiple topics if told to (rbe)', function(done) {
|
||||
var flow = [{id:"n1", type:"rbe", func:"rbe", gap:"0", septopics:false, 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", 2);
|
||||
c+=1;
|
||||
}
|
||||
else if (c == 2) {
|
||||
msg.should.have.a.property("payload");
|
||||
msg.payload.should.have.a.property("b",1);
|
||||
msg.payload.should.have.a.property("c",2);
|
||||
c+=1;
|
||||
}
|
||||
else if (c == 3) {
|
||||
msg.should.have.a.property("payload",true);
|
||||
c+=1;
|
||||
}
|
||||
else if (c == 4) {
|
||||
msg.should.have.a.property("payload",false);
|
||||
c+=1;
|
||||
}
|
||||
else if (c == 5) {
|
||||
msg.should.have.a.property("payload",true);
|
||||
c+=1;
|
||||
}
|
||||
else if (c == 6) {
|
||||
msg.should.have.a.property("topic","a");
|
||||
msg.should.have.a.property("payload",1);
|
||||
c+=1;
|
||||
}
|
||||
else {
|
||||
msg.should.have.a.property("topic","a");
|
||||
msg.should.have.a.property("payload",2);
|
||||
done();
|
||||
}
|
||||
});
|
||||
n1.emit("input", {topic:"a",payload:"a"});
|
||||
n1.emit("input", {topic:"b",payload:"a"});
|
||||
n1.emit("input", {topic:"c",payload:"a"});
|
||||
n1.emit("input", {topic:"a",payload:2});
|
||||
n1.emit("input", {topic:"b",payload:2});
|
||||
n1.emit("input", {payload:{b:1,c:2}});
|
||||
n1.emit("input", {payload:{c:2,b:1}});
|
||||
n1.emit("input", {payload:{c:2,b:1}});
|
||||
n1.emit("input", {topic:"a",payload:true});
|
||||
n1.emit("input", {topic:"b",payload:false});
|
||||
n1.emit("input", {topic:"c",payload:false});
|
||||
n1.emit("input", {topic:"d",payload:true});
|
||||
|
||||
n1.emit("input", {topic:"a",payload:1});
|
||||
n1.emit("input", {topic:"b",payload:1});
|
||||
n1.emit("input", {topic:"c",payload:1});
|
||||
n1.emit("input", {topic:"d",payload:1});
|
||||
n1.emit("input", {topic:"a",payload:2});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user