node-red-contrib-alarm-ultimate 0.1.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/LICENSE +22 -0
- package/README.md +73 -0
- package/examples/README.md +21 -0
- package/examples/alarm-ultimate-basic.json +636 -0
- package/examples/alarm-ultimate-dashboard.json +99 -0
- package/nodes/AlarmSystemUltimate.html +697 -0
- package/nodes/AlarmSystemUltimate.js +1418 -0
- package/nodes/AlarmUltimateSiren.html +94 -0
- package/nodes/AlarmUltimateSiren.js +83 -0
- package/nodes/AlarmUltimateState.html +95 -0
- package/nodes/AlarmUltimateState.js +87 -0
- package/nodes/AlarmUltimateZone.html +130 -0
- package/nodes/AlarmUltimateZone.js +91 -0
- package/nodes/lib/alarm-registry.js +15 -0
- package/nodes/lib/node-helpers.js +96 -0
- package/nodes/utils.js +95 -0
- package/package.json +33 -0
- package/test/alarm-system.spec.js +470 -0
- package/test/helpers.js +28 -0
- package/test/output-nodes.spec.js +155 -0
- package/tools/alarm-json-mapper.html +596 -0
- package/tools/alarm-panel.html +728 -0
package/test/helpers.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const helper = require('node-red-node-test-helper');
|
|
4
|
+
|
|
5
|
+
helper.init(require.resolve('node-red'));
|
|
6
|
+
|
|
7
|
+
function loadNode(nodeDef, flow, credentials = {}) {
|
|
8
|
+
const normalizedFlow = flow.map((node, index) => {
|
|
9
|
+
if (
|
|
10
|
+
node &&
|
|
11
|
+
node.type &&
|
|
12
|
+
node.type !== 'tab' &&
|
|
13
|
+
node.type !== 'subflow' &&
|
|
14
|
+
node.type !== 'group' &&
|
|
15
|
+
node.z &&
|
|
16
|
+
!(Object.prototype.hasOwnProperty.call(node, 'x') && Object.prototype.hasOwnProperty.call(node, 'y'))
|
|
17
|
+
) {
|
|
18
|
+
return { ...node, x: 100 + index * 10, y: 100 + index * 10 };
|
|
19
|
+
}
|
|
20
|
+
return node;
|
|
21
|
+
});
|
|
22
|
+
return helper.load(nodeDef, normalizedFlow, credentials);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
helper,
|
|
27
|
+
loadNode,
|
|
28
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { helper } = require('./helpers');
|
|
4
|
+
|
|
5
|
+
const alarmNode = require('../nodes/AlarmSystemUltimate.js');
|
|
6
|
+
const alarmStateNode = require('../nodes/AlarmUltimateState.js');
|
|
7
|
+
const alarmZoneNode = require('../nodes/AlarmUltimateZone.js');
|
|
8
|
+
const alarmSirenNode = require('../nodes/AlarmUltimateSiren.js');
|
|
9
|
+
|
|
10
|
+
describe('Alarm Ultimate output-only nodes', function () {
|
|
11
|
+
this.timeout(5000);
|
|
12
|
+
|
|
13
|
+
before(function (done) {
|
|
14
|
+
helper.startServer(done);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
after(function (done) {
|
|
18
|
+
helper.stopServer(done);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(function () {
|
|
22
|
+
return helper.unload();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('emits alarm state, zone state and siren state', function (done) {
|
|
26
|
+
const flowId = 'flow1';
|
|
27
|
+
const flow = [
|
|
28
|
+
{ id: flowId, type: 'tab', label: 'flow1' },
|
|
29
|
+
{
|
|
30
|
+
id: 'alarm',
|
|
31
|
+
type: 'AlarmSystemUltimate',
|
|
32
|
+
z: flowId,
|
|
33
|
+
x: 100,
|
|
34
|
+
y: 80,
|
|
35
|
+
controlTopic: 'alarm',
|
|
36
|
+
exitDelaySeconds: 0,
|
|
37
|
+
entryDelaySeconds: 0,
|
|
38
|
+
sirenDurationSeconds: 0.2,
|
|
39
|
+
requireCodeForDisarm: false,
|
|
40
|
+
zones: JSON.stringify([{ id: 'front', topic: 'sensor/frontdoor', type: 'perimeter', entry: false }]),
|
|
41
|
+
wires: [['events'], ['siren'], [], [], [], [], [], [], []],
|
|
42
|
+
},
|
|
43
|
+
{ id: 'events', type: 'helper', z: flowId, x: 280, y: 60 },
|
|
44
|
+
{ id: 'siren', type: 'helper', z: flowId, x: 280, y: 100 },
|
|
45
|
+
{
|
|
46
|
+
id: 'stateNode',
|
|
47
|
+
type: 'AlarmUltimateState',
|
|
48
|
+
z: flowId,
|
|
49
|
+
x: 100,
|
|
50
|
+
y: 160,
|
|
51
|
+
alarmId: 'alarm',
|
|
52
|
+
outputInitialState: true,
|
|
53
|
+
wires: [['stateOut']],
|
|
54
|
+
},
|
|
55
|
+
{ id: 'stateOut', type: 'helper', z: flowId, x: 280, y: 160 },
|
|
56
|
+
{
|
|
57
|
+
id: 'zoneNode',
|
|
58
|
+
type: 'AlarmUltimateZone',
|
|
59
|
+
z: flowId,
|
|
60
|
+
x: 100,
|
|
61
|
+
y: 220,
|
|
62
|
+
alarmId: 'alarm',
|
|
63
|
+
zoneId: 'front',
|
|
64
|
+
outputInitialState: true,
|
|
65
|
+
wires: [['zoneOut']],
|
|
66
|
+
},
|
|
67
|
+
{ id: 'zoneOut', type: 'helper', z: flowId, x: 280, y: 220 },
|
|
68
|
+
{
|
|
69
|
+
id: 'sirenNode',
|
|
70
|
+
type: 'AlarmUltimateSiren',
|
|
71
|
+
z: flowId,
|
|
72
|
+
x: 100,
|
|
73
|
+
y: 280,
|
|
74
|
+
alarmId: 'alarm',
|
|
75
|
+
outputInitialState: true,
|
|
76
|
+
wires: [['sirenOut']],
|
|
77
|
+
},
|
|
78
|
+
{ id: 'sirenOut', type: 'helper', z: flowId, x: 280, y: 280 },
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
helper
|
|
82
|
+
.load([alarmNode, alarmStateNode, alarmZoneNode, alarmSirenNode], flow, {})
|
|
83
|
+
.then(() => {
|
|
84
|
+
const alarm = helper.getNode('alarm');
|
|
85
|
+
const stateOut = helper.getNode('stateOut');
|
|
86
|
+
const zoneOut = helper.getNode('zoneOut');
|
|
87
|
+
const sirenOut = helper.getNode('sirenOut');
|
|
88
|
+
|
|
89
|
+
const seen = {
|
|
90
|
+
initialDisarmed: false,
|
|
91
|
+
initialZoneClosed: false,
|
|
92
|
+
initialSirenOff: false,
|
|
93
|
+
armed: false,
|
|
94
|
+
zoneOpen: false,
|
|
95
|
+
sirenOn: false,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
function maybeDone() {
|
|
99
|
+
if (Object.values(seen).every(Boolean)) {
|
|
100
|
+
done();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
stateOut.on('input', (msg) => {
|
|
105
|
+
try {
|
|
106
|
+
if (String(msg.reason || '').startsWith('init') && msg.payload === 'disarmed') {
|
|
107
|
+
seen.initialDisarmed = true;
|
|
108
|
+
}
|
|
109
|
+
if (msg.payload === 'armed') {
|
|
110
|
+
seen.armed = true;
|
|
111
|
+
}
|
|
112
|
+
maybeDone();
|
|
113
|
+
} catch (err) {
|
|
114
|
+
done(err);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
zoneOut.on('input', (msg) => {
|
|
119
|
+
try {
|
|
120
|
+
if (String(msg.reason || '').startsWith('init') && msg.payload === false) {
|
|
121
|
+
seen.initialZoneClosed = true;
|
|
122
|
+
}
|
|
123
|
+
if (msg.payload === true && msg.zone && msg.zone.id === 'front') {
|
|
124
|
+
seen.zoneOpen = true;
|
|
125
|
+
}
|
|
126
|
+
maybeDone();
|
|
127
|
+
} catch (err) {
|
|
128
|
+
done(err);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
sirenOut.on('input', (msg) => {
|
|
133
|
+
try {
|
|
134
|
+
if (String(msg.reason || '').startsWith('init') && msg.payload === false) {
|
|
135
|
+
seen.initialSirenOff = true;
|
|
136
|
+
}
|
|
137
|
+
if (msg.payload === true) {
|
|
138
|
+
seen.sirenOn = true;
|
|
139
|
+
}
|
|
140
|
+
maybeDone();
|
|
141
|
+
} catch (err) {
|
|
142
|
+
done(err);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
setTimeout(() => {
|
|
147
|
+
alarm.receive({ topic: 'alarm', command: 'arm' });
|
|
148
|
+
setTimeout(() => {
|
|
149
|
+
alarm.receive({ topic: 'sensor/frontdoor', payload: true });
|
|
150
|
+
}, 30);
|
|
151
|
+
}, 50);
|
|
152
|
+
})
|
|
153
|
+
.catch(done);
|
|
154
|
+
});
|
|
155
|
+
});
|