homebridge-lib 6.3.2 → 6.3.4
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/AccessoryDelegate.js
CHANGED
|
@@ -109,9 +109,22 @@ class AccessoryDelegate extends homebridgeLib.Delegate {
|
|
|
109
109
|
})
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
/** Destroy accessory delegate and associated HomeKit accessory.
|
|
113
|
+
* @params {boolean} [delegateOnly=false] - Destroy the delegate, but keep the
|
|
114
|
+
* associated HomeKit accessory (including context).
|
|
115
|
+
*/
|
|
116
|
+
destroy (delegateOnly = false) {
|
|
114
117
|
this.removeAllListeners()
|
|
118
|
+
for (const key in this._serviceDelegates) {
|
|
119
|
+
this._serviceDelegates[key].destroy(delegateOnly)
|
|
120
|
+
}
|
|
121
|
+
for (const key in this._propertyDelegates) {
|
|
122
|
+
this._propertyDelegates[key]._destroy(delegateOnly)
|
|
123
|
+
}
|
|
124
|
+
if (delegateOnly) {
|
|
125
|
+
this._accessory.removeAllListeners()
|
|
126
|
+
return
|
|
127
|
+
}
|
|
115
128
|
this._platform._removeAccessory(this._accessory)
|
|
116
129
|
}
|
|
117
130
|
|
|
@@ -122,10 +135,13 @@ class AccessoryDelegate extends homebridgeLib.Delegate {
|
|
|
122
135
|
return serviceDelegate
|
|
123
136
|
}
|
|
124
137
|
|
|
125
|
-
_unlinkServiceDelegate (serviceDelegate) {
|
|
138
|
+
_unlinkServiceDelegate (serviceDelegate, delegateOnly) {
|
|
126
139
|
const key = serviceDelegate._key
|
|
127
140
|
// this.debug('unlink service %s', key)
|
|
128
141
|
delete this._serviceDelegates[key]
|
|
142
|
+
if (delegateOnly) {
|
|
143
|
+
return
|
|
144
|
+
}
|
|
129
145
|
delete this._context[key]
|
|
130
146
|
}
|
|
131
147
|
|
|
@@ -136,6 +136,7 @@ class CharacteristicDelegate extends homebridgeLib.Delegate {
|
|
|
136
136
|
// Install getter and setter when needed.
|
|
137
137
|
if (params.getter != null && typeof params.getter === 'function') {
|
|
138
138
|
this._getter = params.getter
|
|
139
|
+
this._onGetCount = 0
|
|
139
140
|
this._characteristic.on('get', this._onGet.bind(this))
|
|
140
141
|
}
|
|
141
142
|
if (this._canWrite && Characteristic !== this.Characteristics.hap.Identify) {
|
|
@@ -167,13 +168,21 @@ class CharacteristicDelegate extends homebridgeLib.Delegate {
|
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
170
|
|
|
170
|
-
/** Destroy
|
|
171
|
-
*
|
|
172
|
-
*
|
|
171
|
+
/** Destroy characteristic delegate and delete associated HomeKit characteristic.
|
|
172
|
+
* @params {boolean} [delegateOnly=false] - Destroy the delegate, but keep the
|
|
173
|
+
* associated HomeKit characteristic (including context).
|
|
173
174
|
*/
|
|
174
|
-
_destroy () {
|
|
175
|
+
_destroy (delegateOnly = false) {
|
|
175
176
|
this.debug('destroy %s', this._key)
|
|
176
177
|
this.removeAllListeners()
|
|
178
|
+
if (delegateOnly) {
|
|
179
|
+
if (this._characteristic != null) {
|
|
180
|
+
// this._characteristic.removeAllListeners() // Doesn't work ?!
|
|
181
|
+
this._characteristic.removeAllListeners('get')
|
|
182
|
+
this._characteristic.removeAllListeners('set')
|
|
183
|
+
}
|
|
184
|
+
return
|
|
185
|
+
}
|
|
177
186
|
if (this._characteristic != null) {
|
|
178
187
|
this._service.removeCharacteristic(this._characteristic)
|
|
179
188
|
}
|
|
@@ -338,7 +347,6 @@ class CharacteristicDelegate extends homebridgeLib.Delegate {
|
|
|
338
347
|
let value = this.value
|
|
339
348
|
const timeout = setTimeout(() => {
|
|
340
349
|
timedOut = true
|
|
341
|
-
this.warn('get: timed out - return previous value %j%s', this.value, this._unit)
|
|
342
350
|
callback(null, this.value)
|
|
343
351
|
}, this._timeout)
|
|
344
352
|
try {
|
package/lib/PropertyDelegate.js
CHANGED
|
@@ -60,10 +60,15 @@ class PropertyDelegate extends homebridgeLib.Delegate {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/** Destroy the propery delegate.
|
|
63
|
+
* @params {boolean} [delegateOnly=false] - Destroy the delegate, but keep the
|
|
64
|
+
* associated value in context.
|
|
63
65
|
*/
|
|
64
|
-
_destroy () {
|
|
66
|
+
_destroy (delegateOnly = false) {
|
|
65
67
|
this.vdebug('destroy')
|
|
66
68
|
this.removeAllListeners()
|
|
69
|
+
if (delegateOnly) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
67
72
|
delete this._parent._context[this.key]
|
|
68
73
|
}
|
|
69
74
|
|
|
@@ -102,6 +102,11 @@ class AirPressureValue extends HistoryValue {
|
|
|
102
102
|
prepareEntry (entry) { entry[this.id] = this._delegate.value * 10 }
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
class VocLevelValue extends HistoryValue {
|
|
106
|
+
get tag () { return 0x04 }
|
|
107
|
+
get id () { return 'r' }
|
|
108
|
+
}
|
|
109
|
+
|
|
105
110
|
class ContactValue extends HistoryValue {
|
|
106
111
|
get tag () { return 0x06 }
|
|
107
112
|
get length () { return 1 }
|
|
@@ -145,7 +150,7 @@ class ConsumptionValue extends HistoryValue {
|
|
|
145
150
|
prepareEntry (entry) {
|
|
146
151
|
const delta = this._delegate.value - this._consumption // kWh
|
|
147
152
|
const period = entry.time - this._time // s
|
|
148
|
-
const power = 1000 * 3600 * delta / period // W
|
|
153
|
+
const power = period === 0 ? 0 : 1000 * 3600 * delta / period // W
|
|
149
154
|
if (this._parent.computedPowerDelegate != null) {
|
|
150
155
|
this._parent.computedPowerDelegate.value = Math.round(power) // W
|
|
151
156
|
}
|
|
@@ -162,7 +167,7 @@ class PowerValue extends HistoryValue {
|
|
|
162
167
|
constructor (parent, delegate) {
|
|
163
168
|
super(parent, delegate)
|
|
164
169
|
this._runningConsumption = 0 // 10-min-interval running value
|
|
165
|
-
this._totalConsumption = parent.computedConsumptionDelegate.value
|
|
170
|
+
this._totalConsumption = parent.computedConsumptionDelegate.value * 100
|
|
166
171
|
this._power = delegate.value // current power
|
|
167
172
|
this._time = History.now() // start time of current power
|
|
168
173
|
delegate.on('didSet', (value) => {
|
|
@@ -195,6 +200,25 @@ class PowerValue extends HistoryValue {
|
|
|
195
200
|
}
|
|
196
201
|
}
|
|
197
202
|
|
|
203
|
+
class SwitchOnValue extends HistoryValue {
|
|
204
|
+
get tag () { return 0x0E }
|
|
205
|
+
get length () { return 1 }
|
|
206
|
+
get id () { return 'w' }
|
|
207
|
+
prepareEntry (entry) { entry[this.id] = this._delegate.value ? 1 : 0 }
|
|
208
|
+
writeEntry (entry, buffer, offset) { buffer.writeInt8(entry[this.id], offset) }
|
|
209
|
+
|
|
210
|
+
constructor (parent, delegate) {
|
|
211
|
+
super(parent, delegate)
|
|
212
|
+
delegate.on('didSet', (value) => {
|
|
213
|
+
const now = History.now()
|
|
214
|
+
const entry = { time: now }
|
|
215
|
+
entry[this.id] = this._delegate.value ? 1 : 0
|
|
216
|
+
this._parent.addEntry(entry)
|
|
217
|
+
parent.lastSwitchOnDelegate.value = parent.lastActivationValue(now)
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
198
222
|
class ValvePositionValue extends HistoryValue {
|
|
199
223
|
get tag () { return 0x10 }
|
|
200
224
|
get length () { return 1 }
|
|
@@ -261,9 +285,11 @@ class LightLevelValue extends HistoryValue {
|
|
|
261
285
|
const historyValueTypes = {
|
|
262
286
|
temperature: TemperatureValue,
|
|
263
287
|
humidity: HumidityValue,
|
|
288
|
+
vocLevel: VocLevelValue,
|
|
264
289
|
airPressure: AirPressureValue,
|
|
265
290
|
contact: ContactValue,
|
|
266
291
|
power: PowerValue,
|
|
292
|
+
switchOn: SwitchOnValue,
|
|
267
293
|
consumption: ConsumptionValue,
|
|
268
294
|
valvePosition: ValvePositionValue,
|
|
269
295
|
targetTemperature: TargetTemperatureValue,
|
|
@@ -280,6 +306,7 @@ const historyDerivedTypes = {
|
|
|
280
306
|
lastMotion: 'motion',
|
|
281
307
|
lastOn: 'on',
|
|
282
308
|
lastLightOn: 'lightOn',
|
|
309
|
+
lastSwitchOn: 'switchOn',
|
|
283
310
|
computedConsumption: 'power',
|
|
284
311
|
computedPower: 'consumption'
|
|
285
312
|
}
|
|
@@ -347,12 +374,6 @@ class History extends ServiceDelegate {
|
|
|
347
374
|
* @param {?CharacteristicDelegate} params.lastOnDelegate - The
|
|
348
375
|
* `.eve.LastActivation` characteristic delegate
|
|
349
376
|
* for a `hap.Outlet` service.
|
|
350
|
-
* @param {?CharacteristicDelegate} params.lightOnDelegate - The
|
|
351
|
-
* `Characteristics.hap.On` characteristic delegate
|
|
352
|
-
* for a `hap.Lightbulb` service.
|
|
353
|
-
* @param {?CharacteristicDelegate} params.lastLightOnDelegate - A
|
|
354
|
-
* `.eve.LastActivation` characteristic delegate
|
|
355
|
-
* for a `hap.Lightbulb` service.
|
|
356
377
|
* @param {?CharacteristicDelegate} params.powerDelegate - The
|
|
357
378
|
* `.eve.CurrentConsumption` characteristic delegate
|
|
358
379
|
* for a `hap.Outlet` or `eve.Consumption` service
|
|
@@ -369,6 +390,18 @@ class History extends ServiceDelegate {
|
|
|
369
390
|
* `.eve.CurrentConsumption` characteristic delegate
|
|
370
391
|
* for a `hap.Outlet` or `eve.Consumption` service
|
|
371
392
|
* for a device that reports total consumption but not current consumption.
|
|
393
|
+
* @param {?CharacteristicDelegate} params.lightOnDelegate - The
|
|
394
|
+
* `Characteristics.hap.On` characteristic delegate
|
|
395
|
+
* for a `hap.Lightbulb` service.
|
|
396
|
+
* @param {?CharacteristicDelegate} params.lastLightOnDelegate - A
|
|
397
|
+
* `.eve.LastActivation` characteristic delegate
|
|
398
|
+
* for a `hap.Lightbulb` service.
|
|
399
|
+
* @param {?CharacteristicDelegate} params.switchOnDelegate - The
|
|
400
|
+
* `Characteristics.hap.On` characteristic delegate
|
|
401
|
+
* for a `hap.Switch` service.
|
|
402
|
+
* @param {?CharacteristicDelegate} params.lastSwitchOnDelegate - A
|
|
403
|
+
* `.eve.LastActivation` characteristic delegate
|
|
404
|
+
* for a `hap.Switch` service.
|
|
372
405
|
* @param {integer} [params.memorySize=4032] - The memory size, in number of
|
|
373
406
|
* history entries. The default is 4 weeks of 1 entry per 10 minutes.
|
|
374
407
|
* @param {?boolean} params.config - Expose config.
|
|
@@ -169,17 +169,20 @@ class ServiceDelegate extends homebridgeLib.Delegate {
|
|
|
169
169
|
})
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
/** Destroy
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* Removes the associated HomeKit service.
|
|
172
|
+
/** Destroy service delegate and associated HomeKit service.
|
|
173
|
+
* @params {boolean} [delegateOnly=false] - Destroy the delegate, but keep the
|
|
174
|
+
* associated HomeKit service (including context).
|
|
176
175
|
*/
|
|
177
|
-
destroy () {
|
|
176
|
+
destroy (delegateOnly = false) {
|
|
178
177
|
this.debug('destroy %s (%s)', this._key, this.constructor.name)
|
|
179
|
-
this._accessoryDelegate._unlinkServiceDelegate(this)
|
|
178
|
+
this._accessoryDelegate._unlinkServiceDelegate(this, delegateOnly)
|
|
180
179
|
this.removeAllListeners()
|
|
181
180
|
for (const key in this._characteristicDelegates) {
|
|
182
|
-
this._characteristicDelegates[key]._destroy()
|
|
181
|
+
this._characteristicDelegates[key]._destroy(delegateOnly)
|
|
182
|
+
}
|
|
183
|
+
if (delegateOnly) {
|
|
184
|
+
this._service.removeAllListeners()
|
|
185
|
+
return
|
|
183
186
|
}
|
|
184
187
|
this._accessory.removeService(this._service)
|
|
185
188
|
delete this._accessory.context[this._key]
|