homebridge-securitysystem 6.2.1 → 6.3.0-beta.2

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.
@@ -333,6 +333,13 @@
333
333
  "de-DE"
334
334
  ]
335
335
  },
336
+ "audio_configuration": {
337
+ "title": "Audio Configuration",
338
+ "type": "string",
339
+ "required": false,
340
+ "default": "SDL_AUDIODRIVER=\"alsa\" AUDIODEV=\"hw:0,0\"",
341
+ "placeholder": "SDL_AUDIODRIVER=\"alsa\" AUDIODEV=\"hw:0,0\""
342
+ },
336
343
  "audio_path": {
337
344
  "title": "Custom Audio Path",
338
345
  "description": "Instructions will be created in this path.",
@@ -653,6 +660,7 @@
653
660
  "audio_language"
654
661
  ]
655
662
  },
663
+ "audio_configuration",
656
664
  {
657
665
  "type": "div",
658
666
  "displayFlex": true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-securitysystem",
3
3
  "displayName": "Homebridge Security System",
4
- "version": "6.2.1",
4
+ "version": "6.3.0-beta.2",
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": {
@@ -41,7 +41,8 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "express": "^4.17.1",
44
- "node-fetch": "^2.6.0",
44
+ "express-rate-limit": "^6.2.1",
45
+ "node-fetch": "^2.6.7",
45
46
  "node-persist": "^3.0.5"
46
47
  },
