homebridge-lib 5.6.7 → 5.7.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 +5 -0
- package/lib/AccessoryDelegate.js +1 -1
- package/lib/MyHomeKitTypes.js +1 -1
- package/lib/Platform.js +1 -1
- package/lib/ServiceDelegate/History/Consumption.js +44 -19
- package/lib/ServiceDelegate/History/Motion.js +1 -1
- package/lib/ServiceDelegate/History/On.js +1 -1
- package/lib/ServiceDelegate/History/Power.js +42 -8
- package/lib/SystemInfo.js +6 -5
- package/lib/UiServer.js +1 -1
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -291,6 +291,11 @@ class homebridgeLib {
|
|
|
291
291
|
static toHexString (i, length = 4) {
|
|
292
292
|
return (zeroes + i.toString(16)).slice(-length).toUpperCase()
|
|
293
293
|
}
|
|
294
|
+
|
|
295
|
+
/** Return the `semver` library, so plugins don't have to list this as a
|
|
296
|
+
* separate dependency.
|
|
297
|
+
*/
|
|
298
|
+
static get semver () { return require('semver') }
|
|
294
299
|
}
|
|
295
300
|
|
|
296
301
|
module.exports = homebridgeLib
|
package/lib/AccessoryDelegate.js
CHANGED
|
@@ -204,7 +204,7 @@ class AccessoryDelegate extends homebridgeLib.Delegate {
|
|
|
204
204
|
|
|
205
205
|
/** Returns the property delegate correspondig to the property key.
|
|
206
206
|
* @param {!string} key - The key for the property.
|
|
207
|
-
* returns {PropertyDelegate}
|
|
207
|
+
* @returns {PropertyDelegate}
|
|
208
208
|
*/
|
|
209
209
|
propertyDelegate (key) {
|
|
210
210
|
return this._propertyDelegates[key]
|
package/lib/MyHomeKitTypes.js
CHANGED
|
@@ -700,7 +700,7 @@ class MyHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
|
|
|
700
700
|
format: this.Formats.UINT8,
|
|
701
701
|
unit: this.Units.PERCENTAGE,
|
|
702
702
|
minValue: 0,
|
|
703
|
-
maxValue:
|
|
703
|
+
maxValue: 100,
|
|
704
704
|
minStep: 5,
|
|
705
705
|
perms: [this.Perms.READ, this.Perms.NOTIFY, this.Perms.WRITE]
|
|
706
706
|
}, 'Low Battery Threshold')
|
package/lib/Platform.js
CHANGED
|
@@ -10,7 +10,7 @@ const homebridgeLib = require('../index')
|
|
|
10
10
|
const events = require('events')
|
|
11
11
|
const fs = require('fs')
|
|
12
12
|
const http = require('http')
|
|
13
|
-
const semver =
|
|
13
|
+
const { semver } = homebridgeLib
|
|
14
14
|
const util = require('util')
|
|
15
15
|
const zlib = require('zlib')
|
|
16
16
|
|
|
@@ -53,9 +53,11 @@ class Consumption extends History {
|
|
|
53
53
|
* @param {?CharacteristicDelegate} powerDelegate - A reference to the
|
|
54
54
|
* delegate of the associated `Characteristics.eve.CurrentConsumption`
|
|
55
55
|
* characteristic.
|
|
56
|
+
* @param {!CharacteristicDelegate} onDelegate - A reference to the
|
|
57
|
+
* delegate of the associated `Characteristics.hap.On` characteristic.
|
|
56
58
|
*/
|
|
57
59
|
constructor (
|
|
58
|
-
accessoryDelegate, params, consumptionDelegate, powerDelegate
|
|
60
|
+
accessoryDelegate, params, consumptionDelegate, powerDelegate, onDelegate
|
|
59
61
|
) {
|
|
60
62
|
super(accessoryDelegate, params)
|
|
61
63
|
if (!(consumptionDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
@@ -67,25 +69,33 @@ class Consumption extends History {
|
|
|
67
69
|
) {
|
|
68
70
|
throw new TypeError('powerDelegate: not a CharacteristicDelegate')
|
|
69
71
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
silent: true
|
|
77
|
-
})
|
|
72
|
+
if (
|
|
73
|
+
onDelegate != null &&
|
|
74
|
+
!(onDelegate instanceof homebridgeLib.CharacteristicDelegate)
|
|
75
|
+
) {
|
|
76
|
+
throw new TypeError('temperatureDelegate: not a CharacteristicDelegate')
|
|
77
|
+
}
|
|
78
78
|
this._consumptionDelegate = consumptionDelegate
|
|
79
79
|
this._powerDelegate = powerDelegate
|
|
80
80
|
this._entry = { time: 0, power: 0 }
|
|
81
|
+
if (onDelegate != null) {
|
|
82
|
+
this._entry.on = onDelegate.value ? 1 : 0
|
|
83
|
+
onDelegate.on('didSet', (value) => {
|
|
84
|
+
this._entry.on = value ? 1 : 0
|
|
85
|
+
const power = this._entry.power
|
|
86
|
+
this._entry.power = null
|
|
87
|
+
super._addEntry()
|
|
88
|
+
this._entry.power = power
|
|
89
|
+
})
|
|
90
|
+
}
|
|
81
91
|
}
|
|
82
92
|
|
|
83
93
|
_addEntry () {
|
|
84
94
|
const now = Math.round(new Date().valueOf() / 1000)
|
|
85
95
|
// Sensor deliveres totalConsumption, optionally compute currentConsumption
|
|
86
|
-
if (this.
|
|
87
|
-
const delta = this._consumptionDelegate.value - this.
|
|
88
|
-
const period = now - this.
|
|
96
|
+
if (this._consumption != null && this._time != null) {
|
|
97
|
+
const delta = this._consumptionDelegate.value - this._consumption // kWh
|
|
98
|
+
const period = now - this._time // s
|
|
89
99
|
const power = Math.round(1000 * 3600 * delta / period) // W
|
|
90
100
|
if (this._powerDelegate != null) {
|
|
91
101
|
this._powerDelegate.value = power
|
|
@@ -93,20 +103,35 @@ class Consumption extends History {
|
|
|
93
103
|
this._entry.power = power
|
|
94
104
|
super._addEntry(now)
|
|
95
105
|
}
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
106
|
+
this._consumption = this._consumptionDelegate.value
|
|
107
|
+
this._time = now
|
|
98
108
|
}
|
|
99
109
|
|
|
100
|
-
|
|
101
|
-
get _fingerPrint () { return '01 0702' }
|
|
110
|
+
get _fingerPrint () { return '02 0702 0E01' }
|
|
102
111
|
|
|
103
112
|
_entryStream (entry) {
|
|
113
|
+
if (entry.on == null) {
|
|
114
|
+
return util.format(
|
|
115
|
+
'|0c %s %s 01 %s',
|
|
116
|
+
numToHex(swap32(this._h.currentEntry), 8),
|
|
117
|
+
numToHex(swap32(entry.time - this._h.initialTime), 8),
|
|
118
|
+
numToHex(swap16(entry.power * 10), 4)
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
if (entry.power == null) {
|
|
122
|
+
return util.format(
|
|
123
|
+
'|0b %s %s 02 %s',
|
|
124
|
+
numToHex(swap32(this._h.currentEntry), 8),
|
|
125
|
+
numToHex(swap32(entry.time - this._h.initialTime), 8),
|
|
126
|
+
numToHex(entry.on, 2)
|
|
127
|
+
)
|
|
128
|
+
}
|
|
104
129
|
return util.format(
|
|
105
|
-
|
|
106
|
-
'|0c %s %s 01 %s',
|
|
130
|
+
'|0d %s %s 03 %s %s',
|
|
107
131
|
numToHex(swap32(this._h.currentEntry), 8),
|
|
108
132
|
numToHex(swap32(entry.time - this._h.initialTime), 8),
|
|
109
|
-
numToHex(swap16(entry.power * 10), 4)
|
|
133
|
+
numToHex(swap16(entry.power * 10), 4),
|
|
134
|
+
numToHex(entry.on, 2)
|
|
110
135
|
)
|
|
111
136
|
}
|
|
112
137
|
}
|
|
@@ -49,10 +49,11 @@ class Power extends History {
|
|
|
49
49
|
* @param {!CharacteristicDelegate} consumptionDelegate - A reference to the
|
|
50
50
|
* delegate of the associated `Characteristics.eve.TotalConsumption`
|
|
51
51
|
* characteristic.
|
|
52
|
+
* @param {!CharacteristicDelegate} onDelegate - A reference to the
|
|
53
|
+
* delegate of the associated `Characteristics.hap.On` characteristic.
|
|
52
54
|
*/
|
|
53
55
|
constructor (
|
|
54
|
-
accessoryDelegate, params,
|
|
55
|
-
powerDelegate, consumptionDelegate
|
|
56
|
+
accessoryDelegate, params, powerDelegate, consumptionDelegate, onDelegate
|
|
56
57
|
) {
|
|
57
58
|
super(accessoryDelegate, params)
|
|
58
59
|
if (!(powerDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
@@ -61,6 +62,12 @@ class Power extends History {
|
|
|
61
62
|
if (!(consumptionDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
62
63
|
throw new TypeError('consumptionDelegate: not a CharacteristicDelegate')
|
|
63
64
|
}
|
|
65
|
+
if (
|
|
66
|
+
onDelegate != null &&
|
|
67
|
+
!(onDelegate instanceof homebridgeLib.CharacteristicDelegate)
|
|
68
|
+
) {
|
|
69
|
+
throw new TypeError('temperatureDelegate: not a CharacteristicDelegate')
|
|
70
|
+
}
|
|
64
71
|
this._powerDelegate = powerDelegate
|
|
65
72
|
this._consumptionDelegate = consumptionDelegate
|
|
66
73
|
this._entry = { time: 0, power: 0 }
|
|
@@ -71,7 +78,7 @@ class Power extends History {
|
|
|
71
78
|
if (this._time != null) {
|
|
72
79
|
const delta = this._power * (now - this._time) // Ws
|
|
73
80
|
this._runningConsumption += Math.round(delta / 600.0) // W * 10 min
|
|
74
|
-
this._totalConsumption += Math.round(delta /
|
|
81
|
+
this._totalConsumption += Math.round(delta / 3600000.0) // kWh
|
|
75
82
|
}
|
|
76
83
|
this._power = value
|
|
77
84
|
this._time = now
|
|
@@ -86,6 +93,16 @@ class Power extends History {
|
|
|
86
93
|
this._totalConsumption = 0
|
|
87
94
|
this._consumptionDelegate.value = this._totalConsumption
|
|
88
95
|
})
|
|
96
|
+
if (onDelegate != null) {
|
|
97
|
+
this._entry.on = onDelegate.value ? 1 : 0
|
|
98
|
+
onDelegate.on('didSet', (value) => {
|
|
99
|
+
this._entry.on = value ? 1 : 0
|
|
100
|
+
const power = this._entry.power
|
|
101
|
+
this._entry.power = null
|
|
102
|
+
super._addEntry()
|
|
103
|
+
this._entry.power = power
|
|
104
|
+
})
|
|
105
|
+
}
|
|
89
106
|
}
|
|
90
107
|
|
|
91
108
|
_addEntry () {
|
|
@@ -98,22 +115,39 @@ class Power extends History {
|
|
|
98
115
|
this._consumptionDelegate.value = this._totalConsumption
|
|
99
116
|
this._entry.power = this._runningConsumption
|
|
100
117
|
super._addEntry(now)
|
|
118
|
+
} else if (this._entry.on != null) {
|
|
119
|
+
super._addEntry(now)
|
|
101
120
|
}
|
|
102
121
|
this._power = this._powerDelegate.value
|
|
103
122
|
this._time = now
|
|
104
123
|
this._runningConsumption = 0
|
|
105
124
|
}
|
|
106
125
|
|
|
107
|
-
|
|
108
|
-
get _fingerPrint () { return '01 0702' }
|
|
126
|
+
get _fingerPrint () { return '02 0702 0E01' }
|
|
109
127
|
|
|
110
128
|
_entryStream (entry) {
|
|
129
|
+
if (entry.on == null) {
|
|
130
|
+
return util.format(
|
|
131
|
+
'|0c %s %s 01 %s',
|
|
132
|
+
numToHex(swap32(this._h.currentEntry), 8),
|
|
133
|
+
numToHex(swap32(entry.time - this._h.initialTime), 8),
|
|
134
|
+
numToHex(swap16(entry.power * 10), 4)
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
if (entry.power == null) {
|
|
138
|
+
return util.format(
|
|
139
|
+
'|0b %s %s 02 %s',
|
|
140
|
+
numToHex(swap32(this._h.currentEntry), 8),
|
|
141
|
+
numToHex(swap32(entry.time - this._h.initialTime), 8),
|
|
142
|
+
numToHex(entry.on, 2)
|
|
143
|
+
)
|
|
144
|
+
}
|
|
111
145
|
return util.format(
|
|
112
|
-
|
|
113
|
-
'|0c %s %s 01 %s',
|
|
146
|
+
'|0d %s %s 03 %s %s',
|
|
114
147
|
numToHex(swap32(this._h.currentEntry), 8),
|
|
115
148
|
numToHex(swap32(entry.time - this._h.initialTime), 8),
|
|
116
|
-
numToHex(swap16(entry.power * 10), 4)
|
|
149
|
+
numToHex(swap16(entry.power * 10), 4),
|
|
150
|
+
numToHex(entry.on, 2)
|
|
117
151
|
)
|
|
118
152
|
}
|
|
119
153
|
}
|
package/lib/SystemInfo.js
CHANGED
|
@@ -98,7 +98,8 @@ const macOsInfo = {
|
|
|
98
98
|
10.14: 'Mojave',
|
|
99
99
|
10.15: 'Catalina',
|
|
100
100
|
11: 'Big Sur',
|
|
101
|
-
12: 'Monterey'
|
|
101
|
+
12: 'Monterey',
|
|
102
|
+
13: 'Ventura'
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
|
|
@@ -340,20 +341,20 @@ class SystemInfo extends events.EventEmitter {
|
|
|
340
341
|
const text = await this.exec('sw_vers')
|
|
341
342
|
const lines = text.split('\n')
|
|
342
343
|
for (const line of lines) {
|
|
343
|
-
const fields = line.split('
|
|
344
|
+
const fields = line.split(':')
|
|
344
345
|
if (fields.length === 2) {
|
|
345
346
|
switch (fields[0]) {
|
|
346
347
|
case 'ProductName': // e.g. 'macOS' or 'Mac OS X'
|
|
347
|
-
name = fields[1]
|
|
348
|
+
name = fields[1].trim()
|
|
348
349
|
break
|
|
349
350
|
case 'ProductVersion': // e.g. '12.0.1' or '12.1'
|
|
350
|
-
version = fields[1]
|
|
351
|
+
version = fields[1].trim()
|
|
351
352
|
if (version.split('.').length === 2) {
|
|
352
353
|
version += '.0'
|
|
353
354
|
}
|
|
354
355
|
break
|
|
355
356
|
case 'BuildVersion': // e.g. '21A559'
|
|
356
|
-
build = fields[1]
|
|
357
|
+
build = fields[1].trim()
|
|
357
358
|
break
|
|
358
359
|
default:
|
|
359
360
|
break
|
package/lib/UiServer.js
CHANGED
|
@@ -10,7 +10,7 @@ const {
|
|
|
10
10
|
} = require('@homebridge/plugin-ui-utils')
|
|
11
11
|
const { HttpClient, formatError } = require('../index')
|
|
12
12
|
const chalk = require('chalk')
|
|
13
|
-
const fs = require('fs
|
|
13
|
+
const fs = require('fs').promises
|
|
14
14
|
const path = require('path')
|
|
15
15
|
const util = require('util')
|
|
16
16
|
|
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.
|
|
6
|
+
"version": "5.7.0",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"homekit",
|
|
9
9
|
"homebridge"
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"upnp": "cli/upnp.js"
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
|
-
"homebridge": "^1.5.
|
|
25
|
-
"node": "^
|
|
24
|
+
"homebridge": "^1.5.1",
|
|
25
|
+
"node": "^18.12.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@homebridge/plugin-ui-utils": "~0.0.19",
|
|
29
|
-
"bonjour-hap": "^3.6.
|
|
29
|
+
"bonjour-hap": "^3.6.4",
|
|
30
30
|
"chalk": "^4.1.2",
|
|
31
|
-
"semver": "^7.3.
|
|
31
|
+
"semver": "^7.3.8"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"prepare": "standard && mocha && rm -rf out && jsdoc -c jsdoc.json",
|