homebridge-securitysystem 8.3.0-beta.1 → 8.3.0-beta.3

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.
@@ -24,3 +24,4 @@ jobs:
24
24
  stale-pr-message: "This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in a few days if no further activity occurs. Thank you for your contributions."
25
25
  stale-issue-label: "stale"
26
26
  stale-pr-label: "stale"
27
+ exempt-issue-labels: "feature,enhancement"
@@ -207,7 +207,7 @@
207
207
  "required": false,
208
208
  "minimum": 0
209
209
  },
210
- "away_extended_trigger_seconds": {
210
+ "mode_away_extended_switch_trigger_seconds": {
211
211
  "title": "Away Extended Delay Trigger Seconds",
212
212
  "description": "",
213
213
  "type": "integer",
@@ -311,14 +311,14 @@
311
311
  "required": false,
312
312
  "minimum": 0
313
313
  },
314
- "siren_sensor": {
314
+ "triggered_sensor": {
315
315
  "title": "Show Triggered Sensor",
316
316
  "description": "Adds a sensor that triggers multiple times when the security system has been triggered.",
317
317
  "type": "boolean",
318
318
  "default": false,
319
319
  "required": false
320
320
  },
321
- "siren_sensor_seconds": {
321
+ "triggered_sensor_seconds": {
322
322
  "title": "Triggered Sensor Seconds",
323
323
  "description": "",
324
324
  "type": "integer",
@@ -383,21 +383,21 @@
383
383
  "default": false,
384
384
  "required": false
385
385
  },
386
- "siren_switch": {
386
+ "trip_switch": {
387
387
  "title": "Show Trip Switch",
388
388
  "description": "Adds a global switch that will trip the security system.",
389
389
  "type": "boolean",
390
390
  "default": false,
391
391
  "required": false
392
392
  },
393
- "siren_override_switch": {
393
+ "trip_override_switch": {
394
394
  "title": "Show Trip Override Switch",
395
395
  "description": "Adds a special switch that will trigger the security system bypassing the conditions set.",
396
396
  "type": "boolean",
397
397
  "default": false,
398
398
  "required": false
399
399
  },
400
- "siren_mode_switches": {
400
+ "trip_mode_switches": {
401
401
  "title": "Show Trip Mode Switches",
402
402
  "description": "Adds switches that will trigger the security system when their mode is set.",
403
403
  "type": "boolean",
@@ -744,7 +744,7 @@
744
744
  "flex-direction": "row",
745
745
  "items": [
746
746
  "mode_away_extended_switch",
747
- "away_extended_trigger_seconds"
747
+ "mode_away_extended_switch_trigger_seconds"
748
748
  ]
749
749
  },
750
750
  {
@@ -756,9 +756,9 @@
756
756
  },
757
757
  "arming_lock_switch",
758
758
  "arming_lock_switches",
759
- "siren_switch",
760
- "siren_override_switch",
761
- "siren_mode_switches",
759
+ "trip_switch",
760
+ "trip_override_switch",
761
+ "trip_mode_switches",
762
762
  "audio_switch"
763
763
  ]
764
764
  },
@@ -771,13 +771,13 @@
771
771
  "items": [
772
772
  "arming_sensor",
773
773
  "tripped_sensor",
774
- "siren_sensor",
774
+ "triggered_sensor",
775
775
  {
776
776
  "type": "div",
777
777
  "displayFlex": true,
778
778
  "flex-flow": "row wrap",
779
779
  "flex-direction": "row",
780
- "items": ["tripped_sensor_seconds", "siren_sensor_seconds"]
780
+ "items": ["tripped_sensor_seconds", "triggered_sensor_seconds"]
781
781
  },
782
782
  "reset_sensor"
783
783
  ]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-securitysystem",
3
3
  "displayName": "Homebridge Security System",
4
- "version": "8.3.0-beta.1",
4
+ "version": "8.3.0-beta.3",
5
5
  "description": "Homebridge plugin that creates a security system accessory that can be triggered by HomeKit sensors.",
6
6
  "main": "src/index.js",
7
7
  "scripts": {
package/src/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ // WARNING:
2
+ // I didn't know about TypeScript when I wrote this code. I'm sorry.
3
+
1
4
  const fs = require("fs");
2
5
  const path = require("path");
3
6
  const storage = require("node-persist");
@@ -13,7 +16,7 @@ const HK_NOT_ALLOWED_IN_CURRENT_STATE = -70412;
13
16
 
14
17
  const originTypes = {
15
18
  REGULAR_SWITCH: 0,
16
- SPECIAL_SWITCH: 1,
19
+ OVERRIDE_SWITCH: 1,
17
20
  INTERNAL: 3,
18
21
  EXTERNAL: 4,
19
22
  };
@@ -652,7 +655,7 @@ SecuritySystem.prototype.load = async function () {
652
655
  this.currentState
653
656
  );
654
657
 
655
- this.handleTargetStateChange(false);
658
+ this.handleTargetStateChange(originTypes.INTERNAL);
656
659
 
657
660
  // Log
658
661
  this.logMode("Current", this.currentState);
@@ -697,10 +700,6 @@ SecuritySystem.prototype.identify = function (callback) {
697
700
 
698
701
  // Services
699
702
  SecuritySystem.prototype.addArmingMotionSensor = function () {
700
- if (options.armingMotionSensor === false) {
701
- return;
702
- }
703
-
704
703
  this.armingMotionSensorService = new Service.MotionSensor(
705
704
  "Arming",
706
705
  "arming-motion-sensor"
@@ -715,7 +714,9 @@ SecuritySystem.prototype.addArmingMotionSensor = function () {
715
714
  .getCharacteristic(Characteristic.MotionDetected)
716
715
  .on("get", this.getArmingMotionDetected.bind(this));
717
716
 
718
- this.services.push(this.armingMotionSensorService);
717
+ if (options.armingMotionSensor) {
718
+ this.services.push(this.armingMotionSensorService);
719
+ }
719
720
  };
720
721
 
721
722
  // Security system
@@ -814,26 +815,42 @@ SecuritySystem.prototype.setCurrentState = function (state, origin) {
814
815
  this.logMode("Current", state);
815
816
  }
816
817
 
817
- this.handleCurrentStateChange(state, origin);
818
+ this.handleCurrentStateChange(origin);
818
819
  this.save();
819
820
  };
820
821
 
821
- SecuritySystem.prototype.handleCurrentStateChange = function (state, origin) {
822
- // Commands
823
- this.executeCommand("current", state, origin);
824
-
825
- // Webhooks
826
- this.sendWebhookEvent("current", state, origin);
827
-
822
+ SecuritySystem.prototype.handleCurrentStateChange = function (origin) {
828
823
  const isCurrentStateAlarmTriggered =
829
- state === Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERE;
824
+ this.currentState ===
825
+ Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED;
830
826
 
831
827
  if (isCurrentStateAlarmTriggered) {
832
828
  this.handleTriggeredState();
829
+
830
+ if (options.testMode) {
831
+ return;
832
+ }
833
833
  }
834
+
835
+ // Reset trip switches if on
836
+ this.resetTripSwitches();
837
+
838
+ // Commands
839
+ this.executeCommand("current", this.currentState, origin);
840
+
841
+ // Webhooks
842
+ this.sendWebhookEvent("current", this.currentState, origin);
834
843
  };
835
844
 
836
845
  SecuritySystem.prototype.handleTriggeredState = function () {
846
+ // Clear tripped interval
847
+ if (this.trippedMotionSensorInterval !== null) {
848
+ clearInterval(this.trippedMotionSensorInterval);
849
+
850
+ this.trippedMotionSensorInterval = null;
851
+ this.log.debug("Tripped interval (Cleared)");
852
+ }
853
+
837
854
  // Trigger triggered motion sensor
838
855
  // every configured seconds
839
856
  this.triggeredMotionSensorInterval = setInterval(() => {
@@ -855,8 +872,7 @@ SecuritySystem.prototype.handleTriggeredState = function () {
855
872
  }
856
873
 
857
874
  // Normal flow
858
- this.handleTargetStateChange(false);
859
- this.setCurrentState(this.targetState, false);
875
+ this.setCurrentState(this.targetState, originTypes.EXTERNAL);
860
876
  }, options.resetMinutes * 60 * 1000);
861
877
  };
862
878
 
@@ -953,10 +969,10 @@ SecuritySystem.prototype.resetTimers = function () {
953
969
  }
954
970
  };
955
971
 
956
- SecuritySystem.prototype.handleTargetStateChange = function (
957
- origin,
958
- alarmTriggered
959
- ) {
972
+ SecuritySystem.prototype.handleTargetStateChange = function (origin) {
973
+ // Clear arming timeout
974
+ clearTimeout(this.armTimeout);
975
+
960
976
  // Reset double-knock
961
977
  this.isKnocked = false;
962
978
 
@@ -972,10 +988,12 @@ SecuritySystem.prototype.handleTargetStateChange = function (
972
988
 
973
989
  // Trigger reset sensor for mode
974
990
  // change in triggered state
975
- if (alarmTriggered) {
976
- if (isCurrentStateAlarmTriggered) {
977
- this.triggerResetSensor();
978
- }
991
+ const isCurrentStateAlarmTriggered =
992
+ this.currentState ===
993
+ Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED;
994
+
995
+ if (isCurrentStateAlarmTriggered) {
996
+ this.triggerResetSensor();
979
997
 
980
998
  // Keep characteristic & switches on
981
999
  return;
@@ -1052,11 +1070,11 @@ SecuritySystem.prototype.updateTargetState = function (
1052
1070
  );
1053
1071
  }
1054
1072
 
1073
+ // Handle mode change
1074
+ this.handleTargetStateChange(origin);
1075
+
1055
1076
  // Check if current state is already set
1056
1077
  if (state === this.currentState) {
1057
- // Clear arming timeout
1058
- clearTimeout(this.armTimeout);
1059
-
1060
1078
  // Run set current state logic again
1061
1079
  this.setCurrentState(state, origin);
1062
1080
 
@@ -1067,9 +1085,6 @@ SecuritySystem.prototype.updateTargetState = function (
1067
1085
  return false;
1068
1086
  }
1069
1087
 
1070
- // Handle mode change
1071
- this.handleTargetStateChange(origin, false);
1072
-
1073
1088
  // Set arming delay
1074
1089
  let armSeconds = 0;
1075
1090
 
@@ -1171,9 +1186,9 @@ SecuritySystem.prototype.updateTripSwitch = function (
1171
1186
 
1172
1187
  // Check if the security system is disarmed
1173
1188
  const isNotOverridingOff = options.overrideOff === false;
1174
- const isNotSpecialSwitch = origin !== originTypes.SPECIAL_SWITCH;
1189
+ const isNotOverrideSwitch = origin !== originTypes.OVERRIDE_SWITCH;
1175
1190
 
1176
- if (isCurrentStateDisarmed && isNotOverridingOff && isNotSpecialSwitch) {
1191
+ if (isCurrentStateDisarmed && isNotOverridingOff && isNotOverrideSwitch) {
1177
1192
  this.log.warn("Trip Switch (Not armed)");
1178
1193
 
1179
1194
  if (callback !== null) {
@@ -1201,14 +1216,14 @@ SecuritySystem.prototype.updateTripSwitch = function (
1201
1216
  });
1202
1217
 
1203
1218
  const isFirstKnock = this.isKnocked === false;
1204
- const isSpecialSwitch = origin === originTypes.SPECIAL_SWITCH;
1219
+ const isOverrideSwitch = origin === originTypes.OVERRIDE_SWITCH;
1205
1220
  const isStateKnockable = doubleKnockStates.includes(this.currentState);
1206
1221
 
1207
1222
  if (
1208
1223
  value &&
1209
1224
  isStateKnockable &&
1210
1225
  isFirstKnock &&
1211
- isSpecialSwitch === false
1226
+ isOverrideSwitch === false
1212
1227
  ) {
1213
1228
  this.log.warn("Trip Switch (Knock)");
1214
1229
  this.isKnocked = true;
@@ -1316,10 +1331,10 @@ SecuritySystem.prototype.updateTripSwitch = function (
1316
1331
  modeAwayExtendedSwitchCharacteristicOn.value;
1317
1332
 
1318
1333
  if (
1319
- options.isValueSet(options.awayExtendedTriggerSeconds) &&
1334
+ options.isValueSet(options.modeAwayExtendedSwitchTriggerSeconds) &&
1320
1335
  modeAwayExtendedSwitchCharacteristicOnValue
1321
1336
  ) {
1322
- triggerSeconds = options.awayExtendedTriggerSeconds;
1337
+ triggerSeconds = options.modeAwayExtendedSwitchTriggerSeconds;
1323
1338
  } else if (options.isValueSet(options.awayTriggerSeconds)) {
1324
1339
  triggerSeconds = options.awayTriggerSeconds;
1325
1340
  }
@@ -1506,10 +1521,9 @@ SecuritySystem.prototype.startServer = async function () {
1506
1521
  return;
1507
1522
  }
1508
1523
 
1509
- this.handleTargetStateChange(true);
1510
1524
  this.setCurrentState(
1511
1525
  Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED,
1512
- true
1526
+ originTypes.EXTERNAL
1513
1527
  );
1514
1528
  }
1515
1529
 
@@ -1987,7 +2001,7 @@ SecuritySystem.prototype.getTripOverrideSwitch = function (callback) {
1987
2001
 
1988
2002
  SecuritySystem.prototype.setTripOverrideSwitch = function (value, callback) {
1989
2003
  this.log.info(`Trip Override Switch (${value ? "On" : "Off"})`);
1990
- this.updateTripSwitch(value, originTypes.SPECIAL_SWITCH, false, callback);
2004
+ this.updateTripSwitch(value, originTypes.OVERRIDE_SWITCH, false, callback);
1991
2005
  };
1992
2006
 
1993
2007
  SecuritySystem.prototype.triggerIfModeSet = function (
@@ -2390,12 +2404,7 @@ SecuritySystem.prototype.setModePauseSwitch = function (value, callback) {
2390
2404
  if (options.pauseMinutes !== 0) {
2391
2405
  this.pauseTimeout = setTimeout(() => {
2392
2406
  this.log.info("Mode pause (Finished)");
2393
- this.updateTargetState(
2394
- this.pausedCurrentState,
2395
- originTypes.INTERNAL,
2396
- true,
2397
- null
2398
- );
2407
+ this.Atate(this.pausedCurrentState, originTypes.INTERNAL, true, null);
2399
2408
  }, options.pauseMinutes * 60 * 1000);
2400
2409
  }
2401
2410
  } else {
@@ -10,7 +10,6 @@ const options = {
10
10
  options.defaultMode = config.default_mode;
11
11
  options.armSeconds = config.arm_seconds;
12
12
  options.triggerSeconds = config.trigger_seconds;
13
- options.pauseMinutes = config.pause_minutes;
14
13
  options.resetMinutes = config.reset_minutes;
15
14
  options.saveState = config.save_state;
16
15
  options.proxyMode = config.proxy_mode;
@@ -35,30 +34,33 @@ const options = {
35
34
 
36
35
  // END: Names
37
36
 
37
+ // Main settings
38
38
  options.logDirectory = config.log_directory;
39
39
  options.overrideOff = config.override_off;
40
40
  options.resetOffFlow = config.reset_off_flow;
41
41
  options.disabledModes = config.disabled_modes;
42
42
 
43
+ // Arming settings
43
44
  options.homeArmSeconds = config.home_arm_seconds;
44
45
  options.awayArmSeconds = config.away_arm_seconds;
45
46
  options.nightArmSeconds = config.night_arm_seconds;
46
47
 
48
+ // Trigger settings
47
49
  options.homeTriggerSeconds = config.home_trigger_seconds;
48
50
  options.awayTriggerSeconds = config.away_trigger_seconds;
49
51
  options.nightTriggerSeconds = config.night_trigger_seconds;
50
52
 
51
- options.awayExtendedTriggerSeconds = config.away_extended_trigger_seconds;
53
+ // Trip switches
54
+ options.tripSwitch = config.trip_switch || config.siren_switch;
55
+ options.tripOverrideSwitch =
56
+ config.trip_override_switch || config.siren_override_switch;
57
+ options.tripModeSwitches =
58
+ config.trip_mode_switches || config.siren_mode_switches;
52
59
 
53
60
  // Arming lock switch
54
61
  options.armingLockSwitch = config.arming_lock_switch;
55
62
  options.armingLockSwitches = config.arming_lock_switches;
56
63
 
57
- // Trip switches
58
- options.tripSwitch = config.siren_switch;
59
- options.tripOverrideSwitch = config.siren_override_switch;
60
- options.tripModeSwitches = config.siren_mode_switches;
61
-
62
64
  // Arming motion sensor
63
65
  options.armingMotionSensor = config.arming_sensor;
64
66
 
@@ -67,17 +69,28 @@ const options = {
67
69
  options.trippedMotionSensorSeconds = config.tripped_sensor_seconds;
68
70
 
69
71
  // Triggered motion sensor
70
- options.triggeredMotionSensor = config.siren_sensor;
71
- options.triggeredMotionSensorSeconds = config.siren_sensor_seconds;
72
+ options.triggeredMotionSensor =
73
+ config.triggered_sensor || config.siren_sensor;
74
+ options.triggeredMotionSensorSeconds =
75
+ config.triggered_sensor_seconds || config.siren_sensor_seconds;
72
76
 
73
77
  // Reset motion sensor
74
78
  options.resetSensor = config.reset_sensor;
75
79
 
76
80
  // Mode switches
77
81
  options.modeSwitches = config.mode_switches;
82
+
83
+ // Off switch
78
84
  options.modeOffSwitch = config.mode_off_switch;
85
+
86
+ // Pause switch
79
87
  options.modePauseSwitch = config.mode_pause_switch;
88
+ options.pauseMinutes = config.pause_minutes;
89
+
90
+ // Away extended switch
80
91
  options.modeAwayExtendedSwitch = config.mode_away_extended_switch;
92
+ options.modeAwayExtendedSwitchTriggerSeconds =
93
+ config.mode_away_extended_switch_trigger_seconds;
81
94
 
82
95
  // Double knock
83
96
  options.doubleKnock = config.double_knock;
@@ -88,8 +101,6 @@ const options = {
88
101
  options.awayDoubleKnockSeconds = config.away_double_knock_seconds;
89
102
  options.nightDoubleKnockSeconds = config.night_double_knock_seconds;
90
103
 
91
- options.audioSwitch = config.audio_switch;
92
-
93
104
  // Server
94
105
  options.serverPort = config.server_port;
95
106
  options.serverCode = config.server_code;
@@ -103,6 +114,9 @@ const options = {
103
114
  options.audioAlertLooped = config.audio_alert_looped;
104
115
  options.audioExtraVariables = config.audio_extra_variables;
105
116
 
117
+ // Audio switch
118
+ options.audioSwitch = config.audio_switch;
119
+
106
120
  // Commands
107
121
  options.commandTargetHome = config.command_target_home;
108
122
  options.commandTargetAway = config.command_target_away;