47
48
  "devDependencies": {
package/src/index.js CHANGED
@@ -4,6 +4,7 @@ const storage = require('node-persist');
4
4
  const { spawn } = require('child_process');
5
5
  const fetch = require('node-fetch');
6
6
  const express = require('express');
7
+ const rateLimit = require('express-rate-limit');
7
8
 
8
9
  const packageJson = require('../package.json');
9
10
  const options = require('./utils/options.js');
@@ -834,7 +835,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
834
835
  const isNotSpecialSwitch = origin !== originTypes.SPECIAL_SWITCH;
835
836
 
836
837
  if (isCurrentStateDisarmed && isNotOverridingOff && isNotSpecialSwitch) {
837
- this.log.warn('Siren (Not armed)');
838
+ this.log.warn('Siren Switch (Not armed)');
838
839
 
839
840
  if (callback !== null) {
840
841
  callback(-70412, false);
@@ -845,7 +846,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
845
846
 
846
847
  // Check if arming
847
848
  if (this.isArming) {
848
- this.log.warn('Siren (Still arming)');
849
+ this.log.warn('Siren Switch (Still arming)');
849
850
 
850
851
  if (callback !== null) {
851
852
  callback(-70412, false);
@@ -865,7 +866,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
865
866
  const isStateKnockable = doubleKnockStates.includes(this.currentState);
866
867
 
867
868
  if (value && isStateKnockable && isFirstKnock && isSpecialSwitch === false) {
868
- this.log.warn('Siren (Knock)');
869
+ this.log.warn('Siren Switch (Knock)');
869
870
  this.isKnocked = true;
870
871
 
871
872
  // Custom mode seconds
@@ -885,7 +886,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
885
886
  this.doubleKnockTimeout = null;
886
887
  this.isKnocked = false;
887
888
 
888
- this.log.info('Siren (Reset)');
889
+ this.log.info('Siren Switch (Reset)');
889
890
  }, doubleKnockSeconds * 1000);
890
891
 
891
892
  if (callback !== null) {
@@ -911,7 +912,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
911
912
  if (value) {
912
913
  // Already triggered
913
914
  if (isCurrentStateAlarmTriggered) {
914
- this.log.warn('Siren (Already triggered)');
915
+ this.log.warn('Siren Switch (Already triggered)');
915
916
 
916
917
  if (callback !== null) {
917
918
  callback(-70412, false);
@@ -922,7 +923,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
922
923
 
923
924
  // Already about to trigger
924
925
  if (this.triggerTimeout !== null) {
925
- this.log.warn('Siren (Already on)');
926
+ this.log.warn('Siren Switch (Already on)');
926
927
 
927
928
  if (callback !== null) {
928
929
  callback(-70412, false);
@@ -931,7 +932,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
931
932
  return false;
932
933
  }
933
934
 
934
- this.log.info('Siren (On)');
935
+ this.log.info('Siren Switch (On)');
935
936
 
936
937
  // Update siren tripped sensor
937
938
  if (options.trippedSensor) {
@@ -988,7 +989,7 @@ SecuritySystem.prototype.updateSiren = function (value, origin, stateChanged, ca
988
989
  }
989
990
  else {
990
991
  // Off
991
- this.log.info('Siren (Off)');
992
+ this.log.info('Siren Switch (Off)');
992
993
  this.stopAudio();
993
994
 
994
995
  if (isCurrentStateAlarmTriggered) {
@@ -1095,6 +1096,15 @@ SecuritySystem.prototype.sendResultResponse = function (res, sucess) {
1095
1096
  };
1096
1097
 
1097
1098
  SecuritySystem.prototype.startServer = async function () {
1099
+ const apiLimiter = rateLimit({
1100
+ windowMs: 1 * 60 * 1000,
1101
+ max: 100,
1102
+ standardHeaders: true,
1103
+ legacyHeaders: false
1104
+ });
1105
+
1106
+ app.use(apiLimiter);
1107
+
1098
1108
  app.get('/', (req, res) => {
1099
1109
  res.redirect('https://github.com/MiguelRipoll23/homebridge-securitysystem/wiki/Server');
1100
1110
  });
@@ -1294,11 +1304,19 @@ SecuritySystem.prototype.playAudio = async function (type, state) {
1294
1304
  }
1295
1305
 
1296
1306
  // Process
1297
- this.audioProcess = spawn('ffplay', commandArguments);
1298
- this.log.debug(`ffplay ${commandArguments.join(' ')}`);
1307
+ let command = '';
1308
+
1309
+ if (options.isValueSet(options.audioConfiguration)) {
1310
+ command += `${options.audioConfiguration} `;
1311
+ }
1312
+
1313
+ command += `ffplay ${commandArguments.join(' ')}`;
1314
+
1315
+ this.audioProcess = spawn(command, { shell: true });
1316
+ this.log.debug(command);
1299
1317
 
1300
1318
  this.audioProcess.on('error', data => {
1301
- // Check if command is missing
1319
+ // Check if ffmpeg is installed
1302
1320
  if (data !== null && data.toString().indexOf('ENOENT') > -1) {
1303
1321
  this.log.error('Unable to play sound, ffmpeg is not installed.');
1304
1322
  return;
@@ -1518,26 +1536,30 @@ SecuritySystem.prototype.setSirenOverrideSwitch = function (value, callback) {
1518
1536
  };
1519
1537
 
1520
1538
  SecuritySystem.prototype.resetSirenSwitches = function () {
1521
- const sirenOverrideOnCharacteristic = this.sirenOverrideSwitchService.getCharacteristic(Characteristic.On);
1522
-
1523
1539
  const sirenHomeOnCharacteristic = this.sirenHomeSwitchService.getCharacteristic(Characteristic.On);
1524
1540
  const sirenAwayOnCharacteristic = this.sirenAwaySwitchService.getCharacteristic(Characteristic.On);
1525
1541
  const sirenNightOnCharacteristic = this.sirenNightSwitchService.getCharacteristic(Characteristic.On);
1526
1542
 
1527
- if (sirenOverrideOnCharacteristic.value) {
1528
- sirenOverrideOnCharacteristic.updateValue(false);
1529
- }
1543
+ const sirenOverrideOnCharacteristic = this.sirenOverrideSwitchService.getCharacteristic(Characteristic.On);
1530
1544
 
1531
1545
  if (sirenHomeOnCharacteristic.value) {
1532
1546
  sirenHomeOnCharacteristic.updateValue(false);
1547
+ this.log.debug('Siren Home Switch (Off)');
1533
1548
  }
1534
1549
 
1535
1550
  if (sirenAwayOnCharacteristic.value) {
1536
1551
  sirenAwayOnCharacteristic.updateValue(false);
1552
+ this.log.debug('Siren Away Switch (Off)');
1537
1553
  }
1538
1554
 
1539
1555
  if (sirenNightOnCharacteristic.value) {
1540
1556
  sirenNightOnCharacteristic.updateValue(false);
1557
+ this.log.debug('Siren Night Switch (Off)');
1558
+ }
1559
+
1560
+ if (sirenOverrideOnCharacteristic.value) {
1561
+ sirenOverrideOnCharacteristic.updateValue(false);
1562
+ this.log.debug('Siren Override Switch (Off)');
1541
1563
  }
1542
1564
  };
1543
1565
 
@@ -1565,6 +1587,7 @@ SecuritySystem.prototype.getSirenHomeSwitch = function (callback) {
1565
1587
  };
1566
1588
 
1567
1589
  SecuritySystem.prototype.setSirenHomeSwitch = function (value, callback) {
1590
+ this.log.debug('Siren Home Switch (On)');
1568
1591
  this.triggerIfModeSet(Characteristic.SecuritySystemCurrentState.STAY_ARM, value, callback);
1569
1592
  };
1570
1593
 
@@ -1574,6 +1597,7 @@ SecuritySystem.prototype.getSirenAwaySwitch = function (callback) {
1574
1597
  };
1575
1598
 
1576
1599
  SecuritySystem.prototype.setSirenAwaySwitch = function (value, callback) {
1600
+ this.log.debug('Siren Away Switch (On)');
1577
1601
  this.triggerIfModeSet(Characteristic.SecuritySystemCurrentState.AWAY_ARM, value, callback);
1578
1602
  };
1579
1603
 
@@ -1583,6 +1607,7 @@ SecuritySystem.prototype.getSirenNightSwitch = function (callback) {
1583
1607
  };
1584
1608
 
1585
1609
  SecuritySystem.prototype.setSirenNightSwitch = function (value, callback) {
1610
+ this.log.debug('Siren Night Switch (On)');
1586
1611
  this.triggerIfModeSet(Characteristic.SecuritySystemCurrentState.NIGHT_ARM, value, callback);
1587
1612
  };
1588
1613
 
@@ -1704,26 +1729,32 @@ SecuritySystem.prototype.resetModeSwitches = function () {
1704
1729
 
1705
1730
  if (modeHomeSwitchCharacteristicOn.value) {
1706
1731
  modeHomeSwitchCharacteristicOn.updateValue(false);
1732
+ this.log.debug('Mode Home Switch (Off)');
1707
1733
  }
1708
1734
 
1709
1735
  if (modeAwaySwitchCharacteristicOn.value) {
1710
1736
  modeAwaySwitchCharacteristicOn.updateValue(false);
1737
+ this.log.debug('Mode Away Switch (Off)');
1711
1738
  }
1712
1739
 
1713
1740
  if (modeNightSwitchCharacteristicOn.value) {
1714
1741
  modeNightSwitchCharacteristicOn.updateValue(false);
1742
+ this.log.debug('Mode Night Switch (Off)');
1715
1743
  }
1716
1744
 
1717
1745
  if (modeOffSwitchCharacteristicOn.value) {
1718
1746
  modeOffSwitchCharacteristicOn.updateValue(false);
1747
+ this.log.debug('Mode Off Switch (Off)');
1719
1748
  }
1720
1749
 
1721
1750
  if (modeAwayExtendedSwitchCharacteristicOn.value) {
1722
1751
  modeAwayExtendedSwitchCharacteristicOn.updateValue(false);
1752
+ this.log.debug('Mode Away Extended Switch (Off)');
1723
1753
  }
1724
1754
 
1725
1755
  if (modePauseSwitchCharacteristicOn.value) {
1726
1756
  modePauseSwitchCharacteristicOn.updateValue(false);
1757
+ this.log.debug('Mode Pause Switch (Off)');
1727
1758
  }
1728
1759
  };
1729
1760
 
@@ -1731,18 +1762,22 @@ SecuritySystem.prototype.updateModeSwitches = function () {
1731
1762
  switch (this.targetState) {
1732
1763
  case Characteristic.SecuritySystemTargetState.STAY_ARM:
1733
1764
  this.modeHomeSwitchService.updateCharacteristic(Characteristic.On, true);
1765
+ this.log.debug('Mode Home Switch (On)');
1734
1766
  break;
1735
1767
 
1736
1768
  case Characteristic.SecuritySystemTargetState.AWAY_ARM:
1737
1769
  this.modeAwaySwitchService.updateCharacteristic(Characteristic.On, true);
1770
+ this.log.debug('Mode Away Switch (On)');
1738
1771
  break;
1739
1772
 
1740
1773
  case Characteristic.SecuritySystemTargetState.NIGHT_ARM:
1741
1774
  this.modeNightSwitchService.updateCharacteristic(Characteristic.On, true);
1775
+ this.log.debug('Mode Night Switch (On)');
1742
1776
  break;
1743
1777
 
1744
1778
  case Characteristic.SecuritySystemTargetState.DISARM:
1745
1779
  this.modeOffSwitchService.updateCharacteristic(Characteristic.On, true);
1780
+ this.log.debug('Mode Off Switch (On)');
1746
1781
  break;
1747
1782
  }
1748
1783
  };
@@ -70,6 +70,7 @@ const options = {
70
70
 
71
71
  // Audio
72
72
  options.audio = config.audio;
73
+ options.audioConfiguration = config.audio_configuration;
73
74
  options.audioPath = config.audio_path;
74
75
  options.audioLanguage = config.audio_language;
75
76
  options.audioVolume = config.audio_volume;
@@ -1 +0,0 @@
1
- Closes #XXX