node-red-contrib-boolean-logic-ultimate 1.1.27 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -1
- package/README.md +108 -1
- package/boolean-logic-ultimate/PresenceSimulatorUltimate.html +119 -0
- package/boolean-logic-ultimate/PresenceSimulatorUltimate.js +247 -0
- package/boolean-logic-ultimate/RateLimiterUltimate.html +164 -0
- package/boolean-logic-ultimate/RateLimiterUltimate.js +396 -0
- package/boolean-logic-ultimate/StaircaseLightUltimate.html +165 -0
- package/boolean-logic-ultimate/StaircaseLightUltimate.js +229 -0
- package/boolean-logic-ultimate/lib/node-helpers.js +96 -0
- package/package.json +13 -1
- package/test/helpers.js +29 -0
- package/test/presence-simulator.spec.js +101 -0
- package/test/rate-limiter.spec.js +169 -0
- package/test/staircase-light.spec.js +134 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const { helper } = require('./helpers');
|
|
5
|
+
|
|
6
|
+
const staircaseNode = require('../boolean-logic-ultimate/StaircaseLightUltimate.js');
|
|
7
|
+
|
|
8
|
+
function loadStaircase(flow, credentials) {
|
|
9
|
+
return helper.load(staircaseNode, flow, credentials || {});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe('StaircaseLightUltimate node', function () {
|
|
13
|
+
this.timeout(5000);
|
|
14
|
+
|
|
15
|
+
before(function (done) {
|
|
16
|
+
helper.startServer(done);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
after(function (done) {
|
|
20
|
+
helper.stopServer(done);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
afterEach(function () {
|
|
24
|
+
return helper.unload();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('emits warning before turning off', function (done) {
|
|
28
|
+
const flowId = 'stair1';
|
|
29
|
+
const flow = [
|
|
30
|
+
{ id: flowId, type: 'tab', label: 'stair1' },
|
|
31
|
+
{
|
|
32
|
+
id: 'stair',
|
|
33
|
+
type: 'StaircaseLightUltimate',
|
|
34
|
+
z: flowId,
|
|
35
|
+
controlTopic: 'stairs',
|
|
36
|
+
durationSeconds: 0.2,
|
|
37
|
+
warningEnabled: true,
|
|
38
|
+
warningOffsetSeconds: 0.1,
|
|
39
|
+
restartOnTrigger: true,
|
|
40
|
+
allowOffInput: false,
|
|
41
|
+
onPayload: true,
|
|
42
|
+
onPayloadType: 'bool',
|
|
43
|
+
offPayload: false,
|
|
44
|
+
offPayloadType: 'bool',
|
|
45
|
+
warningPayload: 'warning',
|
|
46
|
+
warningPayloadType: 'str',
|
|
47
|
+
wires: [['outOn'], ['outWarn']],
|
|
48
|
+
},
|
|
49
|
+
{ id: 'in', type: 'helper', z: flowId, wires: [['stair']] },
|
|
50
|
+
{ id: 'outOn', type: 'helper', z: flowId },
|
|
51
|
+
{ id: 'outWarn', type: 'helper', z: flowId },
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
loadStaircase(flow).then(() => {
|
|
55
|
+
const input = helper.getNode('in');
|
|
56
|
+
const outOn = helper.getNode('outOn');
|
|
57
|
+
const outWarn = helper.getNode('outWarn');
|
|
58
|
+
const events = [];
|
|
59
|
+
|
|
60
|
+
outOn.on('input', (msg) => {
|
|
61
|
+
events.push({ type: msg.event, payload: msg.payload });
|
|
62
|
+
});
|
|
63
|
+
outWarn.on('input', (msg) => {
|
|
64
|
+
events.push({ type: msg.event, payload: msg.payload });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
try {
|
|
69
|
+
const types = events.map((e) => e.type);
|
|
70
|
+
expect(types).to.include('on');
|
|
71
|
+
expect(types).to.include('warning');
|
|
72
|
+
expect(types).to.include('off');
|
|
73
|
+
done();
|
|
74
|
+
} catch (err) {
|
|
75
|
+
done(err);
|
|
76
|
+
}
|
|
77
|
+
}, 400);
|
|
78
|
+
|
|
79
|
+
input.receive({ payload: true });
|
|
80
|
+
}).catch(done);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('extends timer on control extend command', function (done) {
|
|
84
|
+
const flowId = 'stair2';
|
|
85
|
+
const flow = [
|
|
86
|
+
{ id: flowId, type: 'tab', label: 'stair2' },
|
|
87
|
+
{
|
|
88
|
+
id: 'stair',
|
|
89
|
+
type: 'StaircaseLightUltimate',
|
|
90
|
+
z: flowId,
|
|
91
|
+
controlTopic: 'stairs',
|
|
92
|
+
durationSeconds: 0.15,
|
|
93
|
+
warningEnabled: false,
|
|
94
|
+
restartOnTrigger: true,
|
|
95
|
+
onPayload: true,
|
|
96
|
+
onPayloadType: 'bool',
|
|
97
|
+
offPayload: false,
|
|
98
|
+
offPayloadType: 'bool',
|
|
99
|
+
wires: [['out'], ['warn']],
|
|
100
|
+
},
|
|
101
|
+
{ id: 'in', type: 'helper', z: flowId, wires: [['stair']] },
|
|
102
|
+
{ id: 'control', type: 'helper', z: flowId, wires: [['stair']] },
|
|
103
|
+
{ id: 'out', type: 'helper', z: flowId },
|
|
104
|
+
{ id: 'warn', type: 'helper', z: flowId },
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
loadStaircase(flow).then(() => {
|
|
108
|
+
const input = helper.getNode('in');
|
|
109
|
+
const control = helper.getNode('control');
|
|
110
|
+
const out = helper.getNode('out');
|
|
111
|
+
const events = [];
|
|
112
|
+
|
|
113
|
+
out.on('input', (msg) => {
|
|
114
|
+
events.push({ type: msg.event, at: Date.now() });
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
input.receive({ payload: true });
|
|
118
|
+
|
|
119
|
+
setTimeout(() => {
|
|
120
|
+
control.receive({ topic: 'stairs', command: 'extend' });
|
|
121
|
+
}, 80);
|
|
122
|
+
|
|
123
|
+
setTimeout(() => {
|
|
124
|
+
try {
|
|
125
|
+
const offEvents = events.filter((e) => e.type === 'off');
|
|
126
|
+
expect(offEvents.length).to.equal(1);
|
|
127
|
+
done();
|
|
128
|
+
} catch (err) {
|
|
129
|
+
done(err);
|
|
130
|
+
}
|
|
131
|
+
}, 400);
|
|
132
|
+
}).catch(done);
|
|
133
|
+
});
|
|
134
|
+
});
|