homebridge-lib 5.1.18 → 5.1.22-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.
@@ -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
@@ -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
@@ -113,25 +113,16 @@ class SystemInfo extends events.EventEmitter {
113
113
  */
114
114
  static parseRpiCpuInfo (cpuInfo) {
115
115
  const id = /Serial\s*: ([0-9a-f]{16})/.exec(cpuInfo)[1].toUpperCase()
116
- const revision = parseInt(/Revision\s*: ([0-9a-f]{4,})/.exec(cpuInfo)[1], 16)
117
- const rpi = SystemInfo.parseRpiRevision(revision & 0x00FFFFFF)
118
- return Object.assign({ id: id }, rpi)
119
- }
120
-
121
- /** Parse the revision of a Raspberry Pi.
122
- *
123
- * @see https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-revision-codes
124
- * @param {int} revision - The Raspberry Pi revision.
125
- * @return {object} - The parsed revision.
126
- */
127
- static parseRpiRevision (revision) {
116
+ const revision = parseInt(
117
+ /Revision\s*: ([0-9a-f]{4,})/.exec(cpuInfo)[1], 16
118
+ ) & 0x00FFFFFF
128
119
  let gpioMask, manufacturer, memory, model, modelRevision, processor
129
120
  if ((revision & 0x00800000) !== 0) { // New revision scheme.
130
- manufacturer = rpiInfo.manufacturers[(revision & 0x000f0000) >> 16]
121
+ manufacturer = rpiInfo.manufacturers[(revision & 0x000F0000) >> 16]
131
122
  memory = rpiInfo.memorySizes[(revision & 0x00700000) >> 20]
132
- model = rpiInfo.models[(revision & 0x00000ff0) >> 4]
133
- modelRevision = '1.' + ((revision & 0x0000000f) >> 0).toString()
134
- processor = rpiInfo.processors[(revision & 0x0000f000) >> 12]
123
+ model = rpiInfo.models[(revision & 0x00000FF0) >> 4]
124
+ modelRevision = '1.' + ((revision & 0x0000000F) >> 0).toString()
125
+ processor = rpiInfo.processors[(revision & 0x0000F000) >> 12]
135
126
  } else if (rpiInfo.oldRevisions[revision] != null) { // Old incremental revisions.
136
127
  manufacturer = rpiInfo.oldRevisions[revision].manufacturer
137
128
  memory = rpiInfo.oldRevisions[revision].memory
@@ -155,6 +146,8 @@ class SystemInfo extends events.EventEmitter {
155
146
  return {
156
147
  gpioMask: gpioMask,
157
148
  gpioMaskSerial: (1 << 15) | (1 << 14),
149
+ id: id,
150
+ isRpi: true,
158
151
  manufacturer: manufacturer,
159
152
  memory: memory,
160
153
  model: model,
@@ -216,22 +209,7 @@ class SystemInfo extends events.EventEmitter {
216
209
  */
217
210
  async getRpiInfo () {
218
211
  const cpuInfo = await this.readTextFile('/proc/cpuinfo')
219
- const rpi = SystemInfo.parseRpiCpuInfo(cpuInfo)
220
- return {
221
- gpioMask: rpi.gpioMask,
222
- gpioMaskSerial: rpi.gpioMaskSerial,
223
- id: rpi.id,
224
- isRpi: true,
225
- manufacturer: rpi.manufacturer,
226
- memory: rpi.memory,
227
- model: rpi.model,
228
- modelRevision: rpi.modelRevision,
229
- nCores: os.cpus().length,
230
- powerLed: rpi.powerLed,
231
- prettyName: rpi.prettyName,
232
- processor: rpi.processor,
233
- revision: rpi.revision
234
- }
212
+ return SystemInfo.parseRpiCpuInfo(cpuInfo)
235
213
  }
236
214
 
237
215
  /** Extract OS info from /etc/os-release.
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.18",
6
+ "version": "5.1.22-0",
7
7
  "keywords": [
8
8
  "homekit",
9
9
  "homebridge"
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "engines": {
24
24
  "homebridge": "^1.3.8",
25
- "node": "^16.13.0"
25
+ "node": "^16.13.1"
26
26
  },
27
27
  "dependencies": {
28
28
  "bonjour-hap": "^3.6.3",