node-red-contrib-boolean-logic-ultimate 1.2.6 → 1.2.9
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 +13 -1
- package/README.md +238 -132
- package/boolean-logic-ultimate/HysteresisUltimate.html +137 -0
- package/boolean-logic-ultimate/HysteresisUltimate.js +197 -0
- package/boolean-logic-ultimate/PresenceSimulatorUltimate.html +1 -0
- package/boolean-logic-ultimate/RateLimiterUltimate.html +2 -2
- package/boolean-logic-ultimate/StaircaseLightUltimate.html +1 -0
- package/examples/HysteresisUltimate.json +109 -0
- package/examples/README.md +29 -0
- package/img/alarm-system-ultimate.svg +69 -0
- package/package.json +3 -2
- package/test/hysteresis.spec.js +87 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const { helper } = require('./helpers');
|
|
5
|
+
|
|
6
|
+
const hysteresisNode = require('../boolean-logic-ultimate/HysteresisUltimate.js');
|
|
7
|
+
|
|
8
|
+
function loadHysteresis(flow, credentials) {
|
|
9
|
+
const normalizedFlow = flow.map((node, index) => {
|
|
10
|
+
if (
|
|
11
|
+
node &&
|
|
12
|
+
node.type &&
|
|
13
|
+
node.type !== 'tab' &&
|
|
14
|
+
node.type !== 'subflow' &&
|
|
15
|
+
node.type !== 'group' &&
|
|
16
|
+
node.z &&
|
|
17
|
+
!(Object.prototype.hasOwnProperty.call(node, 'x') && Object.prototype.hasOwnProperty.call(node, 'y'))
|
|
18
|
+
) {
|
|
19
|
+
return { ...node, x: 100 + index * 10, y: 100 + index * 10 };
|
|
20
|
+
}
|
|
21
|
+
return node;
|
|
22
|
+
});
|
|
23
|
+
return helper.load(hysteresisNode, normalizedFlow, credentials || {});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('HysteresisUltimate node', function () {
|
|
27
|
+
this.timeout(5000);
|
|
28
|
+
|
|
29
|
+
before(function (done) {
|
|
30
|
+
helper.startServer(done);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
after(function (done) {
|
|
34
|
+
helper.stopServer(done);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(function () {
|
|
38
|
+
return helper.unload();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('emits on state transitions only', function (done) {
|
|
42
|
+
const flowId = 'hys1';
|
|
43
|
+
const flow = [
|
|
44
|
+
{ id: flowId, type: 'tab', label: 'hys1' },
|
|
45
|
+
{
|
|
46
|
+
id: 'hys',
|
|
47
|
+
type: 'HysteresisUltimate',
|
|
48
|
+
z: flowId,
|
|
49
|
+
mode: 'high',
|
|
50
|
+
onThreshold: 70,
|
|
51
|
+
offThreshold: 60,
|
|
52
|
+
emitOnlyOnChange: true,
|
|
53
|
+
onPayload: true,
|
|
54
|
+
onPayloadType: 'bool',
|
|
55
|
+
offPayload: false,
|
|
56
|
+
offPayloadType: 'bool',
|
|
57
|
+
wires: [['out'], ['diag']],
|
|
58
|
+
},
|
|
59
|
+
{ id: 'in', type: 'helper', z: flowId, wires: [['hys']] },
|
|
60
|
+
{ id: 'out', type: 'helper', z: flowId },
|
|
61
|
+
{ id: 'diag', type: 'helper', z: flowId },
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
loadHysteresis(flow).then(() => {
|
|
65
|
+
const hys = helper.getNode('hys');
|
|
66
|
+
const out = helper.getNode('out');
|
|
67
|
+
const results = [];
|
|
68
|
+
|
|
69
|
+
out.on('input', (msg) => {
|
|
70
|
+
results.push(msg.payload);
|
|
71
|
+
if (results.length === 2) {
|
|
72
|
+
try {
|
|
73
|
+
expect(results).to.deep.equal([true, false]);
|
|
74
|
+
done();
|
|
75
|
+
} catch (error) {
|
|
76
|
+
done(error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
hys.receive({ topic: 'sensor', payload: 65 });
|
|
82
|
+
hys.receive({ topic: 'sensor', payload: 72 });
|
|
83
|
+
hys.receive({ topic: 'sensor', payload: 68 });
|
|
84
|
+
hys.receive({ topic: 'sensor', payload: 58 });
|
|
85
|
+
}).catch(done);
|
|
86
|
+
});
|
|
87
|
+
});
|