diff --git a/nodes/core/core/89-trigger.html b/nodes/core/core/89-trigger.html
index 16d092d9a..165e09d8d 100644
--- a/nodes/core/core/89-trigger.html
+++ b/nodes/core/core/89-trigger.html
@@ -172,8 +172,7 @@
}
else if ((this.duration * 1) < 0) {
$("#node-then-type").val("loop");
- this.duration = this.duration * -1;
- $("#node-input-duration").val(this.duration);
+ $("#node-input-duration").val(this.duration*-1);
} else {
$("#node-then-type").val("wait");
}
@@ -194,6 +193,7 @@
$("#node-input-duration").val($("#node-input-duration").val() * -1);
}
+
}
});
diff --git a/nodes/core/core/89-trigger.js b/nodes/core/core/89-trigger.js
index ce9debc88..5314645a0 100644
--- a/nodes/core/core/89-trigger.js
+++ b/nodes/core/core/89-trigger.js
@@ -47,7 +47,10 @@ module.exports = function(RED) {
this.extend = n.extend || "false";
this.units = n.units || "ms";
this.reset = n.reset || '';
- this.duration = n.duration || 250;
+ this.duration = parseInt(n.duration);
+ if (isNaN(this.duration)) {
+ this.duration = 250;
+ }
if (this.duration < 0) {
this.loop = true;
this.duration = this.duration * -1;
diff --git a/test/nodes/core/core/89-trigger_spec.js b/test/nodes/core/core/89-trigger_spec.js
index 2f5aee68b..85726b385 100644
--- a/test/nodes/core/core/89-trigger_spec.js
+++ b/test/nodes/core/core/89-trigger_spec.js
@@ -47,7 +47,7 @@ describe('trigger node', function() {
});
it("should be able to set delay in seconds", function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", units:"s", duration:1, "wires":[[]]}];
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", units:"s", duration:"1", "wires":[[]]}];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
n1.should.have.property('duration', 1000);
@@ -56,7 +56,7 @@ describe('trigger node', function() {
});
it("should be able to set delay in minutes", function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", units:"min", duration:1, "wires":[[]]}];
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", units:"min", duration:"1", "wires":[[]]}];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
n1.should.have.property('duration', 60000);
@@ -65,7 +65,7 @@ describe('trigger node', function() {
});
it("should be able to set delay in hours", function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", units:"hr", duration:1, "wires":[[]]}];
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", units:"hr", duration:"1", "wires":[[]]}];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
n1.should.have.property('duration', 3600000);
@@ -74,7 +74,7 @@ describe('trigger node', function() {
});
it('should output 1 then 0 when triggered (default)', function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", duration:20, wires:[["n2"]] },
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", duration:"20", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
@@ -95,7 +95,7 @@ describe('trigger node', function() {
});
it('should ignore any other inputs while triggered if extend is false', function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", duration:50,wires:[["n2"]] },
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", duration:"50",wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
@@ -137,7 +137,7 @@ describe('trigger node', function() {
});
it('should handle true and false as strings and delay of 0', function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1:"true",op1type:"val",op2:"false",op2type:"val",duration:30, wires:[["n2"]] },
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1:"true",op1type:"val",op2:"false",op2type:"val",duration:"30", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
@@ -162,7 +162,7 @@ describe('trigger node', function() {
});
it('should be able to not output anything on first trigger', function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"nul", op1:"true",op2:"false",op2type:"val",duration:30, wires:[["n2"]] },
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"nul", op1:"true",op2:"false",op2type:"val",duration:"30", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
@@ -180,7 +180,7 @@ describe('trigger node', function() {
});
it('should be able to not output anything on second edge', function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op2type:"nul", op1:"true",op1type:"val", op2:"false", duration:30, wires:[["n2"]] },
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op2type:"nul", op1:"true",op1type:"val", op2:"false", duration:"30", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
@@ -199,7 +199,7 @@ describe('trigger node', function() {
});
it('should be able to extend the delay', function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"pay", op1:"false", op2:"true", duration:100, wires:[["n2"]] },
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"pay", op1:"false", op2:"true", duration:"100", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
@@ -226,7 +226,7 @@ describe('trigger node', function() {
});
it('should be able to extend the delay (but with no 2nd output)', function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"pay", op2type:"nul", op1:"false", op2:"true", duration:50, wires:[["n2"]] },
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"pay", op2type:"nul", op1:"false", op2:"true", duration:"50", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
@@ -256,7 +256,7 @@ describe('trigger node', function() {
});
it('should be able to extend the delay and output the 2nd payload', function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"nul", op2type:"payl", op1:"false", op2:"true", duration:50, wires:[["n2"]] },
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"nul", op2type:"payl", op1:"false", op2:"true", duration:"50", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
@@ -285,7 +285,7 @@ describe('trigger node', function() {
});
it('should be able output the 2nd payload', function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"false", op1type:"nul", op2type:"payl", op1:"false", op2:"true", duration:50, wires:[["n2"]] },
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"false", op1type:"nul", op2type:"payl", op1:"false", op2:"true", duration:"50", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
@@ -314,7 +314,7 @@ describe('trigger node', function() {
});
it('should be able to apply mustache templates to payloads', function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"val", op2type:"val", op1:"{{payload}}", op2:"{{topic}}", duration:50, wires:[["n2"]] },
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"val", op2type:"val", op1:"{{payload}}", op2:"{{topic}}", duration:"50", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
@@ -335,7 +335,7 @@ describe('trigger node', function() {
});
it('should handle string null as null', function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"val", op2type:"pay", op1:"null", op2:"null", duration:40, wires:[["n2"]] },
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"val", op2type:"pay", op1:"null", op2:"null", duration:"40", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
@@ -356,7 +356,7 @@ describe('trigger node', function() {
});
it('should be able to set infinite timeout, and clear timeout', function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", duration:0, wires:[["n2"]] },
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", duration:"0", extend: false, wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
@@ -368,6 +368,9 @@ describe('trigger node', function() {
});
setTimeout( function() {
if (c === 2) { done(); }
+ else {
+ done(new Error("Too many messages received"));
+ }
},20);
n1.emit("input", {payload:null}); // trigger
n1.emit("input", {payload:null}); // blocked
@@ -378,7 +381,7 @@ describe('trigger node', function() {
});
it('should be able to set infinite timeout, and clear timeout by message', function(done) {
- var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", reset:"boo", duration:0, wires:[["n2"]] },
+ var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", reset:"boo", duration:"0", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(triggerNode, flow, function() {
var n1 = helper.getNode("n1");
@@ -390,6 +393,9 @@ describe('trigger node', function() {
});
setTimeout( function() {
if (c === 2) { done(); }
+ else {
+ done(new Error("Too many messages received"));
+ }
},20);
n1.emit("input", {payload:null}); // trigger
n1.emit("input", {payload:null}); // blocked