homebridge-lib 5.4.0 → 5.6.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/lib/AdaptiveLighting.js +25 -11
- package/lib/CharacteristicDelegate.js +1 -1
- package/lib/Colour.js +1 -1
- package/lib/CommandLineParser.js +1 -5
- package/lib/HttpClient.js +5 -5
- package/lib/JsonFormatter.js +3 -3
- package/lib/Platform.js +10 -4
- package/lib/PropertyDelegate.js +1 -1
- package/lib/ServiceDelegate/History/Motion.js +44 -5
- package/lib/SystemInfo.js +18 -24
- package/package.json +3 -3
package/lib/AdaptiveLighting.js
CHANGED
|
@@ -172,12 +172,8 @@ class AdaptiveLighting {
|
|
|
172
172
|
* @param {integer} ct - The IID of the _Color Temperature_ characteristic.
|
|
173
173
|
*/
|
|
174
174
|
constructor (bri, ct) {
|
|
175
|
-
this.
|
|
176
|
-
|
|
177
|
-
: bri
|
|
178
|
-
this.ct = ct instanceof homebridgeLib.CharacteristicDelegate
|
|
179
|
-
? ct._characteristic.iid
|
|
180
|
-
: ct
|
|
175
|
+
this._bri = bri
|
|
176
|
+
this._ct = ct
|
|
181
177
|
this._active = false
|
|
182
178
|
}
|
|
183
179
|
|
|
@@ -187,6 +183,24 @@ class AdaptiveLighting {
|
|
|
187
183
|
*/
|
|
188
184
|
get active () { return this._control != null }
|
|
189
185
|
|
|
186
|
+
get briIid () {
|
|
187
|
+
if (this._briIid == null) {
|
|
188
|
+
this._briIid = this._bri instanceof homebridgeLib.CharacteristicDelegate
|
|
189
|
+
? this._bri._characteristic.iid
|
|
190
|
+
: this._bri
|
|
191
|
+
}
|
|
192
|
+
return this._briIid
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
get ctIid () {
|
|
196
|
+
if (this._ctIid == null) {
|
|
197
|
+
this._ctIid = this._ct instanceof homebridgeLib.CharacteristicDelegate
|
|
198
|
+
? this._ct._characteristic.iid
|
|
199
|
+
: this._ct
|
|
200
|
+
}
|
|
201
|
+
return this._ctIid
|
|
202
|
+
}
|
|
203
|
+
|
|
190
204
|
/** Deactivtate adaptive lighting.
|
|
191
205
|
*/
|
|
192
206
|
deactivate () {
|
|
@@ -199,12 +213,12 @@ class AdaptiveLighting {
|
|
|
199
213
|
generateConfiguration () {
|
|
200
214
|
return Buffer.concat([
|
|
201
215
|
tlvFromBuffer(1, Buffer.concat([
|
|
202
|
-
tlvFromUInt(1, this.
|
|
216
|
+
tlvFromUInt(1, this.briIid),
|
|
203
217
|
tlvFromUInt(2, 1)
|
|
204
218
|
])),
|
|
205
219
|
tlvFromNull(0),
|
|
206
220
|
tlvFromBuffer(1, Buffer.concat([
|
|
207
|
-
tlvFromUInt(1, this.
|
|
221
|
+
tlvFromUInt(1, this.ctIid),
|
|
208
222
|
tlvFromUInt(2, 2)
|
|
209
223
|
]))
|
|
210
224
|
]).toString('base64')
|
|
@@ -212,7 +226,7 @@ class AdaptiveLighting {
|
|
|
212
226
|
|
|
213
227
|
_generateControl () {
|
|
214
228
|
return tlvFromBuffer(1, Buffer.concat([
|
|
215
|
-
tlvFromUInt(1, this.
|
|
229
|
+
tlvFromUInt(1, this.ctIid),
|
|
216
230
|
tlvFromBuffer(2, Buffer.concat([
|
|
217
231
|
tlvFromHexString(1, this._control.transitionParameters['2.1.2.1']),
|
|
218
232
|
tlvFromUInt(2, this._startTime - epoch),
|
|
@@ -266,11 +280,11 @@ class AdaptiveLighting {
|
|
|
266
280
|
value = parseTlv('2', buf)
|
|
267
281
|
}
|
|
268
282
|
const control = value.colorTemperature
|
|
269
|
-
if (control.iid != null && control.iid !== this.
|
|
283
|
+
if (control.iid != null && control.iid !== this.ctIid) {
|
|
270
284
|
throw new Error('%d: bad ColorTemperature iid', control.iid)
|
|
271
285
|
}
|
|
272
286
|
if (control.curve != null) {
|
|
273
|
-
if (control.curve.adjustmentIid !== this.
|
|
287
|
+
if (control.curve.adjustmentIid !== this.briIid) {
|
|
274
288
|
throw new Error('%d: bad Brightness iid', control.curve.adjustmentIid)
|
|
275
289
|
}
|
|
276
290
|
this._control = control
|
package/lib/Colour.js
CHANGED
package/lib/CommandLineParser.js
CHANGED
|
@@ -201,11 +201,7 @@ See ${this._packageJson.homepage.split('#')[0]} for more info.
|
|
|
201
201
|
parameter (key, callback, optional = false) {
|
|
202
202
|
key = homebridgeLib.OptionParser.toString('key', key, true)
|
|
203
203
|
callback = homebridgeLib.OptionParser.toFunction('callback', callback)
|
|
204
|
-
this._callbacks.parameters.push({
|
|
205
|
-
key: key,
|
|
206
|
-
callback: callback,
|
|
207
|
-
optional: optional
|
|
208
|
-
})
|
|
204
|
+
this._callbacks.parameters.push({ key, callback, optional })
|
|
209
205
|
return this
|
|
210
206
|
}
|
|
211
207
|
|
package/lib/HttpClient.js
CHANGED
|
@@ -349,14 +349,14 @@ class HttpClient extends events.EventEmitter {
|
|
|
349
349
|
const requestId = ++this.__requestId
|
|
350
350
|
const url = this.__params.url + (resource === '/' ? '' : resource) +
|
|
351
351
|
this.__params.suffix + suffix
|
|
352
|
-
const options = Object.assign({ method
|
|
352
|
+
const options = Object.assign({ method }, this.__options)
|
|
353
353
|
const requestInfo = Object.assign({
|
|
354
354
|
name: this.name,
|
|
355
355
|
id: requestId,
|
|
356
|
-
method
|
|
357
|
-
resource
|
|
358
|
-
body
|
|
359
|
-
url
|
|
356
|
+
method,
|
|
357
|
+
resource,
|
|
358
|
+
body,
|
|
359
|
+
url
|
|
360
360
|
}, info)
|
|
361
361
|
const request = this._http.request(url, options)
|
|
362
362
|
request
|
package/lib/JsonFormatter.js
CHANGED
|
@@ -185,9 +185,9 @@ class JsonFormatter {
|
|
|
185
185
|
obj[`/${keys.join('/')}`] = value
|
|
186
186
|
return obj
|
|
187
187
|
} else {
|
|
188
|
-
if (this.options.keysOnly) { return { keys
|
|
189
|
-
if (this.options.valuesOnly) { return { value
|
|
190
|
-
return { keys
|
|
188
|
+
if (this.options.keysOnly) { return { keys } }
|
|
189
|
+
if (this.options.valuesOnly) { return { value } }
|
|
190
|
+
return { keys, value }
|
|
191
191
|
}
|
|
192
192
|
})
|
|
193
193
|
if (this.options.ascii) {
|
package/lib/Platform.js
CHANGED
|
@@ -116,6 +116,12 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
116
116
|
|
|
117
117
|
get Characteristics () { return context.Characteristics }
|
|
118
118
|
|
|
119
|
+
/** Content of the plugin's package.json file.
|
|
120
|
+
* @type {object}
|
|
121
|
+
* @readonly
|
|
122
|
+
*/
|
|
123
|
+
get packageJson () { return context.packageJson }
|
|
124
|
+
|
|
119
125
|
/** Create a new instance of the platform plugin.
|
|
120
126
|
*
|
|
121
127
|
* Called by Homebridge when initialising the plugin from `config.json`.
|
|
@@ -466,10 +472,10 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
466
472
|
this._accessories[id] = accessory
|
|
467
473
|
accessory.displayName = name
|
|
468
474
|
accessory.context = {
|
|
469
|
-
className
|
|
470
|
-
version
|
|
471
|
-
id
|
|
472
|
-
name
|
|
475
|
+
className,
|
|
476
|
+
version,
|
|
477
|
+
id,
|
|
478
|
+
name,
|
|
473
479
|
logLevel: this.logLevel,
|
|
474
480
|
context: {}
|
|
475
481
|
}
|
package/lib/PropertyDelegate.js
CHANGED
|
@@ -48,6 +48,10 @@ class Motion extends History {
|
|
|
48
48
|
* @param {!CharacteristicDelegate} lastActivationDelegate - A reference to the
|
|
49
49
|
* delegate of the associated `Characteristics.eve.LastActivation`
|
|
50
50
|
* characteristic.
|
|
51
|
+
* @param {?CharacteristicDelegate} lightLevelDelegate - A reference to the
|
|
52
|
+
* delegate of the associated `Characteristics.hap.CurrentAmbientLightLevel`
|
|
53
|
+
* characteristic. For PIR sensors (like the Hue motion sensor) that report
|
|
54
|
+
* light level in addition to motion.
|
|
51
55
|
* @param {?CharacteristicDelegate} temperatureDelegate - A reference to the
|
|
52
56
|
* delegate of the associated `Characteristics.hap.CurrentTemperature`
|
|
53
57
|
* characteristic. For PIR sensors (like the Hue motion sensor) that report
|
|
@@ -55,7 +59,8 @@ class Motion extends History {
|
|
|
55
59
|
*/
|
|
56
60
|
constructor (
|
|
57
61
|
accessoryDelegate, params,
|
|
58
|
-
motionDelegate, lastActivationDelegate,
|
|
62
|
+
motionDelegate, lastActivationDelegate,
|
|
63
|
+
lightLevelDelegate, temperatureDelegate
|
|
59
64
|
) {
|
|
60
65
|
super(accessoryDelegate, params)
|
|
61
66
|
if (!(motionDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
@@ -64,6 +69,12 @@ class Motion extends History {
|
|
|
64
69
|
if (!(lastActivationDelegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
65
70
|
throw new TypeError('lastActivationDelegate: not a CharacteristicDelegate')
|
|
66
71
|
}
|
|
72
|
+
if (
|
|
73
|
+
lightLevelDelegate != null &&
|
|
74
|
+
!(lightLevelDelegate instanceof homebridgeLib.CharacteristicDelegate)
|
|
75
|
+
) {
|
|
76
|
+
throw new TypeError('lightLevelDelegate: not a CharacteristicDelegate')
|
|
77
|
+
}
|
|
67
78
|
if (
|
|
68
79
|
temperatureDelegate != null &&
|
|
69
80
|
!(temperatureDelegate instanceof homebridgeLib.CharacteristicDelegate)
|
|
@@ -76,14 +87,23 @@ class Motion extends History {
|
|
|
76
87
|
lastActivationDelegate.value = now - this._h.initialTime
|
|
77
88
|
this._entry.status = value
|
|
78
89
|
if (this._entry.temp != null) {
|
|
90
|
+
const lightlevel = this._entry.lightlevel
|
|
79
91
|
const temp = this._entry.temp
|
|
92
|
+
this._entry.lightlevel = null
|
|
80
93
|
this._entry.temp = null
|
|
81
94
|
this._addEntry(now)
|
|
95
|
+
this._entry.lightlevel = lightlevel
|
|
82
96
|
this._entry.temp = temp
|
|
83
97
|
} else {
|
|
84
98
|
this._addEntry(now)
|
|
85
99
|
}
|
|
86
100
|
})
|
|
101
|
+
if (lightLevelDelegate != null) {
|
|
102
|
+
this._entry.lightlevel = lightLevelDelegate.value
|
|
103
|
+
lightLevelDelegate.on('didSet', (value) => {
|
|
104
|
+
this._entry.lightlevel = value
|
|
105
|
+
})
|
|
106
|
+
}
|
|
87
107
|
if (temperatureDelegate != null) {
|
|
88
108
|
this._entry.temp = temperatureDelegate.value
|
|
89
109
|
temperatureDelegate.on('didSet', (value) => {
|
|
@@ -93,23 +113,42 @@ class Motion extends History {
|
|
|
93
113
|
}
|
|
94
114
|
|
|
95
115
|
get _fingerPrint () {
|
|
96
|
-
return '
|
|
116
|
+
return '03 1c01 3002 0102'
|
|
97
117
|
}
|
|
98
118
|
|
|
99
119
|
_entryStream (entry) {
|
|
100
120
|
if (entry.temp == null) {
|
|
121
|
+
if (entry.lightlevel == null) {
|
|
122
|
+
return util.format(
|
|
123
|
+
'|0b %s %s 01 %s',
|
|
124
|
+
numToHex(swap32(this._h.currentEntry), 8),
|
|
125
|
+
numToHex(swap32(entry.time - this._h.initialTime), 8),
|
|
126
|
+
numToHex(entry.status, 2)
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
return util.format(
|
|
130
|
+
'|0d %s %s 03 %s %s',
|
|
131
|
+
numToHex(swap32(this._h.currentEntry), 8),
|
|
132
|
+
numToHex(swap32(entry.time - this._h.initialTime), 8),
|
|
133
|
+
numToHex(entry.status, 2),
|
|
134
|
+
numToHex(swap16(entry.lightlevel), 4)
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
if (entry.lightlevel == null) {
|
|
101
138
|
return util.format(
|
|
102
|
-
'|
|
|
139
|
+
'|0d %s %s 05 %s %s',
|
|
103
140
|
numToHex(swap32(this._h.currentEntry), 8),
|
|
104
141
|
numToHex(swap32(entry.time - this._h.initialTime), 8),
|
|
105
|
-
numToHex(entry.status, 2)
|
|
142
|
+
numToHex(entry.status, 2),
|
|
143
|
+
numToHex(swap16(entry.temp * 100), 4)
|
|
106
144
|
)
|
|
107
145
|
}
|
|
108
146
|
return util.format(
|
|
109
|
-
'|
|
|
147
|
+
'|0f %s %s 07 %s %s %s',
|
|
110
148
|
numToHex(swap32(this._h.currentEntry), 8),
|
|
111
149
|
numToHex(swap32(entry.time - this._h.initialTime), 8),
|
|
112
150
|
numToHex(entry.status, 2),
|
|
151
|
+
numToHex(swap16(entry.lightlevel), 4),
|
|
113
152
|
numToHex(swap16(entry.temp * 100), 4)
|
|
114
153
|
)
|
|
115
154
|
}
|
package/lib/SystemInfo.js
CHANGED
|
@@ -150,19 +150,19 @@ class SystemInfo extends events.EventEmitter {
|
|
|
150
150
|
gpioMask = 0x03E6CF93 // 0-1, 4, 7-11, 14-15, 17-18, 21-25
|
|
151
151
|
}
|
|
152
152
|
return {
|
|
153
|
-
gpioMask
|
|
153
|
+
gpioMask,
|
|
154
154
|
gpioMaskSerial: (1 << 15) | (1 << 14),
|
|
155
|
-
id
|
|
155
|
+
id,
|
|
156
156
|
isRpi: true,
|
|
157
|
-
manufacturer
|
|
158
|
-
memory
|
|
159
|
-
model
|
|
160
|
-
modelRevision
|
|
157
|
+
manufacturer,
|
|
158
|
+
memory,
|
|
159
|
+
model,
|
|
160
|
+
modelRevision,
|
|
161
161
|
prettyName: [
|
|
162
162
|
'Raspberry Pi', model, modelRevision, '(' + memory + ')'
|
|
163
163
|
].join(' '),
|
|
164
164
|
powerLed: !(['A', 'B', 'Zero', 'Zero W', 'Zero 2 W'].includes(model)),
|
|
165
|
-
processor
|
|
165
|
+
processor,
|
|
166
166
|
revision: homebridgeLib.toHexString(revision, 6),
|
|
167
167
|
usbPower: ['B+', '2B', '3B', '3B+'].includes(model)
|
|
168
168
|
}
|
|
@@ -249,13 +249,7 @@ class SystemInfo extends events.EventEmitter {
|
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
|
-
return {
|
|
253
|
-
name: name,
|
|
254
|
-
platform: platform,
|
|
255
|
-
prettyName: prettyName,
|
|
256
|
-
version: version,
|
|
257
|
-
versionName: versionName
|
|
258
|
-
}
|
|
252
|
+
return { name, platform, prettyName, version, versionName }
|
|
259
253
|
}
|
|
260
254
|
|
|
261
255
|
/** Extract Apple Mac hardware info from `system_profiler` command.
|
|
@@ -315,15 +309,15 @@ class SystemInfo extends events.EventEmitter {
|
|
|
315
309
|
this.emit('error', error)
|
|
316
310
|
}
|
|
317
311
|
return {
|
|
318
|
-
id
|
|
312
|
+
id,
|
|
319
313
|
isMac: true,
|
|
320
314
|
manufacturer: 'Apple Inc.',
|
|
321
|
-
memory
|
|
322
|
-
model
|
|
323
|
-
nCores
|
|
315
|
+
memory,
|
|
316
|
+
model,
|
|
317
|
+
nCores,
|
|
324
318
|
prettyName: prettyName || model,
|
|
325
|
-
processor
|
|
326
|
-
revision
|
|
319
|
+
processor,
|
|
320
|
+
revision
|
|
327
321
|
}
|
|
328
322
|
}
|
|
329
323
|
|
|
@@ -361,13 +355,13 @@ class SystemInfo extends events.EventEmitter {
|
|
|
361
355
|
}
|
|
362
356
|
const versionName = macOsInfo.versionNames[v] // e.g. 'Monterey'
|
|
363
357
|
return {
|
|
364
|
-
build
|
|
358
|
+
build,
|
|
365
359
|
catalina: semver.gte(version, '10.15.0'),
|
|
366
|
-
name
|
|
360
|
+
name,
|
|
367
361
|
platform: process.platform,
|
|
368
362
|
prettyName: [name, versionName, version, '(' + build + ')'].join(' '),
|
|
369
|
-
version
|
|
370
|
-
versionName
|
|
363
|
+
version,
|
|
364
|
+
versionName
|
|
371
365
|
}
|
|
372
366
|
}
|
|
373
367
|
|
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.6.0",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"homekit",
|
|
9
9
|
"homebridge"
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"upnp": "cli/upnp.js"
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
|
-
"homebridge": "^1.4.
|
|
25
|
-
"node": "^16.
|
|
24
|
+
"homebridge": "^1.4.1",
|
|
25
|
+
"node": "^16.15.1"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@homebridge/plugin-ui-utils": "~0.0.19",
|