homebridge-lib 6.3.18 → 6.4.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/index.js +9 -0
- package/lib/Platform.js +7 -4
- package/lib/ServiceDelegate/Battery.js +46 -26
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -238,6 +238,15 @@ class homebridgeLib {
|
|
|
238
238
|
* @memberof module:homebridgeLib
|
|
239
239
|
*/
|
|
240
240
|
static get semver () { return hbLibTools.semver }
|
|
241
|
+
|
|
242
|
+
/** Return the recommended version of NodeJS from package.json.
|
|
243
|
+
* This is the version used to develop and test the software,
|
|
244
|
+
* typically the latest LTS version.
|
|
245
|
+
* @param {string} packageJson - The contents of package.json
|
|
246
|
+
* #return {string} - The recommended version.
|
|
247
|
+
* @memberof module:hbLibTools
|
|
248
|
+
*/
|
|
249
|
+
static get recommendedNodeVersion () { return hbLibTools.recommendedNodeVersion }
|
|
241
250
|
}
|
|
242
251
|
|
|
243
252
|
module.exports = homebridgeLib
|
package/lib/Platform.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
const homebridgeLib = require('../index')
|
|
9
9
|
const {
|
|
10
|
-
HttpClient, SystemInfo, UpnpClient, formatError, semver
|
|
10
|
+
HttpClient, SystemInfo, UpnpClient, formatError, recommendedNodeVersion, semver
|
|
11
11
|
} = homebridgeLib
|
|
12
12
|
|
|
13
13
|
const events = require('events')
|
|
@@ -25,8 +25,7 @@ const context = {
|
|
|
25
25
|
libName: libPackageJson.name,
|
|
26
26
|
libVersion: libPackageJson.version,
|
|
27
27
|
nodeVersion: process.version.slice(1),
|
|
28
|
-
recommendedNodeVersion:
|
|
29
|
-
semver.minVersion(libPackageJson.engines.node).toString(),
|
|
28
|
+
recommendedNodeVersion: recommendedNodeVersion(libPackageJson),
|
|
30
29
|
recommendedHomebridgeVersion:
|
|
31
30
|
semver.minVersion(libPackageJson.engines.homebridge).toString(),
|
|
32
31
|
saveInterval: 3600,
|
|
@@ -354,7 +353,7 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
354
353
|
)
|
|
355
354
|
if (context.nodeVersion !== context.recommendedNodeVersion) {
|
|
356
355
|
this.warn(
|
|
357
|
-
'recommended version: node v%s
|
|
356
|
+
'recommended version: node v%s', context.recommendedNodeVersion
|
|
358
357
|
)
|
|
359
358
|
}
|
|
360
359
|
if (context.homebridgeVersion !== context.recommendedHomebridgeVersion) {
|
|
@@ -460,6 +459,10 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
460
459
|
* @event Platform#accessoryRestored
|
|
461
460
|
* @param {!string} className - The name of the
|
|
462
461
|
* {@link AccessoryDelegate#className class} of the accessory delegate.
|
|
462
|
+
* @param {!string} version - The version of the plugin that stored the
|
|
463
|
+
* cached accessory.
|
|
464
|
+
* @param {!string} id - The accessory ID.
|
|
465
|
+
* @param {!string} name - The accessory name.
|
|
463
466
|
* @param {object} context - The accessory
|
|
464
467
|
* {@link AccessoryDelegate#context context}.
|
|
465
468
|
*/
|
|
@@ -17,9 +17,18 @@ const { ServiceDelegate } = require('../../index')
|
|
|
17
17
|
* `name` | `Characteristics.hap.Name` |
|
|
18
18
|
* `batteryLevel` | `Characteristics.hap.BatteryLevel` | Y
|
|
19
19
|
* `chargingState` | `Characteristics.hap.ChargingState` | Y
|
|
20
|
-
* `statusLowBattery` | `Characteristics.hap.StatusLowBattery` |
|
|
20
|
+
* `statusLowBattery` | `Characteristics.hap.StatusLowBattery` |
|
|
21
21
|
* `lowBatteryThreshold`| `Characteristics.my.LowBatteryThreshold` | Y
|
|
22
22
|
*
|
|
23
|
+
* Depending on the capabilities of the device, the `Battery` service should
|
|
24
|
+
* be configured:
|
|
25
|
+
* - With only `statusLowBattery`, for devices that only report status low
|
|
26
|
+
* battery;
|
|
27
|
+
* - With `statusLowBattery` and `batteryLevel`, for devices that report both
|
|
28
|
+
* battery level and status low battery;
|
|
29
|
+
* - With `statusLowBattery`, `batteryLevel`, and `lowBatteryThreshold`, for
|
|
30
|
+
* devices that only report battery level.
|
|
31
|
+
*
|
|
23
32
|
* @extends ServiceDelegate
|
|
24
33
|
* @memberof ServiceDelegate
|
|
25
34
|
*/
|
|
@@ -29,47 +38,58 @@ class Battery extends ServiceDelegate {
|
|
|
29
38
|
* corresponding HomeKit accessory.
|
|
30
39
|
* @param {object} params - The parameters for the
|
|
31
40
|
* _AccessoryInformation_ HomeKit service.
|
|
32
|
-
* @param {integer} [params.batteryLevel=100] - Initial value for
|
|
41
|
+
* @param {?integer} [params.batteryLevel=100] - Initial value for
|
|
33
42
|
* `Characteristics.hap.BatteryLevel`.
|
|
34
|
-
*
|
|
43
|
+
* <br>When set to `undefined`, the `BatteryLevel` characteristic is not exposed.
|
|
44
|
+
* @param {?integer} [params.chargingState=NOT_CHARGING] - Initial value for
|
|
35
45
|
* `Characteristics.hap.ChargingState`.
|
|
46
|
+
* <br>When set to `undefined`, the `ChargingState` characteristic is not exposed.
|
|
36
47
|
* @param {integer} [params.statusLowBattery=BATTERY_LEVEL_NORMAL] - Initial
|
|
37
48
|
* value for `Characteristics.hap.StatusLowBattery`.
|
|
38
|
-
* @param {integer} [params.lowBatteryThreshold=20] - Initial value for
|
|
49
|
+
* @param {?integer} [params.lowBatteryThreshold=20] - Initial value for
|
|
39
50
|
* low battery threshold.
|
|
51
|
+
* <br>When set to `undefined`, the value of `StatusLowBattery` is not derived
|
|
52
|
+
* from the value of `BatteryLevel`.
|
|
40
53
|
*/
|
|
41
54
|
constructor (accessoryDelegate, params = {}) {
|
|
42
55
|
params.name = accessoryDelegate.name + ' Battery'
|
|
43
56
|
params.Service = accessoryDelegate.Services.hap.BatteryService
|
|
44
57
|
super(accessoryDelegate, params)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
if (params.batteryLevel !== undefined) {
|
|
59
|
+
this.addCharacteristicDelegate({
|
|
60
|
+
key: 'batteryLevel',
|
|
61
|
+
Characteristic: this.Characteristics.hap.BatteryLevel,
|
|
62
|
+
unit: '%',
|
|
63
|
+
value: params.batteryLevel ?? 100
|
|
64
|
+
}).on('didSet', (value) => {
|
|
65
|
+
this.updateStatusLowBattery()
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
if (params.chargingState !== undefined) {
|
|
69
|
+
this.addCharacteristicDelegate({
|
|
70
|
+
key: 'chargingState',
|
|
71
|
+
Characteristic: this.Characteristics.hap.ChargingState,
|
|
72
|
+
value: params.chargingState ??
|
|
73
|
+
this.Characteristics.hap.ChargingState.NOT_CHARGING
|
|
74
|
+
// this.Characteristics.hap.ChargingState.NOT_CHARGEABLE
|
|
75
|
+
})
|
|
76
|
+
}
|
|
59
77
|
this.addCharacteristicDelegate({
|
|
60
78
|
key: 'statusLowBattery',
|
|
61
79
|
Characteristic: this.Characteristics.hap.StatusLowBattery,
|
|
62
80
|
value: params.statusLowBattery ??
|
|
63
81
|
this.Characteristics.hap.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
64
82
|
})
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
83
|
+
if (params.lowBatteryThreshold !== undefined) {
|
|
84
|
+
this.addCharacteristicDelegate({
|
|
85
|
+
key: 'lowBatteryThreshold',
|
|
86
|
+
// Characteristic: this.Characteristics.my.LowBatteryThreshold,
|
|
87
|
+
unit: '%',
|
|
88
|
+
value: params.lowBatteryThreshold ?? 20
|
|
89
|
+
}).on('didSet', (value) => {
|
|
90
|
+
this.updateStatusLowBattery()
|
|
91
|
+
})
|
|
92
|
+
}
|
|
73
93
|
|
|
74
94
|
accessoryDelegate.propertyDelegate('name')
|
|
75
95
|
.on('didSet', (value) => {
|
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": "6.
|
|
6
|
+
"version": "6.4.0",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"homekit",
|
|
9
9
|
"homebridge"
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
24
|
"homebridge": "^1.6.1",
|
|
25
|
-
"node": "
|
|
25
|
+
"node": "18.17.0||^18||^16"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@homebridge/plugin-ui-utils": "~0.0.19",
|
|
29
|
-
"hb-lib-tools": "~1.0.
|
|
29
|
+
"hb-lib-tools": "~1.0.11"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"prepare": "standard && rm -rf out && jsdoc -c jsdoc.json",
|