homebridge-securitysystem 6.4.0 → 6.5.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/.eslintrc.js +14 -288
- package/config.schema.json +33 -2
- package/package.json +1 -1
- package/src/index.js +782 -427
- package/src/utils/options.js +9 -8
package/src/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
const fs = require(
|
|
2
|
-
const path = require(
|
|
3
|
-
const storage = require(
|
|
4
|
-
const { spawn } = require(
|
|
5
|
-
const fetch = require(
|
|
6
|
-
const express = require(
|
|
7
|
-
const rateLimit = require(
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const storage = require("node-persist");
|
|
4
|
+
const { spawn } = require("child_process");
|
|
5
|
+
const fetch = require("node-fetch");
|
|
6
|
+
const express = require("express");
|
|
7
|
+
const rateLimit = require("express-rate-limit");
|
|
8
8
|
|
|
9
|
-
const packageJson = require(
|
|
10
|
-
const options = require(
|
|
9
|
+
const packageJson = require("../package.json");
|
|
10
|
+
const options = require("./utils/options.js");
|
|
11
11
|
|
|
12
12
|
const originTypes = {
|
|
13
13
|
REGULAR_SWITCH: 0,
|
|
14
14
|
SPECIAL_SWITCH: 1,
|
|
15
15
|
INTERNAL: 3,
|
|
16
|
-
EXTERNAL: 4
|
|
16
|
+
EXTERNAL: 4,
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const app = express();
|
|
@@ -24,7 +24,11 @@ module.exports = function (homebridge) {
|
|
|
24
24
|
Characteristic = homebridge.hap.Characteristic;
|
|
25
25
|
storagePath = homebridge.user.storagePath();
|
|
26
26
|
|
|
27
|
-
homebridge.registerAccessory(
|
|
27
|
+
homebridge.registerAccessory(
|
|
28
|
+
"homebridge-securitysystem",
|
|
29
|
+
"security-system",
|
|
30
|
+
SecuritySystem
|
|
31
|
+
);
|
|
28
32
|
};
|
|
29
33
|
|
|
30
34
|
function SecuritySystem(log, config) {
|
|
@@ -59,64 +63,68 @@ function SecuritySystem(log, config) {
|
|
|
59
63
|
const logWarn = this.log.warn.bind(this.log);
|
|
60
64
|
const logError = this.log.error.bind(this.log);
|
|
61
65
|
|
|
62
|
-
this.log.info = message => {
|
|
66
|
+
this.log.info = (message) => {
|
|
63
67
|
logInfo.apply(null, [message]);
|
|
64
68
|
this.log.appendFile(message);
|
|
65
69
|
};
|
|
66
70
|
|
|
67
|
-
this.log.warn = message => {
|
|
71
|
+
this.log.warn = (message) => {
|
|
68
72
|
logWarn.apply(null, [message]);
|
|
69
73
|
this.log.appendFile(message);
|
|
70
74
|
};
|
|
71
75
|
|
|
72
|
-
this.log.error = message => {
|
|
76
|
+
this.log.error = (message) => {
|
|
73
77
|
logError.apply(null, [message]);
|
|
74
78
|
this.log.appendFile(message);
|
|
75
79
|
};
|
|
76
80
|
|
|
77
|
-
this.log.appendFile = async message => {
|
|
81
|
+
this.log.appendFile = async (message) => {
|
|
78
82
|
const date = new Date();
|
|
79
83
|
|
|
80
84
|
try {
|
|
81
|
-
const stats = await fs.promises.stat(
|
|
85
|
+
const stats = await fs.promises.stat(
|
|
86
|
+
`${options.logDirectory}/securitysystem.log`
|
|
87
|
+
);
|
|
82
88
|
|
|
83
|
-
if (
|
|
89
|
+
if (
|
|
90
|
+
stats.birthtime.toLocaleDateString() !== date.toLocaleDateString()
|
|
91
|
+
) {
|
|
84
92
|
await fs.promises.rename(
|
|
85
93
|
`${options.logDirectory}/securitysystem.log`,
|
|
86
|
-
`${options.logDirectory}/securitysystem-${stats.birthtime
|
|
94
|
+
`${options.logDirectory}/securitysystem-${stats.birthtime
|
|
95
|
+
.toLocaleDateString()
|
|
96
|
+
.replaceAll("/", "-")}.log`
|
|
87
97
|
);
|
|
88
98
|
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
this.log.debug('Previous log file not found.');
|
|
99
|
+
} catch (error) {
|
|
100
|
+
this.log.debug("Previous log file not found.");
|
|
92
101
|
}
|
|
93
102
|
|
|
94
103
|
try {
|
|
95
104
|
await fs.promises.appendFile(
|
|
96
105
|
`${options.logDirectory}/securitysystem.log`,
|
|
97
106
|
`[${new Date().toLocaleString()}] ${message}\n`,
|
|
98
|
-
{ flag:
|
|
107
|
+
{ flag: "a" }
|
|
99
108
|
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
logError('File logger (Error)');
|
|
109
|
+
} catch (error) {
|
|
110
|
+
logError("File logger (Error)");
|
|
103
111
|
logError(error);
|
|
104
112
|
}
|
|
105
|
-
}
|
|
113
|
+
};
|
|
106
114
|
}
|
|
107
115
|
|
|
108
116
|
// Log
|
|
109
117
|
if (options.testMode) {
|
|
110
|
-
this.log.warn(
|
|
118
|
+
this.log.warn("Test Mode");
|
|
111
119
|
}
|
|
112
120
|
|
|
113
|
-
this.logMode(
|
|
121
|
+
this.logMode("Default", this.defaultState);
|
|
114
122
|
this.log.info(`Arm delay (${options.armSeconds} second/s)`);
|
|
115
123
|
this.log.info(`Trigger delay (${options.triggerSeconds} second/s)`);
|
|
116
|
-
this.log.info(`Audio (${
|
|
124
|
+
this.log.info(`Audio (${options.audio ? "Enabled" : "Disabled"})`);
|
|
117
125
|
|
|
118
126
|
if (options.proxyMode) {
|
|
119
|
-
this.log.info(
|
|
127
|
+
this.log.info("Proxy mode (Enabled)");
|
|
120
128
|
}
|
|
121
129
|
|
|
122
130
|
if (options.isValueSet(options.webhookUrl)) {
|
|
@@ -127,176 +135,224 @@ function SecuritySystem(log, config) {
|
|
|
127
135
|
this.service = new Service.SecuritySystem(options.name);
|
|
128
136
|
this.availableTargetStates = this.getAvailableTargetStates();
|
|
129
137
|
|
|
130
|
-
this.service
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
this.service.getCharacteristic(
|
|
139
|
+
Characteristic.SecuritySystemTargetState
|
|
140
|
+
).value = this.targetState;
|
|
133
141
|
|
|
134
142
|
this.service
|
|
135
143
|
.getCharacteristic(Characteristic.SecuritySystemTargetState)
|
|
136
144
|
.setProps({ validValues: this.availableTargetStates })
|
|
137
|
-
.on(
|
|
138
|
-
.on(
|
|
145
|
+
.on("get", this.getTargetState.bind(this))
|
|
146
|
+
.on("set", this.setTargetState.bind(this));
|
|
139
147
|
|
|
140
|
-
this.service
|
|
141
|
-
|
|
142
|
-
|
|
148
|
+
this.service.getCharacteristic(
|
|
149
|
+
Characteristic.SecuritySystemCurrentState
|
|
150
|
+
).value = this.currentState;
|
|
143
151
|
|
|
144
152
|
this.service
|
|
145
153
|
.getCharacteristic(Characteristic.SecuritySystemCurrentState)
|
|
146
|
-
.on(
|
|
154
|
+
.on("get", this.getCurrentState.bind(this));
|
|
147
155
|
|
|
148
156
|
// Siren switches
|
|
149
|
-
this.sirenSwitchService = new Service.Switch(
|
|
157
|
+
this.sirenSwitchService = new Service.Switch("Siren", "siren-switch");
|
|
150
158
|
|
|
151
159
|
this.sirenSwitchService
|
|
152
160
|
.getCharacteristic(Characteristic.On)
|
|
153
|
-
.on(
|
|
154
|
-
.on(
|
|
161
|
+
.on("get", this.getSirenSwitch.bind(this))
|
|
162
|
+
.on("set", this.setSirenSwitch.bind(this));
|
|
155
163
|
|
|
156
|
-
this.sirenOverrideSwitchService = new Service.Switch(
|
|
164
|
+
this.sirenOverrideSwitchService = new Service.Switch(
|
|
165
|
+
"Siren Override",
|
|
166
|
+
"BdW9ce0mUYatqiRqEjT4iA"
|
|
167
|
+
);
|
|
157
168
|
|
|
158
169
|
this.sirenOverrideSwitchService
|
|
159
170
|
.getCharacteristic(Characteristic.On)
|
|
160
|
-
.on(
|
|
161
|
-
.on(
|
|
171
|
+
.on("get", this.getSirenOverrideSwitch.bind(this))
|
|
172
|
+
.on("set", this.setSirenOverrideSwitch.bind(this));
|
|
162
173
|
|
|
163
|
-
this.sirenHomeSwitchService = new Service.Switch(
|
|
174
|
+
this.sirenHomeSwitchService = new Service.Switch("Siren Home", "siren-home");
|
|
164
175
|
|
|
165
176
|
this.sirenHomeSwitchService
|
|
166
177
|
.getCharacteristic(Characteristic.On)
|
|
167
|
-
.on(
|
|
168
|
-
.on(
|
|
178
|
+
.on("get", this.getSirenHomeSwitch.bind(this))
|
|
179
|
+
.on("set", this.setSirenHomeSwitch.bind(this));
|
|
169
180
|
|
|
170
|
-
this.sirenAwaySwitchService = new Service.Switch(
|
|
181
|
+
this.sirenAwaySwitchService = new Service.Switch("Siren Away", "siren-away");
|
|
171
182
|
|
|
172
183
|
this.sirenAwaySwitchService
|
|
173
184
|
.getCharacteristic(Characteristic.On)
|
|
174
|
-
.on(
|
|
175
|
-
.on(
|
|
185
|
+
.on("get", this.getSirenAwaySwitch.bind(this))
|
|
186
|
+
.on("set", this.setSirenAwaySwitch.bind(this));
|
|
176
187
|
|
|
177
|
-
this.sirenNightSwitchService = new Service.Switch(
|
|
188
|
+
this.sirenNightSwitchService = new Service.Switch(
|
|
189
|
+
"Siren Night",
|
|
190
|
+
"siren-night"
|
|
191
|
+
);
|
|
178
192
|
|
|
179
193
|
this.sirenNightSwitchService
|
|
180
194
|
.getCharacteristic(Characteristic.On)
|
|
181
|
-
.on(
|
|
182
|
-
.on(
|
|
195
|
+
.on("get", this.getSirenNightSwitch.bind(this))
|
|
196
|
+
.on("set", this.setSirenNightSwitch.bind(this));
|
|
183
197
|
|
|
184
198
|
// Arming lock switches
|
|
185
|
-
this.armingLockSwitchService = new Service.Switch(
|
|
199
|
+
this.armingLockSwitchService = new Service.Switch(
|
|
200
|
+
"Arming Lock",
|
|
201
|
+
"arming-lock"
|
|
202
|
+
);
|
|
186
203
|
|
|
187
204
|
this.armingLockSwitchService
|
|
188
205
|
.getCharacteristic(Characteristic.On)
|
|
189
|
-
.on(
|
|
190
|
-
.on(
|
|
206
|
+
.on("get", this.getArmingLockSwitch.bind(this))
|
|
207
|
+
.on("set", this.setArmingLockSwitch.bind(this));
|
|
191
208
|
|
|
192
|
-
this.armingLockHomeSwitchService = new Service.Switch(
|
|
209
|
+
this.armingLockHomeSwitchService = new Service.Switch(
|
|
210
|
+
"Arming Lock Home",
|
|
211
|
+
"arming-lock-home"
|
|
212
|
+
);
|
|
193
213
|
|
|
194
214
|
this.armingLockHomeSwitchService
|
|
195
215
|
.getCharacteristic(Characteristic.On)
|
|
196
|
-
.on(
|
|
197
|
-
.on(
|
|
216
|
+
.on("get", this.getArmingLockHomeSwitch.bind(this))
|
|
217
|
+
.on("set", this.setArmingLockHomeSwitch.bind(this));
|
|
198
218
|
|
|
199
|
-
this.armingLockAwaySwitchService = new Service.Switch(
|
|
219
|
+
this.armingLockAwaySwitchService = new Service.Switch(
|
|
220
|
+
"Arming Lock Away",
|
|
221
|
+
"arming-lock-away"
|
|
222
|
+
);
|
|
200
223
|
|
|
201
224
|
this.armingLockAwaySwitchService
|
|
202
225
|
.getCharacteristic(Characteristic.On)
|
|
203
|
-
.on(
|
|
204
|
-
.on(
|
|
226
|
+
.on("get", this.getArmingLockAwaySwitch.bind(this))
|
|
227
|
+
.on("set", this.setArmingLockAwaySwitch.bind(this));
|
|
205
228
|
|
|
206
|
-
this.armingLockNightSwitchService = new Service.Switch(
|
|
229
|
+
this.armingLockNightSwitchService = new Service.Switch(
|
|
230
|
+
"Arming Lock Night",
|
|
231
|
+
"arming-lock-night"
|
|
232
|
+
);
|
|
207
233
|
|
|
208
234
|
this.armingLockNightSwitchService
|
|
209
235
|
.getCharacteristic(Characteristic.On)
|
|
210
|
-
.on(
|
|
211
|
-
.on(
|
|
236
|
+
.on("get", this.getArmingLockNightSwitch.bind(this))
|
|
237
|
+
.on("set", this.setArmingLockNightSwitch.bind(this));
|
|
212
238
|
|
|
213
239
|
// Mode switches
|
|
214
|
-
this.modeHomeSwitchService = new Service.Switch(
|
|
240
|
+
this.modeHomeSwitchService = new Service.Switch("Mode Home", "mode-home");
|
|
215
241
|
|
|
216
242
|
this.modeHomeSwitchService
|
|
217
243
|
.getCharacteristic(Characteristic.On)
|
|
218
|
-
.on(
|
|
219
|
-
.on(
|
|
244
|
+
.on("get", this.getModeHomeSwitch.bind(this))
|
|
245
|
+
.on("set", this.setModeHomeSwitch.bind(this));
|
|
220
246
|
|
|
221
|
-
this.modeAwaySwitchService = new Service.Switch(
|
|
247
|
+
this.modeAwaySwitchService = new Service.Switch("Mode Away", "mode-away");
|
|
222
248
|
|
|
223
249
|
this.modeAwaySwitchService
|
|
224
250
|
.getCharacteristic(Characteristic.On)
|
|
225
|
-
.on(
|
|
226
|
-
.on(
|
|
251
|
+
.on("get", this.getModeAwaySwitch.bind(this))
|
|
252
|
+
.on("set", this.setModeAwaySwitch.bind(this));
|
|
227
253
|
|
|
228
|
-
this.modeNightSwitchService = new Service.Switch(
|
|
254
|
+
this.modeNightSwitchService = new Service.Switch("Mode Night", "mode-night");
|
|
229
255
|
|
|
230
256
|
this.modeNightSwitchService
|
|
231
257
|
.getCharacteristic(Characteristic.On)
|
|
232
|
-
.on(
|
|
233
|
-
.on(
|
|
258
|
+
.on("get", this.getModeNightSwitch.bind(this))
|
|
259
|
+
.on("set", this.setModeNightSwitch.bind(this));
|
|
234
260
|
|
|
235
|
-
this.modeOffSwitchService = new Service.Switch(
|
|
261
|
+
this.modeOffSwitchService = new Service.Switch("Mode Off", "mode-off");
|
|
236
262
|
|
|
237
263
|
this.modeOffSwitchService
|
|
238
264
|
.getCharacteristic(Characteristic.On)
|
|
239
|
-
.on(
|
|
240
|
-
.on(
|
|
265
|
+
.on("get", this.getModeOffSwitch.bind(this))
|
|
266
|
+
.on("set", this.setModeOffSwitch.bind(this));
|
|
241
267
|
|
|
242
|
-
this.modeAwayExtendedSwitchService = new Service.Switch(
|
|
268
|
+
this.modeAwayExtendedSwitchService = new Service.Switch(
|
|
269
|
+
"Mode Away Extended",
|
|
270
|
+
"mode-away-extended"
|
|
271
|
+
);
|
|
243
272
|
|
|
244
273
|
this.modeAwayExtendedSwitchService
|
|
245
274
|
.getCharacteristic(Characteristic.On)
|
|
246
|
-
.on(
|
|
247
|
-
.on(
|
|
275
|
+
.on("get", this.getModeAwayExtendedSwitch.bind(this))
|
|
276
|
+
.on("set", this.setModeAwayExtendedSwitch.bind(this));
|
|
248
277
|
|
|
249
|
-
this.modePauseSwitchService = new Service.Switch(
|
|
278
|
+
this.modePauseSwitchService = new Service.Switch("Mode Pause", "mode-pause");
|
|
250
279
|
|
|
251
280
|
this.modePauseSwitchService
|
|
252
281
|
.getCharacteristic(Characteristic.On)
|
|
253
|
-
.on(
|
|
254
|
-
.on(
|
|
282
|
+
.on("get", this.getModePauseSwitch.bind(this))
|
|
283
|
+
.on("set", this.setModePauseSwitch.bind(this));
|
|
255
284
|
|
|
256
285
|
// Audio switch
|
|
257
|
-
this.audioSwitchService = new Service.Switch(
|
|
286
|
+
this.audioSwitchService = new Service.Switch(
|
|
287
|
+
"Audio",
|
|
288
|
+
"kx82r64zN3txDXKFiX9JDi"
|
|
289
|
+
);
|
|
258
290
|
|
|
259
291
|
this.audioSwitchService
|
|
260
292
|
.getCharacteristic(Characteristic.On)
|
|
261
|
-
.on(
|
|
262
|
-
.on(
|
|
293
|
+
.on("get", this.getAudioSwitch.bind(this))
|
|
294
|
+
.on("set", this.setAudioSwitch.bind(this));
|
|
263
295
|
|
|
264
296
|
this.audioSwitchService.getCharacteristic(Characteristic.On).value = true;
|
|
265
297
|
|
|
266
298
|
// Siren sensors
|
|
267
|
-
this.sirenTrippedMotionSensorService = new Service.MotionSensor(
|
|
299
|
+
this.sirenTrippedMotionSensorService = new Service.MotionSensor(
|
|
300
|
+
"Siren Tripped",
|
|
301
|
+
"siren-tripped"
|
|
302
|
+
);
|
|
268
303
|
|
|
269
304
|
this.sirenTrippedMotionSensorService
|
|
270
305
|
.getCharacteristic(Characteristic.MotionDetected)
|
|
271
|
-
.on(
|
|
306
|
+
.on("get", this.getSirenTrippedMotionDetected.bind(this));
|
|
272
307
|
|
|
273
|
-
this.sirenTriggeredMotionSensorService = new Service.MotionSensor(
|
|
308
|
+
this.sirenTriggeredMotionSensorService = new Service.MotionSensor(
|
|
309
|
+
"Siren Triggered",
|
|
310
|
+
"siren-triggered"
|
|
311
|
+
);
|
|
274
312
|
|
|
275
313
|
this.sirenTriggeredMotionSensorService
|
|
276
314
|
.getCharacteristic(Characteristic.MotionDetected)
|
|
277
|
-
.on(
|
|
315
|
+
.on("get", this.getSirenTriggeredMotionDetected.bind(this));
|
|
278
316
|
|
|
279
|
-
this.sirenResetMotionSensorService = new Service.MotionSensor(
|
|
317
|
+
this.sirenResetMotionSensorService = new Service.MotionSensor(
|
|
318
|
+
"Siren Reset",
|
|
319
|
+
"reset-event"
|
|
320
|
+
);
|
|
280
321
|
|
|
281
322
|
this.sirenResetMotionSensorService
|
|
282
323
|
.getCharacteristic(Characteristic.MotionDetected)
|
|
283
|
-
.on(
|
|
324
|
+
.on("get", this.getSirenResetMotionDetected.bind(this));
|
|
284
325
|
|
|
285
326
|
// Accessory information
|
|
286
327
|
this.accessoryInformationService = new Service.AccessoryInformation();
|
|
287
328
|
|
|
288
|
-
this.accessoryInformationService.setCharacteristic(
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
this.accessoryInformationService.setCharacteristic(
|
|
293
|
-
|
|
329
|
+
this.accessoryInformationService.setCharacteristic(
|
|
330
|
+
Characteristic.Identify,
|
|
331
|
+
true
|
|
332
|
+
);
|
|
333
|
+
this.accessoryInformationService.setCharacteristic(
|
|
334
|
+
Characteristic.Manufacturer,
|
|
335
|
+
"MiguelRipoll23"
|
|
336
|
+
);
|
|
337
|
+
this.accessoryInformationService.setCharacteristic(
|
|
338
|
+
Characteristic.Model,
|
|
339
|
+
"DIY"
|
|
340
|
+
);
|
|
341
|
+
this.accessoryInformationService.setCharacteristic(
|
|
342
|
+
Characteristic.Name,
|
|
343
|
+
"homebridge-securitysystem"
|
|
344
|
+
);
|
|
345
|
+
this.accessoryInformationService.setCharacteristic(
|
|
346
|
+
Characteristic.SerialNumber,
|
|
347
|
+
"S3CUR1TYSYST3M"
|
|
348
|
+
);
|
|
349
|
+
this.accessoryInformationService.setCharacteristic(
|
|
350
|
+
Characteristic.FirmwareRevision,
|
|
351
|
+
packageJson.version
|
|
352
|
+
);
|
|
294
353
|
|
|
295
354
|
// Services list
|
|
296
|
-
this.services = [
|
|
297
|
-
this.service,
|
|
298
|
-
this.accessoryInformationService
|
|
299
|
-
];
|
|
355
|
+
this.services = [this.service, this.accessoryInformationService];
|
|
300
356
|
|
|
301
357
|
if (options.trippedSensor) {
|
|
302
358
|
this.services.push(this.sirenTrippedMotionSensorService);
|
|
@@ -328,7 +384,11 @@ function SecuritySystem(log, config) {
|
|
|
328
384
|
this.services.push(this.sirenOverrideSwitchService);
|
|
329
385
|
}
|
|
330
386
|
|
|
331
|
-
if (
|
|
387
|
+
if (
|
|
388
|
+
this.availableTargetStates.includes(
|
|
389
|
+
Characteristic.SecuritySystemTargetState.STAY_ARM
|
|
390
|
+
)
|
|
391
|
+
) {
|
|
332
392
|
if (options.modeSwitches) {
|
|
333
393
|
this.services.push(this.modeHomeSwitchService);
|
|
334
394
|
}
|
|
@@ -338,7 +398,11 @@ function SecuritySystem(log, config) {
|
|
|
338
398
|
}
|
|
339
399
|
}
|
|
340
400
|
|
|
341
|
-
if (
|
|
401
|
+
if (
|
|
402
|
+
this.availableTargetStates.includes(
|
|
403
|
+
Characteristic.SecuritySystemTargetState.AWAY_ARM
|
|
404
|
+
)
|
|
405
|
+
) {
|
|
342
406
|
if (options.modeSwitches) {
|
|
343
407
|
this.services.push(this.modeAwaySwitchService);
|
|
344
408
|
}
|
|
@@ -348,7 +412,11 @@ function SecuritySystem(log, config) {
|
|
|
348
412
|
}
|
|
349
413
|
}
|
|
350
414
|
|
|
351
|
-
if (
|
|
415
|
+
if (
|
|
416
|
+
this.availableTargetStates.includes(
|
|
417
|
+
Characteristic.SecuritySystemTargetState.NIGHT_ARM
|
|
418
|
+
)
|
|
419
|
+
) {
|
|
352
420
|
if (options.modeSwitches) {
|
|
353
421
|
this.services.push(this.modeNightSwitchService);
|
|
354
422
|
}
|
|
@@ -396,55 +464,69 @@ SecuritySystem.prototype.getServices = function () {
|
|
|
396
464
|
|
|
397
465
|
SecuritySystem.prototype.load = async function () {
|
|
398
466
|
const storageOptions = {
|
|
399
|
-
|
|
467
|
+
dir: path.join(storagePath, "homebridge-securitysystem"),
|
|
400
468
|
};
|
|
401
469
|
|
|
402
|
-
await storage
|
|
470
|
+
await storage
|
|
471
|
+
.init(storageOptions)
|
|
403
472
|
.then()
|
|
404
|
-
.catch(error => {
|
|
405
|
-
this.log.error(
|
|
473
|
+
.catch((error) => {
|
|
474
|
+
this.log.error("Unable to load state.");
|
|
406
475
|
this.log.error(error);
|
|
407
476
|
});
|
|
408
477
|
|
|
409
478
|
if (options.testMode) {
|
|
410
479
|
await storage.clear();
|
|
411
|
-
this.log.debug(
|
|
480
|
+
this.log.debug("Saved data from the plugin cleared.");
|
|
412
481
|
|
|
413
482
|
return;
|
|
414
483
|
}
|
|
415
484
|
|
|
416
|
-
await storage
|
|
417
|
-
.
|
|
485
|
+
await storage
|
|
486
|
+
.getItem("state")
|
|
487
|
+
.then((state) => {
|
|
418
488
|
if (state === undefined) {
|
|
419
489
|
return;
|
|
420
490
|
}
|
|
421
491
|
|
|
422
|
-
this.log.debug(
|
|
423
|
-
this.log.info(
|
|
492
|
+
this.log.debug("State (Loaded)", state);
|
|
493
|
+
this.log.info("Saved state (Found)");
|
|
424
494
|
|
|
425
|
-
const currentState = options.isValueSet(state.currentState)
|
|
426
|
-
|
|
495
|
+
const currentState = options.isValueSet(state.currentState)
|
|
496
|
+
? state.currentState
|
|
497
|
+
: this.defaultState;
|
|
498
|
+
const targetState = options.isValueSet(state.targetState)
|
|
499
|
+
? state.targetState
|
|
500
|
+
: this.defaultState;
|
|
427
501
|
|
|
428
502
|
// Change target state if triggered
|
|
429
|
-
if (
|
|
503
|
+
if (
|
|
504
|
+
currentState ===
|
|
505
|
+
Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED
|
|
506
|
+
) {
|
|
430
507
|
this.targetState = targetState;
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
508
|
+
} else {
|
|
433
509
|
this.targetState = currentState;
|
|
434
510
|
}
|
|
435
511
|
|
|
436
512
|
this.currentState = currentState;
|
|
437
513
|
|
|
438
514
|
// Update characteristics values
|
|
439
|
-
this.service.updateCharacteristic(
|
|
440
|
-
|
|
515
|
+
this.service.updateCharacteristic(
|
|
516
|
+
Characteristic.SecuritySystemTargetState,
|
|
517
|
+
this.targetState
|
|
518
|
+
);
|
|
519
|
+
this.service.updateCharacteristic(
|
|
520
|
+
Characteristic.SecuritySystemCurrentState,
|
|
521
|
+
this.currentState
|
|
522
|
+
);
|
|
441
523
|
this.handleStateUpdate(false);
|
|
442
524
|
|
|
443
525
|
// Log
|
|
444
|
-
this.logMode(
|
|
526
|
+
this.logMode("Current", this.currentState);
|
|
445
527
|
})
|
|
446
|
-
.catch(error => {
|
|
447
|
-
this.log.error(
|
|
528
|
+
.catch((error) => {
|
|
529
|
+
this.log.error("Saved state (Error)");
|
|
448
530
|
this.log.error(error);
|
|
449
531
|
});
|
|
450
532
|
};
|
|
@@ -456,27 +538,28 @@ SecuritySystem.prototype.save = async function () {
|
|
|
456
538
|
}
|
|
457
539
|
|
|
458
540
|
if (storage.defaultInstance === undefined) {
|
|
459
|
-
this.log.error(
|
|
541
|
+
this.log.error("Unable to save state.");
|
|
460
542
|
return;
|
|
461
543
|
}
|
|
462
544
|
|
|
463
545
|
const state = {
|
|
464
|
-
|
|
465
|
-
|
|
546
|
+
currentState: this.currentState,
|
|
547
|
+
targetState: this.targetState,
|
|
466
548
|
};
|
|
467
549
|
|
|
468
|
-
await storage
|
|
550
|
+
await storage
|
|
551
|
+
.setItem("state", state)
|
|
469
552
|
.then(() => {
|
|
470
|
-
this.log.debug(
|
|
553
|
+
this.log.debug("State (Saved)", state);
|
|
471
554
|
})
|
|
472
|
-
.catch(error => {
|
|
473
|
-
this.log.error(
|
|
555
|
+
.catch((error) => {
|
|
556
|
+
this.log.error("Unable to save state.");
|
|
474
557
|
this.log.error(error);
|
|
475
558
|
});
|
|
476
559
|
};
|
|
477
560
|
|
|
478
561
|
SecuritySystem.prototype.identify = function (callback) {
|
|
479
|
-
this.log.info(
|
|
562
|
+
this.log.info("Identify");
|
|
480
563
|
callback(null);
|
|
481
564
|
};
|
|
482
565
|
|
|
@@ -484,46 +567,46 @@ SecuritySystem.prototype.identify = function (callback) {
|
|
|
484
567
|
SecuritySystem.prototype.state2Mode = function (state) {
|
|
485
568
|
switch (state) {
|
|
486
569
|
case Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED:
|
|
487
|
-
return
|
|
570
|
+
return "triggered";
|
|
488
571
|
|
|
489
572
|
case Characteristic.SecuritySystemCurrentState.STAY_ARM:
|
|
490
|
-
return
|
|
573
|
+
return "home";
|
|
491
574
|
|
|
492
575
|
case Characteristic.SecuritySystemCurrentState.AWAY_ARM:
|
|
493
|
-
return
|
|
576
|
+
return "away";
|
|
494
577
|
|
|
495
578
|
case Characteristic.SecuritySystemCurrentState.NIGHT_ARM:
|
|
496
|
-
return
|
|
579
|
+
return "night";
|
|
497
580
|
|
|
498
581
|
case Characteristic.SecuritySystemCurrentState.DISARMED:
|
|
499
|
-
return
|
|
582
|
+
return "off";
|
|
500
583
|
|
|
501
584
|
// Custom
|
|
502
|
-
case
|
|
585
|
+
case "lock":
|
|
503
586
|
// Audio sound
|
|
504
587
|
return state;
|
|
505
588
|
|
|
506
|
-
case
|
|
589
|
+
case "warning":
|
|
507
590
|
return state;
|
|
508
591
|
|
|
509
592
|
default:
|
|
510
593
|
this.log.error(`Unknown state (${state}).`);
|
|
511
|
-
return
|
|
594
|
+
return "unknown";
|
|
512
595
|
}
|
|
513
596
|
};
|
|
514
597
|
|
|
515
598
|
SecuritySystem.prototype.mode2State = function (mode) {
|
|
516
599
|
switch (mode) {
|
|
517
|
-
case
|
|
600
|
+
case "home":
|
|
518
601
|
return Characteristic.SecuritySystemCurrentState.STAY_ARM;
|
|
519
602
|
|
|
520
|
-
case
|
|
603
|
+
case "away":
|
|
521
604
|
return Characteristic.SecuritySystemCurrentState.AWAY_ARM;
|
|
522
605
|
|
|
523
|
-
case
|
|
606
|
+
case "night":
|
|
524
607
|
return Characteristic.SecuritySystemCurrentState.NIGHT_ARM;
|
|
525
608
|
|
|
526
|
-
case
|
|
609
|
+
case "off":
|
|
527
610
|
return Characteristic.SecuritySystemCurrentState.DISARMED;
|
|
528
611
|
|
|
529
612
|
default:
|
|
@@ -540,13 +623,15 @@ SecuritySystem.prototype.logMode = function (type, state) {
|
|
|
540
623
|
};
|
|
541
624
|
|
|
542
625
|
SecuritySystem.prototype.getAvailableTargetStates = function () {
|
|
543
|
-
const targetStateCharacteristic = this.service.getCharacteristic(
|
|
626
|
+
const targetStateCharacteristic = this.service.getCharacteristic(
|
|
627
|
+
Characteristic.SecuritySystemTargetState
|
|
628
|
+
);
|
|
544
629
|
const validValues = targetStateCharacteristic.props.validValues;
|
|
545
|
-
const invalidValues = options.disabledModes.map(value => {
|
|
630
|
+
const invalidValues = options.disabledModes.map((value) => {
|
|
546
631
|
return this.mode2State(value.toLowerCase());
|
|
547
632
|
});
|
|
548
633
|
|
|
549
|
-
return validValues.filter(state => invalidValues.includes(state) === false);
|
|
634
|
+
return validValues.filter((state) => invalidValues.includes(state) === false);
|
|
550
635
|
};
|
|
551
636
|
|
|
552
637
|
SecuritySystem.prototype.getCurrentState = function (callback) {
|
|
@@ -560,17 +645,20 @@ SecuritySystem.prototype.setCurrentState = function (state, origin) {
|
|
|
560
645
|
}
|
|
561
646
|
|
|
562
647
|
this.currentState = state;
|
|
563
|
-
this.service.setCharacteristic(
|
|
564
|
-
|
|
648
|
+
this.service.setCharacteristic(
|
|
649
|
+
Characteristic.SecuritySystemCurrentState,
|
|
650
|
+
state
|
|
651
|
+
);
|
|
652
|
+
this.logMode("Current", state);
|
|
565
653
|
|
|
566
654
|
// Audio
|
|
567
|
-
this.playAudio(
|
|
655
|
+
this.playAudio("current", state);
|
|
568
656
|
|
|
569
657
|
// Commands
|
|
570
|
-
this.executeCommand(
|
|
658
|
+
this.executeCommand("current", state, origin);
|
|
571
659
|
|
|
572
660
|
// Webhooks
|
|
573
|
-
this.sendWebhookEvent(
|
|
661
|
+
this.sendWebhookEvent("current", state, origin);
|
|
574
662
|
|
|
575
663
|
if (state === Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED) {
|
|
576
664
|
// Update siren triggered sensor
|
|
@@ -582,22 +670,38 @@ SecuritySystem.prototype.setCurrentState = function (state, origin) {
|
|
|
582
670
|
// when time runs out
|
|
583
671
|
this.resetTimeout = setTimeout(() => {
|
|
584
672
|
this.resetTimeout = null;
|
|
585
|
-
this.log.info(
|
|
673
|
+
this.log.info("Reset (Finished)");
|
|
586
674
|
|
|
587
675
|
// Update reset sensor
|
|
588
|
-
this.sirenResetMotionSensorService.updateCharacteristic(
|
|
676
|
+
this.sirenResetMotionSensorService.updateCharacteristic(
|
|
677
|
+
Characteristic.MotionDetected,
|
|
678
|
+
true
|
|
679
|
+
);
|
|
589
680
|
|
|
590
681
|
setTimeout(() => {
|
|
591
|
-
this.sirenResetMotionSensorService.updateCharacteristic(
|
|
682
|
+
this.sirenResetMotionSensorService.updateCharacteristic(
|
|
683
|
+
Characteristic.MotionDetected,
|
|
684
|
+
false
|
|
685
|
+
);
|
|
592
686
|
}, 750);
|
|
593
687
|
|
|
594
688
|
// Alternative flow (Triggered -> Off -> Armed mode)
|
|
595
689
|
if (options.resetOffFlow) {
|
|
596
690
|
const originalTargetState = this.targetState;
|
|
597
|
-
this.updateTargetState(
|
|
691
|
+
this.updateTargetState(
|
|
692
|
+
Characteristic.SecuritySystemTargetState.DISARM,
|
|
693
|
+
originTypes.INTERNAL,
|
|
694
|
+
false,
|
|
695
|
+
null
|
|
696
|
+
);
|
|
598
697
|
|
|
599
698
|
setTimeout(() => {
|
|
600
|
-
this.updateTargetState(
|
|
699
|
+
this.updateTargetState(
|
|
700
|
+
originalTargetState,
|
|
701
|
+
originTypes.INTERNAL,
|
|
702
|
+
true,
|
|
703
|
+
null
|
|
704
|
+
);
|
|
601
705
|
}, 100);
|
|
602
706
|
|
|
603
707
|
return;
|
|
@@ -618,7 +722,7 @@ SecuritySystem.prototype.resetTimers = function () {
|
|
|
618
722
|
clearTimeout(this.triggerTimeout);
|
|
619
723
|
|
|
620
724
|
this.triggerTimeout = null;
|
|
621
|
-
this.log.debug(
|
|
725
|
+
this.log.debug("Trigger timeout (Cleared)");
|
|
622
726
|
}
|
|
623
727
|
|
|
624
728
|
// Clear arming timeout
|
|
@@ -626,7 +730,7 @@ SecuritySystem.prototype.resetTimers = function () {
|
|
|
626
730
|
clearTimeout(this.armTimeout);
|
|
627
731
|
|
|
628
732
|
this.armTimeout = null;
|
|
629
|
-
this.log.debug(
|
|
733
|
+
this.log.debug("Arming timeout (Cleared)");
|
|
630
734
|
}
|
|
631
735
|
|
|
632
736
|
// Clear siren triggered sensor
|
|
@@ -634,7 +738,7 @@ SecuritySystem.prototype.resetTimers = function () {
|
|
|
634
738
|
clearInterval(this.sirenTriggeredInterval);
|
|
635
739
|
|
|
636
740
|
this.sirenTriggeredInterval = null;
|
|
637
|
-
this.log.debug(
|
|
741
|
+
this.log.debug("Siren triggered interval (Cleared)");
|
|
638
742
|
}
|
|
639
743
|
|
|
640
744
|
// Clear siren tripped sensor
|
|
@@ -642,7 +746,7 @@ SecuritySystem.prototype.resetTimers = function () {
|
|
|
642
746
|
clearInterval(this.sirenTrippedInterval);
|
|
643
747
|
|
|
644
748
|
this.sirenTrippedInterval = null;
|
|
645
|
-
this.log.debug(
|
|
749
|
+
this.log.debug("Siren tripped interval (Cleared)");
|
|
646
750
|
}
|
|
647
751
|
|
|
648
752
|
// Clear double-knock timeout
|
|
@@ -650,7 +754,7 @@ SecuritySystem.prototype.resetTimers = function () {
|
|
|
650
754
|
clearTimeout(this.doubleKnockTimeout);
|
|
651
755
|
this.doubleKnockTimeout = null;
|
|
652
756
|
|
|
653
|
-
this.log.debug(
|
|
757
|
+
this.log.debug("Double-knock timeout (Cleared)");
|
|
654
758
|
}
|
|
655
759
|
|
|
656
760
|
// Clear pause timeout
|
|
@@ -658,7 +762,7 @@ SecuritySystem.prototype.resetTimers = function () {
|
|
|
658
762
|
clearTimeout(this.pauseTimeout);
|
|
659
763
|
this.pauseTimeout = null;
|
|
660
764
|
|
|
661
|
-
this.log.debug(
|
|
765
|
+
this.log.debug("Pause timeout (Cleared)");
|
|
662
766
|
}
|
|
663
767
|
|
|
664
768
|
// Clear security system reset timeout
|
|
@@ -666,7 +770,7 @@ SecuritySystem.prototype.resetTimers = function () {
|
|
|
666
770
|
clearTimeout(this.resetTimeout);
|
|
667
771
|
|
|
668
772
|
this.resetTimeout = null;
|
|
669
|
-
this.log.debug(
|
|
773
|
+
this.log.debug("Reset timeout (Cleared)");
|
|
670
774
|
}
|
|
671
775
|
};
|
|
672
776
|
|
|
@@ -683,7 +787,9 @@ SecuritySystem.prototype.handleStateUpdate = function (alarmTriggered) {
|
|
|
683
787
|
return;
|
|
684
788
|
}
|
|
685
789
|
|
|
686
|
-
const sirenOnCharacteristic = this.sirenSwitchService.getCharacteristic(
|
|
790
|
+
const sirenOnCharacteristic = this.sirenSwitchService.getCharacteristic(
|
|
791
|
+
Characteristic.On
|
|
792
|
+
);
|
|
687
793
|
|
|
688
794
|
if (sirenOnCharacteristic.value) {
|
|
689
795
|
this.updateSiren(false, originTypes.INTERNAL, true, null);
|
|
@@ -692,14 +798,22 @@ SecuritySystem.prototype.handleStateUpdate = function (alarmTriggered) {
|
|
|
692
798
|
this.resetSirenSwitches();
|
|
693
799
|
};
|
|
694
800
|
|
|
695
|
-
SecuritySystem.prototype.updateTargetState = function (
|
|
801
|
+
SecuritySystem.prototype.updateTargetState = function (
|
|
802
|
+
state,
|
|
803
|
+
origin,
|
|
804
|
+
delay,
|
|
805
|
+
callback
|
|
806
|
+
) {
|
|
696
807
|
const isTargetStateAlreadySet = this.targetState === state;
|
|
697
|
-
const isCurrentStateAlarmTriggered =
|
|
698
|
-
|
|
808
|
+
const isCurrentStateAlarmTriggered =
|
|
809
|
+
this.currentState ===
|
|
810
|
+
Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED;
|
|
811
|
+
const isTargetStateDisarm =
|
|
812
|
+
state === Characteristic.SecuritySystemTargetState.DISARM;
|
|
699
813
|
|
|
700
814
|
// Check if target state is already set
|
|
701
815
|
if (isTargetStateAlreadySet && isCurrentStateAlarmTriggered === false) {
|
|
702
|
-
this.log.warn(
|
|
816
|
+
this.log.warn("Target mode (Already set)");
|
|
703
817
|
|
|
704
818
|
if (callback !== null) {
|
|
705
819
|
callback(null);
|
|
@@ -710,7 +824,7 @@ SecuritySystem.prototype.updateTargetState = function (state, origin, delay, cal
|
|
|
710
824
|
|
|
711
825
|
// Check if state is enabled
|
|
712
826
|
if (this.availableTargetStates.includes(state) === false) {
|
|
713
|
-
this.log.warn(
|
|
827
|
+
this.log.warn("Target mode (Disabled)");
|
|
714
828
|
|
|
715
829
|
if (callback !== null) {
|
|
716
830
|
// Tip: this will revert the original state
|
|
@@ -721,10 +835,16 @@ SecuritySystem.prototype.updateTargetState = function (state, origin, delay, cal
|
|
|
721
835
|
}
|
|
722
836
|
|
|
723
837
|
// Check arming lock switches
|
|
724
|
-
const isArmingLockEnabled =
|
|
838
|
+
const isArmingLockEnabled =
|
|
839
|
+
options.isValueSet(options.armingLockSwitch) ||
|
|
840
|
+
options.isValueSet(options.armingLockSwitches);
|
|
725
841
|
|
|
726
|
-
if (
|
|
727
|
-
|
|
842
|
+
if (
|
|
843
|
+
isTargetStateDisarm === false &&
|
|
844
|
+
isArmingLockEnabled &&
|
|
845
|
+
this.isArmingLocked(state)
|
|
846
|
+
) {
|
|
847
|
+
this.log.warn("Arming lock (Not allowed)");
|
|
728
848
|
|
|
729
849
|
if (callback !== null) {
|
|
730
850
|
// Tip: this will revert the original state
|
|
@@ -736,32 +856,38 @@ SecuritySystem.prototype.updateTargetState = function (state, origin, delay, cal
|
|
|
736
856
|
|
|
737
857
|
// Update target state
|
|
738
858
|
this.targetState = state;
|
|
739
|
-
this.logMode(
|
|
859
|
+
this.logMode("Target", state);
|
|
740
860
|
|
|
741
|
-
const isTargetStateHome =
|
|
742
|
-
|
|
743
|
-
const
|
|
861
|
+
const isTargetStateHome =
|
|
862
|
+
this.targetState === Characteristic.SecuritySystemTargetState.STAY_ARM;
|
|
863
|
+
const isTargetStateAway =
|
|
864
|
+
this.targetState === Characteristic.SecuritySystemTargetState.AWAY_ARM;
|
|
865
|
+
const isTargetStateNight =
|
|
866
|
+
this.targetState === Characteristic.SecuritySystemTargetState.NIGHT_ARM;
|
|
744
867
|
|
|
745
868
|
// Update characteristic
|
|
746
869
|
if (origin === originTypes.INTERNAL || origin === originTypes.EXTERNAL) {
|
|
747
|
-
this.service.updateCharacteristic(
|
|
870
|
+
this.service.updateCharacteristic(
|
|
871
|
+
Characteristic.SecuritySystemTargetState,
|
|
872
|
+
this.targetState
|
|
873
|
+
);
|
|
748
874
|
}
|
|
749
875
|
|
|
750
876
|
// Reset everything
|
|
751
877
|
this.handleStateUpdate(false);
|
|
752
878
|
|
|
753
879
|
// Commands
|
|
754
|
-
this.executeCommand(
|
|
880
|
+
this.executeCommand("target", state, origin);
|
|
755
881
|
|
|
756
882
|
// Webhooks
|
|
757
|
-
this.sendWebhookEvent(
|
|
883
|
+
this.sendWebhookEvent("target", state, origin);
|
|
758
884
|
|
|
759
885
|
// Check if current state is already set
|
|
760
886
|
if (state === this.currentState) {
|
|
761
|
-
this.log.warn(
|
|
887
|
+
this.log.warn("Current mode (Already set)");
|
|
762
888
|
|
|
763
889
|
// Play audio
|
|
764
|
-
this.playAudio(
|
|
890
|
+
this.playAudio("current", this.currentState);
|
|
765
891
|
|
|
766
892
|
if (callback !== null) {
|
|
767
893
|
callback(null);
|
|
@@ -784,11 +910,15 @@ SecuritySystem.prototype.updateTargetState = function (state, origin, delay, cal
|
|
|
784
910
|
// Custom mode seconds
|
|
785
911
|
if (isTargetStateHome && options.isValueSet(options.homeArmSeconds)) {
|
|
786
912
|
armSeconds = options.homeArmSeconds;
|
|
787
|
-
}
|
|
788
|
-
|
|
913
|
+
} else if (
|
|
914
|
+
isTargetStateAway &&
|
|
915
|
+
options.isValueSet(options.awayArmSeconds)
|
|
916
|
+
) {
|
|
789
917
|
armSeconds = options.awayArmSeconds;
|
|
790
|
-
}
|
|
791
|
-
|
|
918
|
+
} else if (
|
|
919
|
+
isTargetStateNight &&
|
|
920
|
+
options.isValueSet(options.nightArmSeconds)
|
|
921
|
+
) {
|
|
792
922
|
armSeconds = options.nightArmSeconds;
|
|
793
923
|
}
|
|
794
924
|
|
|
@@ -797,7 +927,7 @@ SecuritySystem.prototype.updateTargetState = function (state, origin, delay, cal
|
|
|
797
927
|
this.isArming = true;
|
|
798
928
|
|
|
799
929
|
// Play sound
|
|
800
|
-
this.playAudio(
|
|
930
|
+
this.playAudio("target", state);
|
|
801
931
|
}
|
|
802
932
|
}
|
|
803
933
|
|
|
@@ -823,19 +953,30 @@ SecuritySystem.prototype.setTargetState = function (value, callback) {
|
|
|
823
953
|
this.updateTargetState(value, originTypes.REGULAR_SWITCH, true, callback);
|
|
824
954
|
};
|
|
825
955
|
|
|
826
|
-
SecuritySystem.prototype.updateSiren = function (
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
956
|
+
SecuritySystem.prototype.updateSiren = function (
|
|
957
|
+
value,
|
|
958
|
+
origin,
|
|
959
|
+
stateChanged,
|
|
960
|
+
callback
|
|
961
|
+
) {
|
|
962
|
+
const isCurrentStateAlarmTriggered =
|
|
963
|
+
this.currentState ===
|
|
964
|
+
Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED;
|
|
965
|
+
const isCurrentStateHome =
|
|
966
|
+
this.currentState === Characteristic.SecuritySystemCurrentState.STAY_ARM;
|
|
967
|
+
const isCurrentStateAway =
|
|
968
|
+
this.currentState === Characteristic.SecuritySystemCurrentState.AWAY_ARM;
|
|
969
|
+
const isCurrentStateNight =
|
|
970
|
+
this.currentState === Characteristic.SecuritySystemCurrentState.NIGHT_ARM;
|
|
971
|
+
const isCurrentStateDisarmed =
|
|
972
|
+
this.currentState === Characteristic.SecuritySystemCurrentState.DISARMED;
|
|
832
973
|
|
|
833
974
|
// Check if the security system is disarmed
|
|
834
975
|
const isNotOverridingOff = options.overrideOff === false;
|
|
835
976
|
const isNotSpecialSwitch = origin !== originTypes.SPECIAL_SWITCH;
|
|
836
977
|
|
|
837
978
|
if (isCurrentStateDisarmed && isNotOverridingOff && isNotSpecialSwitch) {
|
|
838
|
-
this.log.warn(
|
|
979
|
+
this.log.warn("Siren Switch (Not armed)");
|
|
839
980
|
|
|
840
981
|
if (callback !== null) {
|
|
841
982
|
callback(-70412, false);
|
|
@@ -846,7 +987,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
|
|
|
846
987
|
|
|
847
988
|
// Check if arming
|
|
848
989
|
if (this.isArming) {
|
|
849
|
-
this.log.warn(
|
|
990
|
+
this.log.warn("Siren Switch (Still arming)");
|
|
850
991
|
|
|
851
992
|
if (callback !== null) {
|
|
852
993
|
callback(-70412, false);
|
|
@@ -857,7 +998,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
|
|
|
857
998
|
|
|
858
999
|
// Check double knock
|
|
859
1000
|
if (options.doubleKnock) {
|
|
860
|
-
const doubleKnockStates = options.doubleKnockModes.map(value => {
|
|
1001
|
+
const doubleKnockStates = options.doubleKnockModes.map((value) => {
|
|
861
1002
|
return this.mode2State(value.toLowerCase());
|
|
862
1003
|
});
|
|
863
1004
|
|
|
@@ -865,20 +1006,32 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
|
|
|
865
1006
|
const isSpecialSwitch = origin === originTypes.SPECIAL_SWITCH;
|
|
866
1007
|
const isStateKnockable = doubleKnockStates.includes(this.currentState);
|
|
867
1008
|
|
|
868
|
-
if (
|
|
869
|
-
|
|
1009
|
+
if (
|
|
1010
|
+
value &&
|
|
1011
|
+
isStateKnockable &&
|
|
1012
|
+
isFirstKnock &&
|
|
1013
|
+
isSpecialSwitch === false
|
|
1014
|
+
) {
|
|
1015
|
+
this.log.warn("Siren Switch (Knock)");
|
|
870
1016
|
this.isKnocked = true;
|
|
871
1017
|
|
|
872
1018
|
// Custom mode seconds
|
|
873
1019
|
let doubleKnockSeconds = options.doubleKnockSeconds;
|
|
874
1020
|
|
|
875
|
-
if (
|
|
1021
|
+
if (
|
|
1022
|
+
isCurrentStateHome &&
|
|
1023
|
+
options.isValueSet(options.homeDoubleKnockSeconds)
|
|
1024
|
+
) {
|
|
876
1025
|
doubleKnockSeconds = options.homeDoubleKnockSeconds;
|
|
877
|
-
}
|
|
878
|
-
|
|
1026
|
+
} else if (
|
|
1027
|
+
isCurrentStateAway &&
|
|
1028
|
+
options.isValueSet(options.awayDoubleKnockSeconds)
|
|
1029
|
+
) {
|
|
879
1030
|
doubleKnockSeconds = options.awayDoubleKnockSeconds;
|
|
880
|
-
}
|
|
881
|
-
|
|
1031
|
+
} else if (
|
|
1032
|
+
isCurrentStateNight &&
|
|
1033
|
+
options.isValueSet(options.nightDoubleKnockSeconds)
|
|
1034
|
+
) {
|
|
882
1035
|
doubleKnockSeconds = options.nightDoubleKnockSeconds;
|
|
883
1036
|
}
|
|
884
1037
|
|
|
@@ -886,7 +1039,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
|
|
|
886
1039
|
this.doubleKnockTimeout = null;
|
|
887
1040
|
this.isKnocked = false;
|
|
888
1041
|
|
|
889
|
-
this.log.info(
|
|
1042
|
+
this.log.info("Siren Switch (Reset)");
|
|
890
1043
|
}, doubleKnockSeconds * 1000);
|
|
891
1044
|
|
|
892
1045
|
if (callback !== null) {
|
|
@@ -902,7 +1055,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
|
|
|
902
1055
|
clearTimeout(this.doubleKnockTimeout);
|
|
903
1056
|
this.doubleKnockTimeout = null;
|
|
904
1057
|
|
|
905
|
-
this.log.debug(
|
|
1058
|
+
this.log.debug("Double-knock timeout (Cleared)");
|
|
906
1059
|
}
|
|
907
1060
|
|
|
908
1061
|
if (origin === originTypes.INTERNAL || origin === originTypes.EXTERNAL) {
|
|
@@ -912,7 +1065,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
|
|
|
912
1065
|
if (value) {
|
|
913
1066
|
// Already triggered
|
|
914
1067
|
if (isCurrentStateAlarmTriggered) {
|
|
915
|
-
this.log.warn(
|
|
1068
|
+
this.log.warn("Siren Switch (Already triggered)");
|
|
916
1069
|
|
|
917
1070
|
if (callback !== null) {
|
|
918
1071
|
callback(-70412, false);
|
|
@@ -923,7 +1076,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
|
|
|
923
1076
|
|
|
924
1077
|
// Already about to trigger
|
|
925
1078
|
if (this.triggerTimeout !== null) {
|
|
926
|
-
this.log.warn(
|
|
1079
|
+
this.log.warn("Siren Switch (Already on)");
|
|
927
1080
|
|
|
928
1081
|
if (callback !== null) {
|
|
929
1082
|
callback(-70412, false);
|
|
@@ -932,7 +1085,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
|
|
|
932
1085
|
return false;
|
|
933
1086
|
}
|
|
934
1087
|
|
|
935
|
-
this.log.info(
|
|
1088
|
+
this.log.info("Siren Switch (On)");
|
|
936
1089
|
|
|
937
1090
|
// Update siren tripped sensor
|
|
938
1091
|
if (options.trippedSensor) {
|
|
@@ -943,9 +1096,12 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
|
|
|
943
1096
|
}, options.trippedSensorSeconds * 1000);
|
|
944
1097
|
}
|
|
945
1098
|
|
|
946
|
-
const isCurrentStateHome =
|
|
947
|
-
|
|
948
|
-
const
|
|
1099
|
+
const isCurrentStateHome =
|
|
1100
|
+
this.currentState === Characteristic.SecuritySystemCurrentState.STAY_ARM;
|
|
1101
|
+
const isCurrentStateAway =
|
|
1102
|
+
this.currentState === Characteristic.SecuritySystemCurrentState.AWAY_ARM;
|
|
1103
|
+
const isCurrentStateNight =
|
|
1104
|
+
this.currentState === Characteristic.SecuritySystemCurrentState.NIGHT_ARM;
|
|
949
1105
|
|
|
950
1106
|
// Set trigger delay
|
|
951
1107
|
let triggerSeconds = options.triggerSeconds;
|
|
@@ -956,54 +1112,70 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
|
|
|
956
1112
|
}
|
|
957
1113
|
|
|
958
1114
|
if (isCurrentStateAway) {
|
|
959
|
-
const modeAwayExtendedSwitchCharacteristicOn =
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
1115
|
+
const modeAwayExtendedSwitchCharacteristicOn =
|
|
1116
|
+
this.modeAwayExtendedSwitchService.getCharacteristic(Characteristic.On);
|
|
1117
|
+
const modeAwayExtendedSwitchCharacteristicOnValue =
|
|
1118
|
+
modeAwayExtendedSwitchCharacteristicOn.value;
|
|
1119
|
+
|
|
1120
|
+
if (
|
|
1121
|
+
options.isValueSet(options.awayExtendedTriggerSeconds) &&
|
|
1122
|
+
modeAwayExtendedSwitchCharacteristicOnValue
|
|
1123
|
+
) {
|
|
963
1124
|
triggerSeconds = options.awayExtendedTriggerSeconds;
|
|
964
|
-
}
|
|
965
|
-
else if (options.isValueSet(options.awayTriggerSeconds)) {
|
|
1125
|
+
} else if (options.isValueSet(options.awayTriggerSeconds)) {
|
|
966
1126
|
triggerSeconds = options.awayTriggerSeconds;
|
|
967
1127
|
}
|
|
968
1128
|
}
|
|
969
1129
|
|
|
970
|
-
if (
|
|
1130
|
+
if (
|
|
1131
|
+
isCurrentStateNight &&
|
|
1132
|
+
options.isValueSet(options.nightTriggerSeconds)
|
|
1133
|
+
) {
|
|
971
1134
|
triggerSeconds = options.nightTriggerSeconds;
|
|
972
1135
|
}
|
|
973
1136
|
|
|
974
1137
|
this.triggerTimeout = setTimeout(() => {
|
|
975
1138
|
this.triggerTimeout = null;
|
|
976
|
-
this.setCurrentState(
|
|
1139
|
+
this.setCurrentState(
|
|
1140
|
+
Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED,
|
|
1141
|
+
origin
|
|
1142
|
+
);
|
|
977
1143
|
}, triggerSeconds * 1000);
|
|
978
1144
|
|
|
979
1145
|
// Audio
|
|
980
1146
|
if (triggerSeconds > 0) {
|
|
981
|
-
this.playAudio(
|
|
1147
|
+
this.playAudio("current", "warning");
|
|
982
1148
|
}
|
|
983
1149
|
|
|
984
1150
|
// Commands
|
|
985
|
-
this.executeCommand(
|
|
1151
|
+
this.executeCommand("current", "warning", origin);
|
|
986
1152
|
|
|
987
1153
|
// Webhooks
|
|
988
|
-
this.sendWebhookEvent(
|
|
989
|
-
}
|
|
990
|
-
else {
|
|
1154
|
+
this.sendWebhookEvent("current", "warning", origin);
|
|
1155
|
+
} else {
|
|
991
1156
|
// Off
|
|
992
|
-
this.log.info(
|
|
1157
|
+
this.log.info("Siren Switch (Off)");
|
|
993
1158
|
this.stopAudio();
|
|
994
1159
|
|
|
995
1160
|
if (isCurrentStateAlarmTriggered) {
|
|
996
1161
|
if (stateChanged === false) {
|
|
997
|
-
this.updateTargetState(
|
|
1162
|
+
this.updateTargetState(
|
|
1163
|
+
Characteristic.SecuritySystemTargetState.DISARM,
|
|
1164
|
+
originTypes.INTERNAL,
|
|
1165
|
+
false,
|
|
1166
|
+
null
|
|
1167
|
+
);
|
|
998
1168
|
}
|
|
999
|
-
}
|
|
1000
|
-
else {
|
|
1169
|
+
} else {
|
|
1001
1170
|
this.resetTimers();
|
|
1002
1171
|
}
|
|
1003
1172
|
|
|
1004
1173
|
// Update siren tripped sensor
|
|
1005
1174
|
if (options.trippedSensor) {
|
|
1006
|
-
this.sirenTrippedMotionSensorService.updateCharacteristic(
|
|
1175
|
+
this.sirenTrippedMotionSensorService.updateCharacteristic(
|
|
1176
|
+
Characteristic.MotionDetected,
|
|
1177
|
+
false
|
|
1178
|
+
);
|
|
1007
1179
|
}
|
|
1008
1180
|
|
|
1009
1181
|
this.isKnocked = false;
|
|
@@ -1057,31 +1229,30 @@ SecuritySystem.prototype.isAuthenticated = function (req, res) {
|
|
|
1057
1229
|
};
|
|
1058
1230
|
|
|
1059
1231
|
SecuritySystem.prototype.getDelayParameter = function (req) {
|
|
1060
|
-
return req.query.delay ===
|
|
1232
|
+
return req.query.delay === "true" ? true : false;
|
|
1061
1233
|
};
|
|
1062
1234
|
|
|
1063
1235
|
SecuritySystem.prototype.sendCodeRequiredError = function (res) {
|
|
1064
|
-
this.log.info(
|
|
1236
|
+
this.log.info("Code required (Server)");
|
|
1065
1237
|
|
|
1066
1238
|
const response = {
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1239
|
+
error: true,
|
|
1240
|
+
message: "Code required",
|
|
1241
|
+
hint: "Add the 'code' URL parameter with your security code",
|
|
1070
1242
|
};
|
|
1071
1243
|
|
|
1072
1244
|
res.status(401).json(response);
|
|
1073
1245
|
};
|
|
1074
1246
|
|
|
1075
1247
|
SecuritySystem.prototype.sendCodeInvalidError = function (req, res) {
|
|
1076
|
-
const response = {
|
|
1248
|
+
const response = { error: true };
|
|
1077
1249
|
|
|
1078
1250
|
if (req.blocked) {
|
|
1079
|
-
this.log.info(
|
|
1080
|
-
response.message =
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
response.message = 'Code invalid';
|
|
1251
|
+
this.log.info("Code blocked (Server)");
|
|
1252
|
+
response.message = "Code blocked";
|
|
1253
|
+
} else {
|
|
1254
|
+
this.log.info("Code invalid (Server)");
|
|
1255
|
+
response.message = "Code invalid";
|
|
1085
1256
|
}
|
|
1086
1257
|
|
|
1087
1258
|
res.status(403).json(response);
|
|
@@ -1089,7 +1260,7 @@ SecuritySystem.prototype.sendCodeInvalidError = function (req, res) {
|
|
|
1089
1260
|
|
|
1090
1261
|
SecuritySystem.prototype.sendResultResponse = function (res, sucess) {
|
|
1091
1262
|
const response = {
|
|
1092
|
-
|
|
1263
|
+
error: sucess ? false : true,
|
|
1093
1264
|
};
|
|
1094
1265
|
|
|
1095
1266
|
res.json(response);
|
|
@@ -1100,32 +1271,34 @@ SecuritySystem.prototype.startServer = async function () {
|
|
|
1100
1271
|
windowMs: 1 * 60 * 1000,
|
|
1101
1272
|
max: 100,
|
|
1102
1273
|
standardHeaders: true,
|
|
1103
|
-
legacyHeaders: false
|
|
1274
|
+
legacyHeaders: false,
|
|
1104
1275
|
});
|
|
1105
1276
|
|
|
1106
1277
|
app.use(apiLimiter);
|
|
1107
1278
|
|
|
1108
|
-
app.get(
|
|
1109
|
-
res.redirect(
|
|
1279
|
+
app.get("/", (req, res) => {
|
|
1280
|
+
res.redirect(
|
|
1281
|
+
"https://github.com/MiguelRipoll23/homebridge-securitysystem/wiki/Server"
|
|
1282
|
+
);
|
|
1110
1283
|
});
|
|
1111
1284
|
|
|
1112
|
-
app.get(
|
|
1285
|
+
app.get("/status", (req, res) => {
|
|
1113
1286
|
if (this.isAuthenticated(req, res) === false) {
|
|
1114
1287
|
return;
|
|
1115
1288
|
}
|
|
1116
1289
|
|
|
1117
1290
|
const response = {
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1291
|
+
arming: this.isArming,
|
|
1292
|
+
current_mode: this.state2Mode(this.currentState),
|
|
1293
|
+
target_mode: this.state2Mode(this.targetState),
|
|
1294
|
+
sensor_triggered: this.triggerTimeout !== null,
|
|
1295
|
+
arming_lock: this.isArmingLocked("global"),
|
|
1123
1296
|
};
|
|
1124
1297
|
|
|
1125
1298
|
res.json(response);
|
|
1126
1299
|
});
|
|
1127
1300
|
|
|
1128
|
-
app.get(
|
|
1301
|
+
app.get("/triggered", (req, res) => {
|
|
1129
1302
|
if (this.isAuthenticated(req, res) === false) {
|
|
1130
1303
|
return;
|
|
1131
1304
|
}
|
|
@@ -1135,9 +1308,10 @@ SecuritySystem.prototype.startServer = async function () {
|
|
|
1135
1308
|
if (this.getDelayParameter(req)) {
|
|
1136
1309
|
// Delay
|
|
1137
1310
|
result = this.updateSiren(true, originTypes.EXTERNAL, false, null);
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1311
|
+
} else {
|
|
1312
|
+
const isCurrentStateDisarmed =
|
|
1313
|
+
this.currentState ===
|
|
1314
|
+
Characteristic.SecuritySystemCurrentState.DISARMED;
|
|
1141
1315
|
|
|
1142
1316
|
// Not armed
|
|
1143
1317
|
if (isCurrentStateDisarmed && options.overrideOff === false) {
|
|
@@ -1146,76 +1320,99 @@ SecuritySystem.prototype.startServer = async function () {
|
|
|
1146
1320
|
}
|
|
1147
1321
|
|
|
1148
1322
|
this.handleStateUpdate(true);
|
|
1149
|
-
this.setCurrentState(
|
|
1323
|
+
this.setCurrentState(
|
|
1324
|
+
Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED,
|
|
1325
|
+
true
|
|
1326
|
+
);
|
|
1150
1327
|
}
|
|
1151
1328
|
|
|
1152
1329
|
this.sendResultResponse(res, result);
|
|
1153
1330
|
});
|
|
1154
1331
|
|
|
1155
|
-
app.get(
|
|
1332
|
+
app.get("/home", (req, res) => {
|
|
1156
1333
|
if (this.isAuthenticated(req, res) === false) {
|
|
1157
1334
|
return;
|
|
1158
1335
|
}
|
|
1159
1336
|
|
|
1160
1337
|
const state = Characteristic.SecuritySystemTargetState.STAY_ARM;
|
|
1161
1338
|
const delay = this.getDelayParameter(req);
|
|
1162
|
-
const result = this.updateTargetState(
|
|
1339
|
+
const result = this.updateTargetState(
|
|
1340
|
+
state,
|
|
1341
|
+
originTypes.EXTERNAL,
|
|
1342
|
+
delay,
|
|
1343
|
+
null
|
|
1344
|
+
);
|
|
1163
1345
|
|
|
1164
1346
|
this.sendResultResponse(res, result);
|
|
1165
1347
|
});
|
|
1166
1348
|
|
|
1167
|
-
app.get(
|
|
1349
|
+
app.get("/away", (req, res) => {
|
|
1168
1350
|
if (this.isAuthenticated(req, res) === false) {
|
|
1169
1351
|
return;
|
|
1170
1352
|
}
|
|
1171
1353
|
|
|
1172
1354
|
const state = Characteristic.SecuritySystemTargetState.AWAY_ARM;
|
|
1173
1355
|
const delay = this.getDelayParameter(req);
|
|
1174
|
-
const result = this.updateTargetState(
|
|
1356
|
+
const result = this.updateTargetState(
|
|
1357
|
+
state,
|
|
1358
|
+
originTypes.EXTERNAL,
|
|
1359
|
+
delay,
|
|
1360
|
+
null
|
|
1361
|
+
);
|
|
1175
1362
|
|
|
1176
1363
|
this.sendResultResponse(res, result);
|
|
1177
1364
|
});
|
|
1178
1365
|
|
|
1179
|
-
app.get(
|
|
1366
|
+
app.get("/night", (req, res) => {
|
|
1180
1367
|
if (this.isAuthenticated(req, res) === false) {
|
|
1181
1368
|
return;
|
|
1182
1369
|
}
|
|
1183
1370
|
|
|
1184
1371
|
const state = Characteristic.SecuritySystemTargetState.NIGHT_ARM;
|
|
1185
1372
|
const delay = this.getDelayParameter(req);
|
|
1186
|
-
const result = this.updateTargetState(
|
|
1373
|
+
const result = this.updateTargetState(
|
|
1374
|
+
state,
|
|
1375
|
+
originTypes.EXTERNAL,
|
|
1376
|
+
delay,
|
|
1377
|
+
null
|
|
1378
|
+
);
|
|
1187
1379
|
|
|
1188
1380
|
this.sendResultResponse(res, result);
|
|
1189
1381
|
});
|
|
1190
1382
|
|
|
1191
|
-
app.get(
|
|
1383
|
+
app.get("/off", (req, res) => {
|
|
1192
1384
|
if (this.isAuthenticated(req, res) === false) {
|
|
1193
1385
|
return;
|
|
1194
1386
|
}
|
|
1195
1387
|
|
|
1196
1388
|
const state = Characteristic.SecuritySystemTargetState.DISARM;
|
|
1197
1389
|
const delay = this.getDelayParameter(req);
|
|
1198
|
-
const result = this.updateTargetState(
|
|
1390
|
+
const result = this.updateTargetState(
|
|
1391
|
+
state,
|
|
1392
|
+
originTypes.EXTERNAL,
|
|
1393
|
+
delay,
|
|
1394
|
+
null
|
|
1395
|
+
);
|
|
1199
1396
|
|
|
1200
1397
|
this.sendResultResponse(res, result);
|
|
1201
1398
|
});
|
|
1202
1399
|
|
|
1203
|
-
app.get(
|
|
1400
|
+
app.get("/arming-lock/:mode/:value", (req, res) => {
|
|
1204
1401
|
if (this.isAuthenticated(req, res) === false) {
|
|
1205
1402
|
return;
|
|
1206
1403
|
}
|
|
1207
1404
|
|
|
1208
|
-
const mode = req.params[
|
|
1209
|
-
const value = req.params[
|
|
1405
|
+
const mode = req.params["mode"].toLowerCase();
|
|
1406
|
+
const value = req.params["value"].includes("on");
|
|
1210
1407
|
const result = this.updateArmingLock(mode, value);
|
|
1211
1408
|
|
|
1212
1409
|
this.sendResultResponse(res, result);
|
|
1213
1410
|
});
|
|
1214
1411
|
|
|
1215
1412
|
// Listener
|
|
1216
|
-
const server = app.listen(options.serverPort, error => {
|
|
1413
|
+
const server = app.listen(options.serverPort, (error) => {
|
|
1217
1414
|
if (error) {
|
|
1218
|
-
this.log.error(
|
|
1415
|
+
this.log.error("Error while starting server.");
|
|
1219
1416
|
this.log.error(error);
|
|
1220
1417
|
return;
|
|
1221
1418
|
}
|
|
@@ -1223,8 +1420,8 @@ SecuritySystem.prototype.startServer = async function () {
|
|
|
1223
1420
|
this.log.info(`Server (${options.serverPort})`);
|
|
1224
1421
|
});
|
|
1225
1422
|
|
|
1226
|
-
server.on(
|
|
1227
|
-
this.log.error(
|
|
1423
|
+
server.on("error", (error) => {
|
|
1424
|
+
this.log.error("Error while starting server.");
|
|
1228
1425
|
this.log.error(error);
|
|
1229
1426
|
});
|
|
1230
1427
|
};
|
|
@@ -1242,17 +1439,19 @@ SecuritySystem.prototype.playAudio = async function (type, state) {
|
|
|
1242
1439
|
this.stopAudio();
|
|
1243
1440
|
|
|
1244
1441
|
// Ignore 'Current Off' event
|
|
1245
|
-
if (mode ===
|
|
1246
|
-
if (type ===
|
|
1442
|
+
if (mode === "off") {
|
|
1443
|
+
if (type === "target") {
|
|
1247
1444
|
return;
|
|
1248
1445
|
}
|
|
1249
1446
|
}
|
|
1250
1447
|
|
|
1251
1448
|
// Check audio switch except for triggered
|
|
1252
|
-
const audioSwitchOnCharacteristic = this.audioSwitchService.getCharacteristic(
|
|
1449
|
+
const audioSwitchOnCharacteristic = this.audioSwitchService.getCharacteristic(
|
|
1450
|
+
Characteristic.On
|
|
1451
|
+
);
|
|
1253
1452
|
const isAudioDisabledBySwitch = audioSwitchOnCharacteristic.value === false;
|
|
1254
1453
|
|
|
1255
|
-
if (mode !==
|
|
1454
|
+
if (mode !== "triggered" && isAudioDisabledBySwitch) {
|
|
1256
1455
|
return;
|
|
1257
1456
|
}
|
|
1258
1457
|
|
|
@@ -1262,7 +1461,7 @@ SecuritySystem.prototype.playAudio = async function (type, state) {
|
|
|
1262
1461
|
if (options.isValueSet(options.audioPath)) {
|
|
1263
1462
|
directory = options.audioPath;
|
|
1264
1463
|
|
|
1265
|
-
if (directory[directory.length] ===
|
|
1464
|
+
if (directory[directory.length] === "/") {
|
|
1266
1465
|
directory = directory.substring(0, directory.length - 1);
|
|
1267
1466
|
}
|
|
1268
1467
|
}
|
|
@@ -1273,51 +1472,66 @@ SecuritySystem.prototype.playAudio = async function (type, state) {
|
|
|
1273
1472
|
|
|
1274
1473
|
try {
|
|
1275
1474
|
await fs.promises.access(filePath);
|
|
1276
|
-
}
|
|
1277
|
-
catch (error) {
|
|
1475
|
+
} catch (error) {
|
|
1278
1476
|
this.log.debug(`Sound file not found (${filePath})`);
|
|
1279
1477
|
return;
|
|
1280
1478
|
}
|
|
1281
1479
|
|
|
1282
1480
|
// Arguments
|
|
1283
|
-
let commandArguments = [
|
|
1284
|
-
|
|
1285
|
-
if (mode ===
|
|
1286
|
-
commandArguments.push(
|
|
1287
|
-
commandArguments.push(
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
commandArguments.push(
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1481
|
+
let commandArguments = ["-loglevel", "error", "-nodisp", "-i", `${filePath}`];
|
|
1482
|
+
|
|
1483
|
+
if (mode === "triggered") {
|
|
1484
|
+
commandArguments.push("-loop");
|
|
1485
|
+
commandArguments.push("-1");
|
|
1486
|
+
} else if (
|
|
1487
|
+
(mode === "home" || mode === "night" || mode === "away") &&
|
|
1488
|
+
type === "target" &&
|
|
1489
|
+
options.audioArmingLooped
|
|
1490
|
+
) {
|
|
1491
|
+
commandArguments.push("-loop");
|
|
1492
|
+
commandArguments.push("-1");
|
|
1493
|
+
} else if (mode === "warning" && options.audioAlertLooped) {
|
|
1494
|
+
commandArguments.push("-loop");
|
|
1495
|
+
commandArguments.push("-1");
|
|
1496
|
+
} else {
|
|
1497
|
+
commandArguments.push("-autoexit");
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
if (options.isValueSet(options.audioVolume)) {
|
|
1501
|
+
commandArguments.push("-volume");
|
|
1502
|
+
commandArguments.push(options.audioVolume);
|
|
1304
1503
|
}
|
|
1305
1504
|
|
|
1306
1505
|
// Process
|
|
1307
|
-
|
|
1308
|
-
|
|
1506
|
+
const environmentVariables = [process.env];
|
|
1507
|
+
|
|
1508
|
+
options.audioExtraVariables.forEach((variable) => {
|
|
1509
|
+
const key = variable.key;
|
|
1510
|
+
const value = variable.value;
|
|
1511
|
+
environmentVariables[key] = value;
|
|
1512
|
+
});
|
|
1309
1513
|
|
|
1310
|
-
this.
|
|
1514
|
+
this.log.debug("Environment Variables (Audio)", environmentVariables);
|
|
1515
|
+
|
|
1516
|
+
const ffplayEnv = {
|
|
1517
|
+
...process.env,
|
|
1518
|
+
...environmentVariables,
|
|
1519
|
+
};
|
|
1520
|
+
|
|
1521
|
+
this.audioProcess = spawn("ffplay", commandArguments, { env: ffplayEnv });
|
|
1522
|
+
this.log.debug(`ffplay ${commandArguments.join(" ")}`);
|
|
1523
|
+
|
|
1524
|
+
this.audioProcess.on("error", (data) => {
|
|
1311
1525
|
// Check if command is missing
|
|
1312
|
-
if (data !== null && data.toString().indexOf(
|
|
1313
|
-
this.log.error(
|
|
1526
|
+
if (data !== null && data.toString().indexOf("ENOENT") > -1) {
|
|
1527
|
+
this.log.error("Unable to play sound, ffmpeg is not installed.");
|
|
1314
1528
|
return;
|
|
1315
1529
|
}
|
|
1316
1530
|
|
|
1317
1531
|
this.log.error(`Unable to play sound.\n${data}`);
|
|
1318
1532
|
});
|
|
1319
1533
|
|
|
1320
|
-
this.audioProcess.on(
|
|
1534
|
+
this.audioProcess.on("close", function () {
|
|
1321
1535
|
this.audioProcess = null;
|
|
1322
1536
|
});
|
|
1323
1537
|
};
|
|
@@ -1331,13 +1545,18 @@ SecuritySystem.prototype.stopAudio = function () {
|
|
|
1331
1545
|
SecuritySystem.prototype.setupAudio = async function () {
|
|
1332
1546
|
try {
|
|
1333
1547
|
await fs.promises.access(`${options.audioPath}/${options.audioLanguage}`);
|
|
1334
|
-
}
|
|
1335
|
-
catch (error) {
|
|
1548
|
+
} catch (error) {
|
|
1336
1549
|
await fs.promises.mkdir(`${options.audioPath}/${options.audioLanguage}`);
|
|
1337
|
-
await fs.promises.copyFile(
|
|
1338
|
-
|
|
1550
|
+
await fs.promises.copyFile(
|
|
1551
|
+
`${__dirname}/sounds/README`,
|
|
1552
|
+
`${options.audioPath}/README`
|
|
1553
|
+
);
|
|
1554
|
+
await fs.promises.copyFile(
|
|
1555
|
+
`${__dirname}/sounds/README`,
|
|
1556
|
+
`${options.audioPath}/README.txt`
|
|
1557
|
+
);
|
|
1339
1558
|
|
|
1340
|
-
this.log.warn(
|
|
1559
|
+
this.log.warn("Check audio path directory for instructions.");
|
|
1341
1560
|
}
|
|
1342
1561
|
};
|
|
1343
1562
|
|
|
@@ -1345,7 +1564,7 @@ SecuritySystem.prototype.setupAudio = async function () {
|
|
|
1345
1564
|
SecuritySystem.prototype.executeCommand = function (type, state, origin) {
|
|
1346
1565
|
// Check proxy mode
|
|
1347
1566
|
if (options.proxyMode && origin === originTypes.EXTERNAL) {
|
|
1348
|
-
this.log.debug(
|
|
1567
|
+
this.log.debug("Command bypassed as proxy mode is enabled.");
|
|
1349
1568
|
return;
|
|
1350
1569
|
}
|
|
1351
1570
|
|
|
@@ -1357,7 +1576,7 @@ SecuritySystem.prototype.executeCommand = function (type, state, origin) {
|
|
|
1357
1576
|
break;
|
|
1358
1577
|
|
|
1359
1578
|
case Characteristic.SecuritySystemCurrentState.STAY_ARM:
|
|
1360
|
-
if (type ===
|
|
1579
|
+
if (type === "current") {
|
|
1361
1580
|
command = options.commandCurrentHome;
|
|
1362
1581
|
break;
|
|
1363
1582
|
}
|
|
@@ -1366,7 +1585,7 @@ SecuritySystem.prototype.executeCommand = function (type, state, origin) {
|
|
|
1366
1585
|
break;
|
|
1367
1586
|
|
|
1368
1587
|
case Characteristic.SecuritySystemCurrentState.AWAY_ARM:
|
|
1369
|
-
if (type ===
|
|
1588
|
+
if (type === "current") {
|
|
1370
1589
|
command = options.commandCurrentAway;
|
|
1371
1590
|
break;
|
|
1372
1591
|
}
|
|
@@ -1375,7 +1594,7 @@ SecuritySystem.prototype.executeCommand = function (type, state, origin) {
|
|
|
1375
1594
|
break;
|
|
1376
1595
|
|
|
1377
1596
|
case Characteristic.SecuritySystemCurrentState.NIGHT_ARM:
|
|
1378
|
-
if (type ===
|
|
1597
|
+
if (type === "current") {
|
|
1379
1598
|
command = options.commandCurrentNight;
|
|
1380
1599
|
break;
|
|
1381
1600
|
}
|
|
@@ -1384,7 +1603,7 @@ SecuritySystem.prototype.executeCommand = function (type, state, origin) {
|
|
|
1384
1603
|
break;
|
|
1385
1604
|
|
|
1386
1605
|
case Characteristic.SecuritySystemCurrentState.DISARMED:
|
|
1387
|
-
if (type ===
|
|
1606
|
+
if (type === "current") {
|
|
1388
1607
|
command = options.commandCurrentOff;
|
|
1389
1608
|
break;
|
|
1390
1609
|
}
|
|
@@ -1392,7 +1611,7 @@ SecuritySystem.prototype.executeCommand = function (type, state, origin) {
|
|
|
1392
1611
|
command = options.commandTargetOff;
|
|
1393
1612
|
break;
|
|
1394
1613
|
|
|
1395
|
-
case
|
|
1614
|
+
case "warning":
|
|
1396
1615
|
command = options.commandCurrentWarning;
|
|
1397
1616
|
break;
|
|
1398
1617
|
|
|
@@ -1406,15 +1625,18 @@ SecuritySystem.prototype.executeCommand = function (type, state, origin) {
|
|
|
1406
1625
|
}
|
|
1407
1626
|
|
|
1408
1627
|
// Parameters
|
|
1409
|
-
command = command.replace(
|
|
1628
|
+
command = command.replace(
|
|
1629
|
+
"${currentMode}",
|
|
1630
|
+
this.state2Mode(this.currentState)
|
|
1631
|
+
);
|
|
1410
1632
|
|
|
1411
1633
|
const process = spawn(command, { shell: true });
|
|
1412
1634
|
|
|
1413
|
-
process.stderr.on(
|
|
1635
|
+
process.stderr.on("data", (data) => {
|
|
1414
1636
|
this.log.error(`Command failed (${command})\n${data}`);
|
|
1415
1637
|
});
|
|
1416
1638
|
|
|
1417
|
-
process.stdout.on(
|
|
1639
|
+
process.stdout.on("data", (data) => {
|
|
1418
1640
|
this.log.info(`Command output: ${data}`);
|
|
1419
1641
|
});
|
|
1420
1642
|
};
|
|
@@ -1423,13 +1645,13 @@ SecuritySystem.prototype.executeCommand = function (type, state, origin) {
|
|
|
1423
1645
|
SecuritySystem.prototype.sendWebhookEvent = function (type, state, origin) {
|
|
1424
1646
|
// Check webhook host
|
|
1425
1647
|
if (options.isValueSet(options.webhookUrl) === false) {
|
|
1426
|
-
this.log.debug(
|
|
1648
|
+
this.log.debug("Webhook base URL option is not set.");
|
|
1427
1649
|
return;
|
|
1428
1650
|
}
|
|
1429
1651
|
|
|
1430
1652
|
// Check proxy mode
|
|
1431
1653
|
if (options.proxyMode && origin === originTypes.EXTERNAL) {
|
|
1432
|
-
this.log.debug(
|
|
1654
|
+
this.log.debug("Webhook bypassed as proxy mode is enabled.");
|
|
1433
1655
|
return;
|
|
1434
1656
|
}
|
|
1435
1657
|
|
|
@@ -1441,7 +1663,7 @@ SecuritySystem.prototype.sendWebhookEvent = function (type, state, origin) {
|
|
|
1441
1663
|
break;
|
|
1442
1664
|
|
|
1443
1665
|
case Characteristic.SecuritySystemCurrentState.STAY_ARM:
|
|
1444
|
-
if (type ===
|
|
1666
|
+
if (type === "current") {
|
|
1445
1667
|
path = options.webhookCurrentHome;
|
|
1446
1668
|
break;
|
|
1447
1669
|
}
|
|
@@ -1450,7 +1672,7 @@ SecuritySystem.prototype.sendWebhookEvent = function (type, state, origin) {
|
|
|
1450
1672
|
break;
|
|
1451
1673
|
|
|
1452
1674
|
case Characteristic.SecuritySystemCurrentState.AWAY_ARM:
|
|
1453
|
-
if (type ===
|
|
1675
|
+
if (type === "current") {
|
|
1454
1676
|
path = options.webhookCurrentAway;
|
|
1455
1677
|
break;
|
|
1456
1678
|
}
|
|
@@ -1459,7 +1681,7 @@ SecuritySystem.prototype.sendWebhookEvent = function (type, state, origin) {
|
|
|
1459
1681
|
break;
|
|
1460
1682
|
|
|
1461
1683
|
case Characteristic.SecuritySystemCurrentState.NIGHT_ARM:
|
|
1462
|
-
if (type ===
|
|
1684
|
+
if (type === "current") {
|
|
1463
1685
|
path = options.webhookCurrentNight;
|
|
1464
1686
|
break;
|
|
1465
1687
|
}
|
|
@@ -1468,7 +1690,7 @@ SecuritySystem.prototype.sendWebhookEvent = function (type, state, origin) {
|
|
|
1468
1690
|
break;
|
|
1469
1691
|
|
|
1470
1692
|
case Characteristic.SecuritySystemCurrentState.DISARMED:
|
|
1471
|
-
if (type ===
|
|
1693
|
+
if (type === "current") {
|
|
1472
1694
|
path = options.webhookCurrentOff;
|
|
1473
1695
|
break;
|
|
1474
1696
|
}
|
|
@@ -1476,7 +1698,7 @@ SecuritySystem.prototype.sendWebhookEvent = function (type, state, origin) {
|
|
|
1476
1698
|
path = options.webhookTargetOff;
|
|
1477
1699
|
break;
|
|
1478
1700
|
|
|
1479
|
-
case
|
|
1701
|
+
case "warning":
|
|
1480
1702
|
path = options.webhookCurrentWarning;
|
|
1481
1703
|
break;
|
|
1482
1704
|
|
|
@@ -1491,18 +1713,18 @@ SecuritySystem.prototype.sendWebhookEvent = function (type, state, origin) {
|
|
|
1491
1713
|
}
|
|
1492
1714
|
|
|
1493
1715
|
// Parameters
|
|
1494
|
-
path = path.replace(
|
|
1716
|
+
path = path.replace("${currentMode}", this.state2Mode(this.currentState));
|
|
1495
1717
|
|
|
1496
1718
|
// Send GET request to server
|
|
1497
1719
|
fetch(options.webhookUrl + path)
|
|
1498
|
-
.then(response => {
|
|
1720
|
+
.then((response) => {
|
|
1499
1721
|
if (response.ok === false) {
|
|
1500
1722
|
throw new Error(`Status code (${response.status})`);
|
|
1501
1723
|
}
|
|
1502
1724
|
|
|
1503
|
-
this.log.info(
|
|
1725
|
+
this.log.info("Webhook event (Sent)");
|
|
1504
1726
|
})
|
|
1505
|
-
.catch(error => {
|
|
1727
|
+
.catch((error) => {
|
|
1506
1728
|
this.log.error(`Request to webhook failed. (${path})`);
|
|
1507
1729
|
this.log.error(error);
|
|
1508
1730
|
});
|
|
@@ -1510,7 +1732,9 @@ SecuritySystem.prototype.sendWebhookEvent = function (type, state, origin) {
|
|
|
1510
1732
|
|
|
1511
1733
|
// Siren switches
|
|
1512
1734
|
SecuritySystem.prototype.getSirenSwitch = function (callback) {
|
|
1513
|
-
const value = this.sirenSwitchService.getCharacteristic(
|
|
1735
|
+
const value = this.sirenSwitchService.getCharacteristic(
|
|
1736
|
+
Characteristic.On
|
|
1737
|
+
).value;
|
|
1514
1738
|
callback(null, value);
|
|
1515
1739
|
};
|
|
1516
1740
|
|
|
@@ -1519,7 +1743,9 @@ SecuritySystem.prototype.setSirenSwitch = function (value, callback) {
|
|
|
1519
1743
|
};
|
|
1520
1744
|
|
|
1521
1745
|
SecuritySystem.prototype.getSirenOverrideSwitch = function (callback) {
|
|
1522
|
-
const value = this.sirenOverrideSwitchService.getCharacteristic(
|
|
1746
|
+
const value = this.sirenOverrideSwitchService.getCharacteristic(
|
|
1747
|
+
Characteristic.On
|
|
1748
|
+
).value;
|
|
1523
1749
|
callback(null, value);
|
|
1524
1750
|
};
|
|
1525
1751
|
|
|
@@ -1528,105 +1754,141 @@ SecuritySystem.prototype.setSirenOverrideSwitch = function (value, callback) {
|
|
|
1528
1754
|
};
|
|
1529
1755
|
|
|
1530
1756
|
SecuritySystem.prototype.resetSirenSwitches = function () {
|
|
1531
|
-
const sirenHomeOnCharacteristic =
|
|
1532
|
-
|
|
1533
|
-
const
|
|
1757
|
+
const sirenHomeOnCharacteristic =
|
|
1758
|
+
this.sirenHomeSwitchService.getCharacteristic(Characteristic.On);
|
|
1759
|
+
const sirenAwayOnCharacteristic =
|
|
1760
|
+
this.sirenAwaySwitchService.getCharacteristic(Characteristic.On);
|
|
1761
|
+
const sirenNightOnCharacteristic =
|
|
1762
|
+
this.sirenNightSwitchService.getCharacteristic(Characteristic.On);
|
|
1534
1763
|
|
|
1535
|
-
const sirenOverrideOnCharacteristic =
|
|
1764
|
+
const sirenOverrideOnCharacteristic =
|
|
1765
|
+
this.sirenOverrideSwitchService.getCharacteristic(Characteristic.On);
|
|
1536
1766
|
|
|
1537
1767
|
if (sirenHomeOnCharacteristic.value) {
|
|
1538
1768
|
sirenHomeOnCharacteristic.updateValue(false);
|
|
1539
|
-
this.log.debug(
|
|
1769
|
+
this.log.debug("Siren Home Switch (Off)");
|
|
1540
1770
|
}
|
|
1541
1771
|
|
|
1542
1772
|
if (sirenAwayOnCharacteristic.value) {
|
|
1543
1773
|
sirenAwayOnCharacteristic.updateValue(false);
|
|
1544
|
-
this.log.debug(
|
|
1774
|
+
this.log.debug("Siren Away Switch (Off)");
|
|
1545
1775
|
}
|
|
1546
1776
|
|
|
1547
1777
|
if (sirenNightOnCharacteristic.value) {
|
|
1548
1778
|
sirenNightOnCharacteristic.updateValue(false);
|
|
1549
|
-
this.log.debug(
|
|
1779
|
+
this.log.debug("Siren Night Switch (Off)");
|
|
1550
1780
|
}
|
|
1551
1781
|
|
|
1552
1782
|
if (sirenOverrideOnCharacteristic.value) {
|
|
1553
1783
|
sirenOverrideOnCharacteristic.updateValue(false);
|
|
1554
|
-
this.log.debug(
|
|
1784
|
+
this.log.debug("Siren Override Switch (Off)");
|
|
1555
1785
|
}
|
|
1556
1786
|
};
|
|
1557
1787
|
|
|
1558
|
-
SecuritySystem.prototype.triggerIfModeSet = function (
|
|
1559
|
-
|
|
1788
|
+
SecuritySystem.prototype.triggerIfModeSet = function (
|
|
1789
|
+
switchRequiredState,
|
|
1790
|
+
value,
|
|
1791
|
+
callback
|
|
1792
|
+
) {
|
|
1793
|
+
const isCurrentStateAlarmTriggered =
|
|
1794
|
+
this.currentState ===
|
|
1795
|
+
Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED;
|
|
1560
1796
|
|
|
1561
1797
|
if (value) {
|
|
1562
|
-
if (
|
|
1563
|
-
|
|
1798
|
+
if (
|
|
1799
|
+
this.currentState === switchRequiredState ||
|
|
1800
|
+
(this.targetState === switchRequiredState && isCurrentStateAlarmTriggered)
|
|
1801
|
+
) {
|
|
1564
1802
|
this.updateSiren(value, originTypes.REGULAR_SWITCH, false, callback);
|
|
1565
|
-
}
|
|
1566
|
-
|
|
1567
|
-
this.log.debug('Siren (Mode switch not set)');
|
|
1803
|
+
} else {
|
|
1804
|
+
this.log.debug("Siren (Mode switch not set)");
|
|
1568
1805
|
callback(-70412, false);
|
|
1569
1806
|
}
|
|
1570
|
-
}
|
|
1571
|
-
else {
|
|
1807
|
+
} else {
|
|
1572
1808
|
this.updateSiren(value, originTypes.REGULAR_SWITCH, false, callback);
|
|
1573
1809
|
}
|
|
1574
1810
|
};
|
|
1575
1811
|
|
|
1576
1812
|
SecuritySystem.prototype.getSirenHomeSwitch = function (callback) {
|
|
1577
|
-
const value = this.sirenHomeSwitchService.getCharacteristic(
|
|
1813
|
+
const value = this.sirenHomeSwitchService.getCharacteristic(
|
|
1814
|
+
Characteristic.On
|
|
1815
|
+
).value;
|
|
1578
1816
|
callback(null, value);
|
|
1579
1817
|
};
|
|
1580
1818
|
|
|
1581
1819
|
SecuritySystem.prototype.setSirenHomeSwitch = function (value, callback) {
|
|
1582
|
-
this.log.debug(
|
|
1583
|
-
this.triggerIfModeSet(
|
|
1820
|
+
this.log.debug("Siren Home Switch (On)");
|
|
1821
|
+
this.triggerIfModeSet(
|
|
1822
|
+
Characteristic.SecuritySystemCurrentState.STAY_ARM,
|
|
1823
|
+
value,
|
|
1824
|
+
callback
|
|
1825
|
+
);
|
|
1584
1826
|
};
|
|
1585
1827
|
|
|
1586
1828
|
SecuritySystem.prototype.getSirenAwaySwitch = function (callback) {
|
|
1587
|
-
const value = this.sirenAwaySwitchService.getCharacteristic(
|
|
1829
|
+
const value = this.sirenAwaySwitchService.getCharacteristic(
|
|
1830
|
+
Characteristic.On
|
|
1831
|
+
).value;
|
|
1588
1832
|
callback(null, value);
|
|
1589
1833
|
};
|
|
1590
1834
|
|
|
1591
1835
|
SecuritySystem.prototype.setSirenAwaySwitch = function (value, callback) {
|
|
1592
|
-
this.log.debug(
|
|
1593
|
-
this.triggerIfModeSet(
|
|
1836
|
+
this.log.debug("Siren Away Switch (On)");
|
|
1837
|
+
this.triggerIfModeSet(
|
|
1838
|
+
Characteristic.SecuritySystemCurrentState.AWAY_ARM,
|
|
1839
|
+
value,
|
|
1840
|
+
callback
|
|
1841
|
+
);
|
|
1594
1842
|
};
|
|
1595
1843
|
|
|
1596
1844
|
SecuritySystem.prototype.getSirenNightSwitch = function (callback) {
|
|
1597
|
-
const value = this.sirenNightSwitchService.getCharacteristic(
|
|
1845
|
+
const value = this.sirenNightSwitchService.getCharacteristic(
|
|
1846
|
+
Characteristic.On
|
|
1847
|
+
).value;
|
|
1598
1848
|
callback(null, value);
|
|
1599
1849
|
};
|
|
1600
1850
|
|
|
1601
1851
|
SecuritySystem.prototype.setSirenNightSwitch = function (value, callback) {
|
|
1602
|
-
this.log.debug(
|
|
1603
|
-
this.triggerIfModeSet(
|
|
1852
|
+
this.log.debug("Siren Night Switch (On)");
|
|
1853
|
+
this.triggerIfModeSet(
|
|
1854
|
+
Characteristic.SecuritySystemCurrentState.NIGHT_ARM,
|
|
1855
|
+
value,
|
|
1856
|
+
callback
|
|
1857
|
+
);
|
|
1604
1858
|
};
|
|
1605
1859
|
|
|
1606
1860
|
// Arming lock switches
|
|
1607
1861
|
SecuritySystem.prototype.getArmingLockSwitch = function (callback) {
|
|
1608
|
-
const value = this.armingLockSwitchService.getCharacteristic(
|
|
1862
|
+
const value = this.armingLockSwitchService.getCharacteristic(
|
|
1863
|
+
Characteristic.On
|
|
1864
|
+
).value;
|
|
1609
1865
|
callback(null, value);
|
|
1610
1866
|
};
|
|
1611
1867
|
|
|
1612
1868
|
SecuritySystem.prototype.getArmingLockHomeSwitch = function (callback) {
|
|
1613
|
-
const value = this.armingLockHomeSwitchService.getCharacteristic(
|
|
1869
|
+
const value = this.armingLockHomeSwitchService.getCharacteristic(
|
|
1870
|
+
Characteristic.On
|
|
1871
|
+
).value;
|
|
1614
1872
|
callback(null, value);
|
|
1615
1873
|
};
|
|
1616
1874
|
|
|
1617
1875
|
SecuritySystem.prototype.getArmingLockAwaySwitch = function (callback) {
|
|
1618
|
-
const value = this.armingLockAwaySwitchService.getCharacteristic(
|
|
1876
|
+
const value = this.armingLockAwaySwitchService.getCharacteristic(
|
|
1877
|
+
Characteristic.On
|
|
1878
|
+
).value;
|
|
1619
1879
|
callback(null, value);
|
|
1620
1880
|
};
|
|
1621
1881
|
|
|
1622
1882
|
SecuritySystem.prototype.getArmingLockNightSwitch = function (callback) {
|
|
1623
|
-
const value = this.armingLockNightSwitchService.getCharacteristic(
|
|
1883
|
+
const value = this.armingLockNightSwitchService.getCharacteristic(
|
|
1884
|
+
Characteristic.On
|
|
1885
|
+
).value;
|
|
1624
1886
|
callback(null, value);
|
|
1625
1887
|
};
|
|
1626
1888
|
|
|
1627
1889
|
SecuritySystem.prototype.logArmingLock = function (mode, value) {
|
|
1628
1890
|
const modeCapitalized = mode.charAt(0).toUpperCase() + mode.slice(1);
|
|
1629
|
-
this.log.info(`Arming lock [${modeCapitalized}] (${
|
|
1891
|
+
this.log.info(`Arming lock [${modeCapitalized}] (${value ? "On" : "Off"})`);
|
|
1630
1892
|
};
|
|
1631
1893
|
|
|
1632
1894
|
SecuritySystem.prototype.isArmingLocked = function (state) {
|
|
@@ -1639,7 +1901,7 @@ SecuritySystem.prototype.isArmingLocked = function (state) {
|
|
|
1639
1901
|
|
|
1640
1902
|
// Check mode switches
|
|
1641
1903
|
switch (state) {
|
|
1642
|
-
case
|
|
1904
|
+
case "global":
|
|
1643
1905
|
// Server status endpoint
|
|
1644
1906
|
return false;
|
|
1645
1907
|
|
|
@@ -1660,26 +1922,34 @@ SecuritySystem.prototype.isArmingLocked = function (state) {
|
|
|
1660
1922
|
}
|
|
1661
1923
|
|
|
1662
1924
|
return armingLockSwitchService.getCharacteristic(Characteristic.On).value;
|
|
1663
|
-
}
|
|
1925
|
+
};
|
|
1664
1926
|
|
|
1665
1927
|
SecuritySystem.prototype.updateArmingLock = function (mode, value) {
|
|
1666
1928
|
this.logArmingLock(mode, value);
|
|
1667
1929
|
|
|
1668
1930
|
switch (mode) {
|
|
1669
|
-
case
|
|
1670
|
-
this.armingLockSwitchService
|
|
1931
|
+
case "global":
|
|
1932
|
+
this.armingLockSwitchService
|
|
1933
|
+
.getCharacteristic(Characteristic.On)
|
|
1934
|
+
.updateValue(value);
|
|
1671
1935
|
break;
|
|
1672
1936
|
|
|
1673
|
-
case
|
|
1674
|
-
this.armingLockHomeSwitchService
|
|
1937
|
+
case "home":
|
|
1938
|
+
this.armingLockHomeSwitchService
|
|
1939
|
+
.getCharacteristic(Characteristic.On)
|
|
1940
|
+
.updateValue(value);
|
|
1675
1941
|
break;
|
|
1676
1942
|
|
|
1677
|
-
case
|
|
1678
|
-
this.armingLockAwaySwitchService
|
|
1943
|
+
case "away":
|
|
1944
|
+
this.armingLockAwaySwitchService
|
|
1945
|
+
.getCharacteristic(Characteristic.On)
|
|
1946
|
+
.updateValue(value);
|
|
1679
1947
|
break;
|
|
1680
1948
|
|
|
1681
|
-
case
|
|
1682
|
-
this.armingLockNightSwitchService
|
|
1949
|
+
case "night":
|
|
1950
|
+
this.armingLockNightSwitchService
|
|
1951
|
+
.getCharacteristic(Characteristic.On)
|
|
1952
|
+
.updateValue(value);
|
|
1683
1953
|
break;
|
|
1684
1954
|
|
|
1685
1955
|
default:
|
|
@@ -1691,62 +1961,68 @@ SecuritySystem.prototype.updateArmingLock = function (mode, value) {
|
|
|
1691
1961
|
};
|
|
1692
1962
|
|
|
1693
1963
|
SecuritySystem.prototype.setArmingLockSwitch = function (value, callback) {
|
|
1694
|
-
this.logArmingLock(
|
|
1964
|
+
this.logArmingLock("global", value);
|
|
1695
1965
|
callback(null);
|
|
1696
1966
|
};
|
|
1697
1967
|
|
|
1698
1968
|
SecuritySystem.prototype.setArmingLockHomeSwitch = function (value, callback) {
|
|
1699
|
-
this.logArmingLock(
|
|
1969
|
+
this.logArmingLock("home", value);
|
|
1700
1970
|
callback(null);
|
|
1701
1971
|
};
|
|
1702
1972
|
|
|
1703
1973
|
SecuritySystem.prototype.setArmingLockAwaySwitch = function (value, callback) {
|
|
1704
|
-
this.logArmingLock(
|
|
1974
|
+
this.logArmingLock("away", value);
|
|
1705
1975
|
callback(null);
|
|
1706
1976
|
};
|
|
1707
1977
|
|
|
1708
1978
|
SecuritySystem.prototype.setArmingLockNightSwitch = function (value, callback) {
|
|
1709
|
-
this.logArmingLock(
|
|
1979
|
+
this.logArmingLock("night", value);
|
|
1710
1980
|
callback(null);
|
|
1711
1981
|
};
|
|
1712
1982
|
|
|
1713
1983
|
// Mode Switches
|
|
1714
1984
|
SecuritySystem.prototype.resetModeSwitches = function () {
|
|
1715
|
-
const modeHomeSwitchCharacteristicOn =
|
|
1716
|
-
|
|
1717
|
-
const
|
|
1718
|
-
|
|
1719
|
-
const
|
|
1720
|
-
|
|
1985
|
+
const modeHomeSwitchCharacteristicOn =
|
|
1986
|
+
this.modeHomeSwitchService.getCharacteristic(Characteristic.On);
|
|
1987
|
+
const modeAwaySwitchCharacteristicOn =
|
|
1988
|
+
this.modeAwaySwitchService.getCharacteristic(Characteristic.On);
|
|
1989
|
+
const modeNightSwitchCharacteristicOn =
|
|
1990
|
+
this.modeNightSwitchService.getCharacteristic(Characteristic.On);
|
|
1991
|
+
const modeOffSwitchCharacteristicOn =
|
|
1992
|
+
this.modeOffSwitchService.getCharacteristic(Characteristic.On);
|
|
1993
|
+
const modeAwayExtendedSwitchCharacteristicOn =
|
|
1994
|
+
this.modeAwayExtendedSwitchService.getCharacteristic(Characteristic.On);
|
|
1995
|
+
const modePauseSwitchCharacteristicOn =
|
|
1996
|
+
this.modePauseSwitchService.getCharacteristic(Characteristic.On);
|
|
1721
1997
|
|
|
1722
1998
|
if (modeHomeSwitchCharacteristicOn.value) {
|
|
1723
1999
|
modeHomeSwitchCharacteristicOn.updateValue(false);
|
|
1724
|
-
this.log.debug(
|
|
2000
|
+
this.log.debug("Mode Home Switch (Off)");
|
|
1725
2001
|
}
|
|
1726
2002
|
|
|
1727
2003
|
if (modeAwaySwitchCharacteristicOn.value) {
|
|
1728
2004
|
modeAwaySwitchCharacteristicOn.updateValue(false);
|
|
1729
|
-
this.log.debug(
|
|
2005
|
+
this.log.debug("Mode Away Switch (Off)");
|
|
1730
2006
|
}
|
|
1731
2007
|
|
|
1732
2008
|
if (modeNightSwitchCharacteristicOn.value) {
|
|
1733
2009
|
modeNightSwitchCharacteristicOn.updateValue(false);
|
|
1734
|
-
this.log.debug(
|
|
2010
|
+
this.log.debug("Mode Night Switch (Off)");
|
|
1735
2011
|
}
|
|
1736
2012
|
|
|
1737
2013
|
if (modeOffSwitchCharacteristicOn.value) {
|
|
1738
2014
|
modeOffSwitchCharacteristicOn.updateValue(false);
|
|
1739
|
-
this.log.debug(
|
|
2015
|
+
this.log.debug("Mode Off Switch (Off)");
|
|
1740
2016
|
}
|
|
1741
2017
|
|
|
1742
2018
|
if (modeAwayExtendedSwitchCharacteristicOn.value) {
|
|
1743
2019
|
modeAwayExtendedSwitchCharacteristicOn.updateValue(false);
|
|
1744
|
-
this.log.debug(
|
|
2020
|
+
this.log.debug("Mode Away Extended Switch (Off)");
|
|
1745
2021
|
}
|
|
1746
2022
|
|
|
1747
2023
|
if (modePauseSwitchCharacteristicOn.value) {
|
|
1748
2024
|
modePauseSwitchCharacteristicOn.updateValue(false);
|
|
1749
|
-
this.log.debug(
|
|
2025
|
+
this.log.debug("Mode Pause Switch (Off)");
|
|
1750
2026
|
}
|
|
1751
2027
|
};
|
|
1752
2028
|
|
|
@@ -1754,28 +2030,30 @@ SecuritySystem.prototype.updateModeSwitches = function () {
|
|
|
1754
2030
|
switch (this.targetState) {
|
|
1755
2031
|
case Characteristic.SecuritySystemTargetState.STAY_ARM:
|
|
1756
2032
|
this.modeHomeSwitchService.updateCharacteristic(Characteristic.On, true);
|
|
1757
|
-
this.log.debug(
|
|
2033
|
+
this.log.debug("Mode Home Switch (On)");
|
|
1758
2034
|
break;
|
|
1759
2035
|
|
|
1760
2036
|
case Characteristic.SecuritySystemTargetState.AWAY_ARM:
|
|
1761
2037
|
this.modeAwaySwitchService.updateCharacteristic(Characteristic.On, true);
|
|
1762
|
-
this.log.debug(
|
|
2038
|
+
this.log.debug("Mode Away Switch (On)");
|
|
1763
2039
|
break;
|
|
1764
2040
|
|
|
1765
2041
|
case Characteristic.SecuritySystemTargetState.NIGHT_ARM:
|
|
1766
2042
|
this.modeNightSwitchService.updateCharacteristic(Characteristic.On, true);
|
|
1767
|
-
this.log.debug(
|
|
2043
|
+
this.log.debug("Mode Night Switch (On)");
|
|
1768
2044
|
break;
|
|
1769
2045
|
|
|
1770
2046
|
case Characteristic.SecuritySystemTargetState.DISARM:
|
|
1771
2047
|
this.modeOffSwitchService.updateCharacteristic(Characteristic.On, true);
|
|
1772
|
-
this.log.debug(
|
|
2048
|
+
this.log.debug("Mode Off Switch (On)");
|
|
1773
2049
|
break;
|
|
1774
2050
|
}
|
|
1775
2051
|
};
|
|
1776
2052
|
|
|
1777
2053
|
SecuritySystem.prototype.getModeHomeSwitch = function (callback) {
|
|
1778
|
-
const value = this.modeHomeSwitchService.getCharacteristic(
|
|
2054
|
+
const value = this.modeHomeSwitchService.getCharacteristic(
|
|
2055
|
+
Characteristic.On
|
|
2056
|
+
).value;
|
|
1779
2057
|
callback(null, value);
|
|
1780
2058
|
};
|
|
1781
2059
|
|
|
@@ -1785,12 +2063,19 @@ SecuritySystem.prototype.setModeHomeSwitch = function (value, callback) {
|
|
|
1785
2063
|
return;
|
|
1786
2064
|
}
|
|
1787
2065
|
|
|
1788
|
-
this.updateTargetState(
|
|
2066
|
+
this.updateTargetState(
|
|
2067
|
+
Characteristic.SecuritySystemTargetState.STAY_ARM,
|
|
2068
|
+
originTypes.INTERNAL,
|
|
2069
|
+
true,
|
|
2070
|
+
null
|
|
2071
|
+
);
|
|
1789
2072
|
callback(null);
|
|
1790
2073
|
};
|
|
1791
2074
|
|
|
1792
2075
|
SecuritySystem.prototype.getModeAwaySwitch = function (callback) {
|
|
1793
|
-
const value = this.modeAwaySwitchService.getCharacteristic(
|
|
2076
|
+
const value = this.modeAwaySwitchService.getCharacteristic(
|
|
2077
|
+
Characteristic.On
|
|
2078
|
+
).value;
|
|
1794
2079
|
callback(null, value);
|
|
1795
2080
|
};
|
|
1796
2081
|
|
|
@@ -1800,12 +2085,19 @@ SecuritySystem.prototype.setModeAwaySwitch = function (value, callback) {
|
|
|
1800
2085
|
return;
|
|
1801
2086
|
}
|
|
1802
2087
|
|
|
1803
|
-
this.updateTargetState(
|
|
2088
|
+
this.updateTargetState(
|
|
2089
|
+
Characteristic.SecuritySystemTargetState.AWAY_ARM,
|
|
2090
|
+
originTypes.INTERNAL,
|
|
2091
|
+
true,
|
|
2092
|
+
null
|
|
2093
|
+
);
|
|
1804
2094
|
callback(null);
|
|
1805
2095
|
};
|
|
1806
2096
|
|
|
1807
2097
|
SecuritySystem.prototype.getModeNightSwitch = function (callback) {
|
|
1808
|
-
const value = this.modeNightSwitchService.getCharacteristic(
|
|
2098
|
+
const value = this.modeNightSwitchService.getCharacteristic(
|
|
2099
|
+
Characteristic.On
|
|
2100
|
+
).value;
|
|
1809
2101
|
callback(null, value);
|
|
1810
2102
|
};
|
|
1811
2103
|
|
|
@@ -1815,12 +2107,19 @@ SecuritySystem.prototype.setModeNightSwitch = function (value, callback) {
|
|
|
1815
2107
|
return;
|
|
1816
2108
|
}
|
|
1817
2109
|
|
|
1818
|
-
this.updateTargetState(
|
|
2110
|
+
this.updateTargetState(
|
|
2111
|
+
Characteristic.SecuritySystemTargetState.NIGHT_ARM,
|
|
2112
|
+
originTypes.INTERNAL,
|
|
2113
|
+
true,
|
|
2114
|
+
null
|
|
2115
|
+
);
|
|
1819
2116
|
callback(null);
|
|
1820
2117
|
};
|
|
1821
2118
|
|
|
1822
2119
|
SecuritySystem.prototype.getModeOffSwitch = function (callback) {
|
|
1823
|
-
const value = this.modeOffSwitchService.getCharacteristic(
|
|
2120
|
+
const value = this.modeOffSwitchService.getCharacteristic(
|
|
2121
|
+
Characteristic.On
|
|
2122
|
+
).value;
|
|
1824
2123
|
callback(null, value);
|
|
1825
2124
|
};
|
|
1826
2125
|
|
|
@@ -1830,111 +2129,167 @@ SecuritySystem.prototype.setModeOffSwitch = function (value, callback) {
|
|
|
1830
2129
|
return;
|
|
1831
2130
|
}
|
|
1832
2131
|
|
|
1833
|
-
this.updateTargetState(
|
|
2132
|
+
this.updateTargetState(
|
|
2133
|
+
Characteristic.SecuritySystemTargetState.DISARM,
|
|
2134
|
+
originTypes.INTERNAL,
|
|
2135
|
+
true,
|
|
2136
|
+
null
|
|
2137
|
+
);
|
|
1834
2138
|
callback(null);
|
|
1835
2139
|
};
|
|
1836
2140
|
|
|
1837
2141
|
SecuritySystem.prototype.getModeAwayExtendedSwitch = function (callback) {
|
|
1838
|
-
const value = this.modeAwayExtendedSwitchService.getCharacteristic(
|
|
2142
|
+
const value = this.modeAwayExtendedSwitchService.getCharacteristic(
|
|
2143
|
+
Characteristic.On
|
|
2144
|
+
).value;
|
|
1839
2145
|
callback(null, value);
|
|
1840
2146
|
};
|
|
1841
2147
|
|
|
1842
|
-
SecuritySystem.prototype.setModeAwayExtendedSwitch = function (
|
|
2148
|
+
SecuritySystem.prototype.setModeAwayExtendedSwitch = function (
|
|
2149
|
+
value,
|
|
2150
|
+
callback
|
|
2151
|
+
) {
|
|
1843
2152
|
if (value === false) {
|
|
1844
2153
|
callback(-70412, false);
|
|
1845
2154
|
return;
|
|
1846
2155
|
}
|
|
1847
2156
|
|
|
1848
|
-
this.updateTargetState(
|
|
2157
|
+
this.updateTargetState(
|
|
2158
|
+
Characteristic.SecuritySystemTargetState.AWAY_ARM,
|
|
2159
|
+
originTypes.INTERNAL,
|
|
2160
|
+
true,
|
|
2161
|
+
null
|
|
2162
|
+
);
|
|
1849
2163
|
callback(null);
|
|
1850
2164
|
};
|
|
1851
2165
|
|
|
1852
2166
|
SecuritySystem.prototype.getModePauseSwitch = function (callback) {
|
|
1853
|
-
const value = this.modePauseSwitchService.getCharacteristic(
|
|
2167
|
+
const value = this.modePauseSwitchService.getCharacteristic(
|
|
2168
|
+
Characteristic.On
|
|
2169
|
+
).value;
|
|
1854
2170
|
callback(null, value);
|
|
1855
2171
|
};
|
|
1856
2172
|
|
|
1857
2173
|
SecuritySystem.prototype.setModePauseSwitch = function (value, callback) {
|
|
1858
|
-
if (
|
|
1859
|
-
this.
|
|
2174
|
+
if (
|
|
2175
|
+
this.currentState ===
|
|
2176
|
+
Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED
|
|
2177
|
+
) {
|
|
2178
|
+
this.log.warn("Mode pause (Alarm is triggered)");
|
|
1860
2179
|
callback(-70412, false);
|
|
1861
2180
|
return;
|
|
1862
2181
|
}
|
|
1863
2182
|
|
|
1864
2183
|
if (value) {
|
|
1865
|
-
if (
|
|
1866
|
-
this.
|
|
2184
|
+
if (
|
|
2185
|
+
this.currentState === Characteristic.SecuritySystemCurrentState.DISARMED
|
|
2186
|
+
) {
|
|
2187
|
+
this.log.warn("Mode pause (Not armed)");
|
|
1867
2188
|
callback(-70412, false);
|
|
1868
2189
|
return;
|
|
1869
2190
|
}
|
|
1870
2191
|
|
|
1871
|
-
this.log.info(
|
|
2192
|
+
this.log.info("Mode pause (Started)");
|
|
1872
2193
|
|
|
1873
2194
|
this.pausedCurrentState = this.currentState;
|
|
1874
|
-
this.updateTargetState(
|
|
2195
|
+
this.updateTargetState(
|
|
2196
|
+
Characteristic.SecuritySystemTargetState.DISARM,
|
|
2197
|
+
originTypes.INTERNAL,
|
|
2198
|
+
true,
|
|
2199
|
+
null
|
|
2200
|
+
);
|
|
1875
2201
|
|
|
1876
2202
|
// Check if time is set to unlimited
|
|
1877
2203
|
if (options.pauseMinutes !== 0) {
|
|
1878
2204
|
this.pauseTimeout = setTimeout(() => {
|
|
1879
|
-
this.log.info(
|
|
1880
|
-
this.updateTargetState(
|
|
2205
|
+
this.log.info("Mode pause (Finished)");
|
|
2206
|
+
this.updateTargetState(
|
|
2207
|
+
this.pausedCurrentState,
|
|
2208
|
+
originTypes.INTERNAL,
|
|
2209
|
+
true,
|
|
2210
|
+
null
|
|
2211
|
+
);
|
|
1881
2212
|
}, options.pauseMinutes * 60 * 1000);
|
|
1882
2213
|
}
|
|
1883
|
-
}
|
|
1884
|
-
|
|
1885
|
-
this.log.info('Mode pause (Cancelled)');
|
|
2214
|
+
} else {
|
|
2215
|
+
this.log.info("Mode pause (Cancelled)");
|
|
1886
2216
|
|
|
1887
2217
|
if (this.pauseTimeout !== null) {
|
|
1888
2218
|
clearTimeout(this.pauseTimeout);
|
|
1889
2219
|
this.pauseTimeout = null;
|
|
1890
2220
|
}
|
|
1891
2221
|
|
|
1892
|
-
this.updateTargetState(
|
|
2222
|
+
this.updateTargetState(
|
|
2223
|
+
this.pausedCurrentState,
|
|
2224
|
+
originTypes.INTERNAL,
|
|
2225
|
+
true,
|
|
2226
|
+
null
|
|
2227
|
+
);
|
|
1893
2228
|
}
|
|
1894
2229
|
|
|
1895
2230
|
callback(null);
|
|
1896
2231
|
};
|
|
1897
2232
|
|
|
1898
2233
|
SecuritySystem.prototype.getAudioSwitch = function (callback) {
|
|
1899
|
-
const value = this.audioSwitchService.getCharacteristic(
|
|
2234
|
+
const value = this.audioSwitchService.getCharacteristic(
|
|
2235
|
+
Characteristic.On
|
|
2236
|
+
).value;
|
|
1900
2237
|
callback(null, value);
|
|
1901
2238
|
};
|
|
1902
2239
|
|
|
1903
2240
|
SecuritySystem.prototype.setAudioSwitch = function (value, callback) {
|
|
1904
|
-
this.log.info(`Audio (${value ?
|
|
2241
|
+
this.log.info(`Audio (${value ? "Enabled" : "Disabled"})`);
|
|
1905
2242
|
callback(null);
|
|
1906
2243
|
};
|
|
1907
2244
|
|
|
1908
2245
|
// Siren Tripped Motion Sensor
|
|
1909
2246
|
SecuritySystem.prototype.getSirenTrippedMotionDetected = function (callback) {
|
|
1910
|
-
const value = this.sirenTrippedMotionSensorService.getCharacteristic(
|
|
2247
|
+
const value = this.sirenTrippedMotionSensorService.getCharacteristic(
|
|
2248
|
+
Characteristic.MotionDetected
|
|
2249
|
+
).value;
|
|
1911
2250
|
callback(null, value);
|
|
1912
2251
|
};
|
|
1913
2252
|
|
|
1914
2253
|
SecuritySystem.prototype.updateSirenTrippedMotionDetected = function () {
|
|
1915
|
-
this.sirenTrippedMotionSensorService.updateCharacteristic(
|
|
2254
|
+
this.sirenTrippedMotionSensorService.updateCharacteristic(
|
|
2255
|
+
Characteristic.MotionDetected,
|
|
2256
|
+
true
|
|
2257
|
+
);
|
|
1916
2258
|
|
|
1917
2259
|
setTimeout(() => {
|
|
1918
|
-
this.sirenTrippedMotionSensorService.updateCharacteristic(
|
|
2260
|
+
this.sirenTrippedMotionSensorService.updateCharacteristic(
|
|
2261
|
+
Characteristic.MotionDetected,
|
|
2262
|
+
false
|
|
2263
|
+
);
|
|
1919
2264
|
}, 750);
|
|
1920
2265
|
};
|
|
1921
2266
|
|
|
1922
2267
|
// Siren Triggered Motion Sensor
|
|
1923
2268
|
SecuritySystem.prototype.getSirenTriggeredMotionDetected = function (callback) {
|
|
1924
|
-
const value = this.sirenTriggeredMotionSensorService.getCharacteristic(
|
|
2269
|
+
const value = this.sirenTriggeredMotionSensorService.getCharacteristic(
|
|
2270
|
+
Characteristic.MotionDetected
|
|
2271
|
+
).value;
|
|
1925
2272
|
callback(null, value);
|
|
1926
2273
|
};
|
|
1927
2274
|
|
|
1928
2275
|
SecuritySystem.prototype.updateSirenTriggeredMotionDetected = function () {
|
|
1929
|
-
this.sirenTriggeredMotionSensorService.updateCharacteristic(
|
|
2276
|
+
this.sirenTriggeredMotionSensorService.updateCharacteristic(
|
|
2277
|
+
Characteristic.MotionDetected,
|
|
2278
|
+
true
|
|
2279
|
+
);
|
|
1930
2280
|
|
|
1931
2281
|
setTimeout(() => {
|
|
1932
|
-
this.sirenTriggeredMotionSensorService.updateCharacteristic(
|
|
2282
|
+
this.sirenTriggeredMotionSensorService.updateCharacteristic(
|
|
2283
|
+
Characteristic.MotionDetected,
|
|
2284
|
+
false
|
|
2285
|
+
);
|
|
1933
2286
|
}, 750);
|
|
1934
2287
|
};
|
|
1935
2288
|
|
|
1936
2289
|
// Siren Reset Motion Sensor
|
|
1937
2290
|
SecuritySystem.prototype.getSirenResetMotionDetected = function (callback) {
|
|
1938
|
-
const value = this.sirenResetMotionSensorService.getCharacteristic(
|
|
2291
|
+
const value = this.sirenResetMotionSensorService.getCharacteristic(
|
|
2292
|
+
Characteristic.MotionDetected
|
|
2293
|
+
).value;
|
|
1939
2294
|
callback(null, value);
|
|
1940
2295
|
};
|