homebridge-lib 5.1.20 → 5.1.23

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/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  </span>
14
14
 
15
15
  ## Library for Homebridge Plugins
16
- Copyright © 2018-2021 Erik Baauw. All rights reserved.
16
+ Copyright © 2018-2022 Erik Baauw. All rights reserved.
17
17
 
18
18
  While developing a number of [Homebridge](https://github.com/homebridge/homebridge) plugins, I find myself duplicating a lot of code.
19
19
  The idea behind this library is to ease developing and maintaining Homebridge plugins by separating this generic code, dealing with [HomeKit](http://www.apple.com/ios/home/) and Homebridge, from the specific code, dealing with the actual devices being exposed to HomeKit.
package/cli/hap.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // homebridge-lib/cli/hap.js
4
4
  //
5
5
  // Library for Homebridge plugins.
6
- // Copyright © 2018-2021 Erik Baauw. All rights reserved.
6
+ // Copyright © 2018-2022 Erik Baauw. All rights reserved.
7
7
  //
8
8
  // Logger for HomeKit accessory announcements.
9
9
 
package/cli/json.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // homebridge-lib/cli/json.js
4
4
  //
5
5
  // Library for Homebridge plugins.
6
- // Copyright © 2018-2021 Erik Baauw. All rights reserved.
6
+ // Copyright © 2018-2022 Erik Baauw. All rights reserved.
7
7
  //
8
8
  // JSON formatter.
9
9
 
package/cli/sysinfo.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // homebridge-lib/cli/sysinfo.js
4
4
  //
5
5
  // Library for Homebridge plugins.
6
- // Copyright © 2021 Erik Baauw. All rights reserved.
6
+ // Copyright © 2021-2022 Erik Baauw. All rights reserved.
7
7
  //
8
8
  // Show system info.
9
9
 
package/cli/upnp.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // homebridge-lib/cli/upnp.js
4
4
  //
5
5
  // Library for Homebridge plugins.
6
- // Copyright © 2018-2021 Erik Baauw. All rights reserved.
6
+ // Copyright © 2018-2022 Erik Baauw. All rights reserved.
7
7
  //
8
8
  // Logger for UPnP device announcements.
9
9
 
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/index.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2017-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  'use strict'
7
7
 
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/AccessoryDelegate.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2017-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  'use strict'
7
7
 
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/AdaptiveLighting.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2020-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2020-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  'use strict'
7
7
 
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/CharacteristicDelegate.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2017-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  'use strict'
7
7
 
package/lib/Colour.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/Colour.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2016-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2016-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  'use strict'
7
7
 
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/CommandLineParser.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2017-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  // TODO:
7
7
  // - Change parameters to (params, callback) with:
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/CommandLineUtility.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2018-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2018-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  'use strict'
7
7
 
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/CustomeHomeKitTypes.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2017-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  const regExps = {
7
7
  uuid: /^[0-9A-F]{8}-[0-9A-F]{4}-[1-5][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/,
package/lib/Delegate.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/Delegate.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2017-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  'use strict'
7
7
 
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/EveHomeKitTypes.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2017-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  const homebridgeLib = require('../index')
7
7
 
package/lib/HttpClient.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/HttpClient.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2018-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2018-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  'use strict'
7
7
 
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/JsonFormatter.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2018-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2018-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  'use strict'
7
7
 
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/MyHomeKitTypes.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2017-2022 Erik Baauw. All rights reserved.
5
5
  //
6
6
  // My own collection of custom HomeKit Services and Characteristics.
7
7
 
@@ -105,6 +105,8 @@ class MyHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
105
105
  * @property {Class} LogLevel - Level of logging.
106
106
  * @property {Class} Loudness - Audio loudness.
107
107
  * <br>Used by: homebridge-zp in Speaker service.
108
+ * @property {Class} LowBatteryThreshold - Threshold value for setting
109
+ * Status Low Battery.
108
110
  * @property {Class} MotorSpeed - Speed at which to move the blinds.
109
111
  * <br>Used by: homebridge-soma in Window Covering service.
110
112
  * @property {Class} MorningMode - Move the blinds slowly, making less
@@ -679,6 +681,23 @@ class MyHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
679
681
  perms: [this.Perms.READ, this.Perms.NOTIFY, this.Perms.WRITE]
680
682
  })
681
683
 
684
+ this.createCharacteristicClass('LowBatteryThreshold', uuid('075'), {
685
+ format: this.Formats.UINT8,
686
+ unit: this.Units.PERCENTAGE,
687
+ minValue: 0,
688
+ maxValue: 95,
689
+ minStep: 5,
690
+ perms: [this.Perms.READ, this.Perms.NOTIFY, this.Perms.WRITE]
691
+ }, 'Low Battery Threshold')
692
+
693
+ this.createCharacteristicClass('PositionChange', uuid('076'), {
694
+ format: this.Formats.INT,
695
+ minValue: -1,
696
+ maxValue: 1,
697
+ minStep: 1, // Force Down|Up control in Eve
698
+ perms: [this.Perms.READ, this.Perms.NOTIFY, this.Perms.WRITE]
699
+ }, 'Position Change')
700
+
682
701
  // Characteristic for Unique ID, used by homebridge-hue.
683
702
  // Source: as exposed by the Philips Hue bridge. This characteristic is
684
703
  // used by the Hue app to select the accessories when syncing Hue bridge
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/OptionParser.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2018-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2018-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  'use strict'
7
7
 
package/lib/Platform.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/Platform.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2017-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  'use strict'
7
7
 
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/ServiceDelegate.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2017-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2017-2022 Erik Baauw. All rights reserved.
5
5
  //
6
6
  // The logic for handling Eve history was copied from Simone Tisa's
7
7
  // fakagato-history repository, copyright © 2017 simont77.
@@ -429,6 +429,8 @@ class AccessoryInformation extends ServiceDelegate {
429
429
  * `batteryLevel` | `Characteristics.hap.BatteryLevel` | Y
430
430
  * `chargingState` | `Characteristics.hap.ChargingState` | Y
431
431
  * `statusLowBattery` | `Characteristics.hap.StatusLowBattery` | Y
432
+ * `lowBatteryThreshold`| `Characteristics.my.LowBatteryThreshold` | Y
433
+ *
432
434
  * @extends ServiceDelegate
433
435
  * @memberof ServiceDelegate
434
436
  */
@@ -436,14 +438,16 @@ class Battery extends ServiceDelegate {
436
438
  /** Create a new instance of an _Battery_ service delegate.
437
439
  * @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
438
440
  * corresponding HomeKit accessory.
439
- * @param {!object} params - The parameters for the
441
+ * @param {object} params - The parameters for the
440
442
  * _AccessoryInformation_ HomeKit service.
441
- * @param {!string} params.batteryLevel - Initial value for
442
- * `Characteristics.hap.BatteryLevel` (default: 100%).
443
- * @param {!string} params.chargingState - Initial value for
444
- * `Characteristics.hap.ChargingState` (default: NOT_CHARGEABLE).
445
- * @param {!string} params.statusLowBattery - Initial value for
446
- * `Characteristics.hap.StatusLowBattery` (default: BATTERY_LEVEL_NORMAL).
443
+ * @param {integer} [params.batteryLevel=100] - Initial value for
444
+ * `Characteristics.hap.BatteryLevel`.
445
+ * @param {integer} [params.chargingState=NOT_CHARGEABLE] - Initial value for
446
+ * `Characteristics.hap.ChargingState`.
447
+ * @param {integer} [params.statusLowBattery=BATTERY_LEVEL_NORMAL] - Initial
448
+ * value for `Characteristics.hap.StatusLowBattery`.
449
+ * @param {integer} [params.lowBatteryThreshold=20] - Initial value for
450
+ * low battery threshold.
447
451
  */
448
452
  constructor (accessoryDelegate, params = {}) {
449
453
  params.name = accessoryDelegate.name + ' Battery'
@@ -454,6 +458,8 @@ class Battery extends ServiceDelegate {
454
458
  Characteristic: this.Characteristics.hap.BatteryLevel,
455
459
  unit: '%',
456
460
  value: params.batteryLevel != null ? params.batteryLevel : 100
461
+ }).on('didSet', (value) => {
462
+ this.updateStatusLowBattery()
457
463
  })
458
464
  this.addCharacteristicDelegate({
459
465
  key: 'chargingState',
@@ -469,6 +475,21 @@ class Battery extends ServiceDelegate {
469
475
  ? params.statusLowBattery
470
476
  : this.Characteristics.hap.StatusLowBattery.BATTERY_LEVEL_NORMAL
471
477
  })
478
+ this.addCharacteristicDelegate({
479
+ key: 'lowBatteryThreshold',
480
+ Characteristic: this.Characteristics.my.LowBatteryThreshold,
481
+ unit: '%',
482
+ value: params.lowBatteryThreshold != null ? params.lowBatteryThreshold : 20
483
+ }).on('didSet', (value) => {
484
+ this.updateStatusLowBattery()
485
+ })
486
+ }
487
+
488
+ updateStatusLowBattery () {
489
+ this.values.statusLowBattery =
490
+ this.values.batteryLevel <= this.values.lowBatteryThreshold
491
+ ? this.Characteristics.hap.StatusLowBattery.BATTERY_LEVEL_LOW
492
+ : this.Characteristics.hap.StatusLowBattery.BATTERY_LEVEL_NORMAL
472
493
  }
473
494
  }
474
495
 
package/lib/SystemInfo.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/SystemInfo.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2019-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2019-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  'use strict'
7
7
 
@@ -112,10 +112,16 @@ class SystemInfo extends events.EventEmitter {
112
112
  * @return {object} - The extracted info.
113
113
  */
114
114
  static parseRpiCpuInfo (cpuInfo) {
115
- const id = /Serial\s*: ([0-9a-f]{16})/.exec(cpuInfo)[1].toUpperCase()
116
- const revision = parseInt(
117
- /Revision\s*: ([0-9a-f]{4,})/.exec(cpuInfo)[1], 16
118
- ) & 0x00FFFFFF
115
+ let a = /Serial\s*: ([0-9a-f]{16})/.exec(cpuInfo)
116
+ if (a == null || a.length < 2) {
117
+ return null
118
+ }
119
+ const id = a[1].toUpperCase()
120
+ a = /Revision\s*: ([0-9a-f]{4,})/.exec(cpuInfo)
121
+ if (a == null || a.length < 2) {
122
+ return null
123
+ }
124
+ const revision = parseInt(a[1], 16) & 0x00FFFFFF
119
125
  let gpioMask, manufacturer, memory, model, modelRevision, processor
120
126
  if ((revision & 0x00800000) !== 0) { // New revision scheme.
121
127
  manufacturer = rpiInfo.manufacturers[(revision & 0x000F0000) >> 16]
@@ -338,8 +344,11 @@ class SystemInfo extends events.EventEmitter {
338
344
  case 'ProductName': // e.g. 'macOS' or 'Mac OS X'
339
345
  name = fields[1]
340
346
  break
341
- case 'ProductVersion': // e.g. '12.0.1'
347
+ case 'ProductVersion': // e.g. '12.0.1' or '12.1'
342
348
  version = fields[1]
349
+ if (version.split('.').length === 2) {
350
+ version += '.0'
351
+ }
343
352
  break
344
353
  case 'BuildVersion': // e.g. '21A559'
345
354
  build = fields[1]
package/lib/UpnpClient.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // homebridge-lib/lib/UpnpClient.js
2
2
  //
3
3
  // Library for Homebridge plugins.
4
- // Copyright © 2018-2021 Erik Baauw. All rights reserved.
4
+ // Copyright © 2018-2022 Erik Baauw. All rights reserved.
5
5
 
6
6
  'use strict'
7
7
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Library for homebridge plugins",
4
4
  "author": "Erik Baauw",
5
5
  "license": "Apache-2.0",
6
- "version": "5.1.20",
6
+ "version": "5.1.23",
7
7
  "keywords": [
8
8
  "homekit",
9
9
  "homebridge"
@@ -21,7 +21,7 @@
21
21
  "upnp": "cli/upnp.js"
22
22
  },
23
23
  "engines": {
24
- "homebridge": "^1.3.8",
24
+ "homebridge": "^1.3.9",
25
25
  "node": "^16.13.1"
26
26
  },
27
27
  "dependencies": {