homebridge-lib 5.1.24-6 → 5.2.3-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/AccessoryDelegate.js +21 -23
- package/lib/EveHomeKitTypes.js +43 -13
- package/lib/MyHomeKitTypes.js +2 -1
- package/lib/Platform.js +58 -132
- package/lib/ServiceDelegate/AccessoryInformation.js +111 -0
- package/lib/ServiceDelegate/Battery.js +87 -0
- package/lib/ServiceDelegate/Dummy.js +44 -0
- package/lib/ServiceDelegate/History/Consumption.js +114 -0
- package/lib/ServiceDelegate/History/Contact.js +100 -0
- package/lib/ServiceDelegate/History/Motion.js +118 -0
- package/lib/ServiceDelegate/History/On.js +86 -0
- package/lib/ServiceDelegate/History/Power.js +121 -0
- package/lib/ServiceDelegate/History/Room.js +115 -0
- package/lib/ServiceDelegate/History/Thermo.js +102 -0
- package/lib/ServiceDelegate/History/Weather.js +127 -0
- package/lib/ServiceDelegate/History/index.js +344 -0
- package/lib/ServiceDelegate/ServiceLabel.js +47 -0
- package/lib/ServiceDelegate/index.js +332 -0
- package/package.json +3 -3
- package/lib/ServiceDelegate.js +0 -1447
package/lib/AccessoryDelegate.js
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
const homebridgeLib = require('../index')
|
|
9
9
|
|
|
10
|
-
const maxLogLevel = 4
|
|
11
10
|
const startsWithUuid = /^[0-9A-F]{8}-[0-9A-F]{4}-[1-5][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}/
|
|
12
11
|
|
|
13
12
|
/** Delegate of a HomeKit accessory.
|
|
@@ -35,9 +34,6 @@ class AccessoryDelegate extends homebridgeLib.Delegate {
|
|
|
35
34
|
* @param {!string} params.firmware - The accessory firmware revision.
|
|
36
35
|
* @param {?string} params.hardware - The accessory hardware revision.
|
|
37
36
|
* @param {?string} params.software - The accessory software revision.
|
|
38
|
-
* @param {integer} params.logLevel - The log level for the accessory.
|
|
39
|
-
* @param {?boolean} [params.inheritLogLevel] - Inherit `logLevel` from
|
|
40
|
-
* `platform` instead of maintaining it oneself.
|
|
41
37
|
*/
|
|
42
38
|
constructor (platform, params = {}) {
|
|
43
39
|
if (params.name == null) {
|
|
@@ -53,18 +49,16 @@ class AccessoryDelegate extends homebridgeLib.Delegate {
|
|
|
53
49
|
|
|
54
50
|
// Link or create associated PlatformAccessory.
|
|
55
51
|
this._accessory = this._platform._getAccessory(this, params)
|
|
56
|
-
this._context = this._accessory.context
|
|
57
52
|
|
|
58
53
|
if (params.logLevel != null) {
|
|
59
|
-
this.
|
|
60
|
-
} else if (params.inheritLogLevel != null) {
|
|
61
|
-
if (params.inheritLogLevel) {
|
|
62
|
-
Object.defineProperty(this, 'logLevel', {
|
|
63
|
-
get () { return platform.logLevel }
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
delete params.inheritLogLevel
|
|
54
|
+
this.warn('params.logLevel: deprecated')
|
|
67
55
|
}
|
|
56
|
+
if (params.inheritLogLevel != null) {
|
|
57
|
+
this.warn('params.inheritLogLevel: deprecated')
|
|
58
|
+
}
|
|
59
|
+
this._context = this._accessory.context
|
|
60
|
+
|
|
61
|
+
delete this._context.logLevel
|
|
68
62
|
|
|
69
63
|
// Setup shortcut for property values and values of the characteristics
|
|
70
64
|
// of the _Accessory Information_ service.
|
|
@@ -270,16 +264,7 @@ class AccessoryDelegate extends homebridgeLib.Delegate {
|
|
|
270
264
|
* @type {!integer}
|
|
271
265
|
*/
|
|
272
266
|
get logLevel () {
|
|
273
|
-
return this.
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
set logLevel (value) {
|
|
277
|
-
const oldLogLevel = this._context.logLevel
|
|
278
|
-
this._context.logLevel = Math.max(0, Math.min(value, maxLogLevel))
|
|
279
|
-
this._platform._message(
|
|
280
|
-
'log', 2, this.name + ': ',
|
|
281
|
-
'set Log Level from %d to %d', oldLogLevel, this.logLevel
|
|
282
|
-
)
|
|
267
|
+
return this.platform.logLevel
|
|
283
268
|
}
|
|
284
269
|
|
|
285
270
|
/** Inherit `logLevel` from another accessory delegate.
|
|
@@ -298,6 +283,19 @@ class AccessoryDelegate extends homebridgeLib.Delegate {
|
|
|
298
283
|
})
|
|
299
284
|
}
|
|
300
285
|
|
|
286
|
+
/** Manage `logLevel` from characteristic delegate.
|
|
287
|
+
* @param {CharacteristicDelegate} delegate - The delegate of the `logLevel`
|
|
288
|
+
* characteristic.
|
|
289
|
+
*/
|
|
290
|
+
manageLogLevel (delegate) {
|
|
291
|
+
if (!(delegate instanceof homebridgeLib.CharacteristicDelegate)) {
|
|
292
|
+
throw new TypeError('delegate: not an CharacteristicDelegate')
|
|
293
|
+
}
|
|
294
|
+
Object.defineProperty(this, 'logLevel', {
|
|
295
|
+
get () { return delegate.value }
|
|
296
|
+
})
|
|
297
|
+
}
|
|
298
|
+
|
|
301
299
|
// Called by homebridge when Identify is selected.
|
|
302
300
|
_identify () {
|
|
303
301
|
this.emit('identify')
|
package/lib/EveHomeKitTypes.js
CHANGED
|
@@ -40,13 +40,12 @@ class EveHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
|
|
|
40
40
|
super(homebridge)
|
|
41
41
|
|
|
42
42
|
/** @member EveHomeKitTypes#Characteristics
|
|
43
|
-
* @property {Class} AirParticulateDensity -
|
|
44
|
-
*
|
|
45
|
-
* <br>Used by: Eve Room.
|
|
43
|
+
* @property {Class} AirParticulateDensity - Deprecated. use `VOCLevel`
|
|
44
|
+
* instead.
|
|
46
45
|
* @property {Class} AirPressure - Air pressure (in hPa).
|
|
47
46
|
* <br>Used by: Eve Weather.
|
|
48
|
-
* @property {Class} ClosedDuration -
|
|
49
|
-
*
|
|
47
|
+
* @property {Class} ClosedDuration - Duration (in seconds) that door has
|
|
48
|
+
* been closed.
|
|
50
49
|
* <br>Used by: Eve Door.
|
|
51
50
|
* @property {Class} Clouds - Cloud coverage (in %).
|
|
52
51
|
* <br>Used by: weather station.
|
|
@@ -59,6 +58,10 @@ class EveHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
|
|
|
59
58
|
* @property {Class} ConditionCategory - Weather condition
|
|
60
59
|
* (as numberic code).
|
|
61
60
|
* <br>Used by: weather station.
|
|
61
|
+
* @property {Class} ConfigCommand - Used by Eve app to set configuration.
|
|
62
|
+
* <br> Used by: `History` service.
|
|
63
|
+
* @property {Class} ConfigData - Used by Eve app to read configuration.
|
|
64
|
+
* <br> Used by: `History` service.
|
|
62
65
|
* @property {Class} CurrentConsumption - Current electric consumption
|
|
63
66
|
* (in W).
|
|
64
67
|
* <br>Used by: Eve Energy.
|
|
@@ -98,7 +101,7 @@ class EveHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
|
|
|
98
101
|
* @property {Class} ObservationTime - Time of observation.
|
|
99
102
|
* <br>Used by: weather station.
|
|
100
103
|
* @property {Class} OpenDuration - Duration (in seconds) that door has
|
|
101
|
-
* been
|
|
104
|
+
* been open.
|
|
102
105
|
* <br>Used by: Eve Door.
|
|
103
106
|
* @property {Class} Ozone - Ozone level (in DU).
|
|
104
107
|
* <br>Used by: weather station.
|
|
@@ -138,6 +141,8 @@ class EveHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
|
|
|
138
141
|
* <br>Used by: Eve Thermo.
|
|
139
142
|
* @property {Class} Visibility - Visibility (in km).
|
|
140
143
|
* <br>Used by: weather station.
|
|
144
|
+
* @property {Class} VOCLevel - Volatile Organic Compound level (in ppm).
|
|
145
|
+
* <br>Used by: Eve Room (1st gen).
|
|
141
146
|
* @property {Class} Voltage - Electric voltage (in V).
|
|
142
147
|
* <br>Used by: Eve Energy.
|
|
143
148
|
* @property {Class} WindDirection - Wind direction (as text).
|
|
@@ -167,31 +172,41 @@ class EveHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
|
|
|
167
172
|
maxValue: 5000,
|
|
168
173
|
minStep: 1,
|
|
169
174
|
perms: [this.Perms.READ, this.Perms.NOTIFY]
|
|
170
|
-
}, '
|
|
175
|
+
}, 'VOC Level')
|
|
176
|
+
|
|
177
|
+
this.createCharacteristicClass('VOCLevel', uuid('10B'), {
|
|
178
|
+
format: this.Formats.INT16,
|
|
179
|
+
unit: 'ppm',
|
|
180
|
+
minValue: 5,
|
|
181
|
+
maxValue: 5000,
|
|
182
|
+
minStep: 5,
|
|
183
|
+
perms: [this.Perms.READ, this.Perms.NOTIFY]
|
|
184
|
+
}, 'VOC Level')
|
|
171
185
|
|
|
172
186
|
this.createCharacteristicClass('TotalConsumption', uuid('10C'), {
|
|
173
187
|
format: this.Formats.FLOAT,
|
|
188
|
+
unit: 'kWh',
|
|
174
189
|
minValue: 0,
|
|
175
190
|
maxValue: 1000000,
|
|
176
191
|
minStep: 0.1,
|
|
177
|
-
unit: 'kWh',
|
|
178
192
|
perms: [this.Perms.READ, this.Perms.NOTIFY]
|
|
179
193
|
}, 'Total Consumption')
|
|
180
194
|
|
|
181
195
|
this.createCharacteristicClass('CurrentConsumption', uuid('10D'), {
|
|
182
196
|
format: this.Formats.FLOAT,
|
|
197
|
+
unit: 'W',
|
|
183
198
|
minValue: 0,
|
|
184
199
|
maxValue: 12000,
|
|
185
200
|
minStep: 0.1,
|
|
186
|
-
unit: 'W',
|
|
187
201
|
perms: [this.Perms.READ, this.Perms.NOTIFY]
|
|
188
202
|
}, 'Current Consumption')
|
|
189
203
|
|
|
190
204
|
this.createCharacteristicClass('AirPressure', uuid('10F'), {
|
|
191
|
-
format: this.Formats.
|
|
205
|
+
format: this.Formats.FLOAT,
|
|
192
206
|
unit: 'hPa',
|
|
193
207
|
minValue: 700,
|
|
194
208
|
maxValue: 1100,
|
|
209
|
+
minStep: 0.1,
|
|
195
210
|
perms: [this.Perms.READ, this.Perms.NOTIFY]
|
|
196
211
|
}, 'Air Pressure')
|
|
197
212
|
|
|
@@ -235,6 +250,11 @@ class EveHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
|
|
|
235
250
|
perms: [this.Perms.WRITE, this.Perms.HIDDEN]
|
|
236
251
|
}, 'History Request')
|
|
237
252
|
|
|
253
|
+
this.createCharacteristicClass('ConfigCommand', uuid('11D'), {
|
|
254
|
+
format: this.Formats.DATA,
|
|
255
|
+
perms: [this.Perms.WRITE, this.Perms.HIDDEN]
|
|
256
|
+
}, 'Config Command')
|
|
257
|
+
|
|
238
258
|
this.createCharacteristicClass('Sensitivity', uuid('120'), {
|
|
239
259
|
format: this.Formats.UINT8,
|
|
240
260
|
minValue: 0,
|
|
@@ -284,6 +304,11 @@ class EveHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
|
|
|
284
304
|
perms: [this.Perms.READ, this.Perms.NOTIFY, this.Perms.WRITE],
|
|
285
305
|
adminOnlyAccess: [this.Access.WRITE]
|
|
286
306
|
})
|
|
307
|
+
this.Characteristics.Duration.VALID_VALUES = [
|
|
308
|
+
5, 10, 20, 30,
|
|
309
|
+
1 * 60, 2 * 60, 3 * 60, 5 * 60, 10 * 60, 20 * 60, 30 * 60,
|
|
310
|
+
1 * 3600, 2 * 3600, 3 * 3600, 5 * 3600, 10 * 3600, 12 * 3600, 15 * 3600
|
|
311
|
+
]
|
|
287
312
|
|
|
288
313
|
this.createCharacteristicClass('ValvePosition', uuid('12E'), {
|
|
289
314
|
format: this.Formats.UINT8,
|
|
@@ -308,6 +333,11 @@ class EveHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
|
|
|
308
333
|
adminOnlyAccess: [this.Access.WRITE]
|
|
309
334
|
})
|
|
310
335
|
|
|
336
|
+
this.createCharacteristicClass('ConfigData', uuid('131'), {
|
|
337
|
+
format: this.Formats.DATA,
|
|
338
|
+
perms: [this.Perms.READ, this.Perms.NOTIFY, this.Perms.HIDDEN]
|
|
339
|
+
}, 'Config Data')
|
|
340
|
+
|
|
311
341
|
// =========================================================================
|
|
312
342
|
|
|
313
343
|
// The following custom characteristics are supported by the Eve app.
|
|
@@ -535,10 +565,10 @@ class EveHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
|
|
|
535
565
|
this.Characteristics.HistoryStatus,
|
|
536
566
|
this.Characteristics.HistoryEntries
|
|
537
567
|
], [
|
|
538
|
-
// this.Characteristics.Char11E,
|
|
568
|
+
// this.Characteristics.Char11E, // Used for firmware update?
|
|
539
569
|
this.Characteristics.ResetTotal
|
|
540
|
-
// this.Characteristics.
|
|
541
|
-
// this.Characteristics.
|
|
570
|
+
// this.Characteristics.ConfigCommand,
|
|
571
|
+
// this.Characteristics.ConfigData
|
|
542
572
|
])
|
|
543
573
|
|
|
544
574
|
this.createServiceClass('AirPressureSensor', uuid('00A'), [
|
package/lib/MyHomeKitTypes.js
CHANGED
|
@@ -589,7 +589,7 @@ class MyHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
|
|
|
589
589
|
this.createCharacteristicClass('LogLevel', uuid('065'), {
|
|
590
590
|
format: this.Formats.UINT8,
|
|
591
591
|
minValue: 0,
|
|
592
|
-
maxValue: 3,
|
|
592
|
+
maxValue: 3, // 4 for homebridge-zp
|
|
593
593
|
minStep: 1, // Force Down|Up control in Eve
|
|
594
594
|
perms: [this.Perms.READ, this.Perms.NOTIFY, this.Perms.WRITE],
|
|
595
595
|
adminOnlyAccess: [this.Access.WRITE]
|
|
@@ -598,6 +598,7 @@ class MyHomeKitTypes extends homebridgeLib.CustomHomeKitTypes {
|
|
|
598
598
|
this.Characteristics.LogLevel.LOG = 1
|
|
599
599
|
this.Characteristics.LogLevel.DEBUG = 2
|
|
600
600
|
this.Characteristics.LogLevel.VDEBUG = 3
|
|
601
|
+
this.Characteristics.LogLevel.VVDEBUG = 4
|
|
601
602
|
|
|
602
603
|
this.createCharacteristicClass('Repeat', uuid('066'), {
|
|
603
604
|
format: this.Formats.UINT8,
|
package/lib/Platform.js
CHANGED
|
@@ -27,8 +27,6 @@ const context = {
|
|
|
27
27
|
checkInterval: 7 * 24 * 3600
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const globalKey = context.libName // + '@' + context.libVersion
|
|
31
|
-
|
|
32
30
|
/** Homebridge dynamic platform plugin.
|
|
33
31
|
*
|
|
34
32
|
* `Platform` provides the following features to a platform plugin:
|
|
@@ -59,6 +57,8 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
59
57
|
static loadPlatform (homebridge, packageJson, platformName, Platform) {
|
|
60
58
|
if (context.homebridge == null) {
|
|
61
59
|
context.homebridge = homebridge
|
|
60
|
+
context.packageJson = packageJson
|
|
61
|
+
context.platformName = platformName
|
|
62
62
|
context.homebridgeVersion = homebridge.serverVersion
|
|
63
63
|
context.PlatformAccessory = homebridge.platformAccessory
|
|
64
64
|
const hap = {
|
|
@@ -98,25 +98,6 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
98
98
|
my: Object.freeze(my.Characteristics)
|
|
99
99
|
})
|
|
100
100
|
}
|
|
101
|
-
if (global[globalKey] == null) {
|
|
102
|
-
global[globalKey] = {
|
|
103
|
-
Platform: {
|
|
104
|
-
platformName: context.libName,
|
|
105
|
-
packageJson: libPackageJson,
|
|
106
|
-
UpnpClient: homebridgeLib.UpnpClient
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
homebridge.registerPlatform(
|
|
110
|
-
// libPackageJson.name, 'Lib', homebridgeLib.Platform, false
|
|
111
|
-
packageJson.name, 'Lib', homebridgeLib.Platform, false
|
|
112
|
-
)
|
|
113
|
-
// } else {
|
|
114
|
-
// TODO: check compatible homebridge-lib version.
|
|
115
|
-
}
|
|
116
|
-
global[globalKey][Platform.name] = {
|
|
117
|
-
platformName: platformName,
|
|
118
|
-
packageJson: packageJson
|
|
119
|
-
}
|
|
120
101
|
homebridge.registerPlatform(
|
|
121
102
|
packageJson.name, platformName, Platform, true
|
|
122
103
|
)
|
|
@@ -148,50 +129,19 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
148
129
|
this._log = log
|
|
149
130
|
this._configJson = configJson
|
|
150
131
|
this._homebridge = homebridge
|
|
151
|
-
|
|
152
|
-
this.
|
|
153
|
-
this.
|
|
154
|
-
|
|
155
|
-
if (myContext.packageJson.name === context.libName) {
|
|
156
|
-
this._isHomebridgeLib = true
|
|
157
|
-
myContext.heartbeat = this
|
|
158
|
-
// Delay start of Homebridge's HAP server until all plugins have
|
|
159
|
-
// initialised.
|
|
160
|
-
this.accessories = (f) => {
|
|
161
|
-
this.on('initialised', () => { f([]) })
|
|
162
|
-
}
|
|
163
|
-
// this.debug('Categories: %j', this.Accessory.Categories)
|
|
164
|
-
// for (const type of ['Access', 'Formats', 'Perms', 'Units']) {
|
|
165
|
-
// this.debug('%s: %j', type, this.Characteristic[type])
|
|
166
|
-
// }
|
|
167
|
-
// for (const module of ['hap', 'eve', 'my']) {
|
|
168
|
-
// this.debug('Services.%s: %j', module, Object.keys(this.Services[module]))
|
|
169
|
-
// this.debug('Characteristics.%s: %j', module, Object.keys(this.Characteristics[module]))
|
|
170
|
-
// }
|
|
171
|
-
} else {
|
|
172
|
-
/** Configure an accessory, after it has been restored from peristent
|
|
173
|
-
* storage.
|
|
174
|
-
*
|
|
175
|
-
* Called by homebridge when restoring peristed accessories, typically from
|
|
176
|
-
* `~/.homebridge/accessories/cachedAccessories`.
|
|
177
|
-
* @method
|
|
178
|
-
* @param {!PlatformAccessory} accessory - The restored Homebridge
|
|
179
|
-
* [PlatformAccessory](https://github.com/nfarina/homebridge/blob/master/lib/platformAccessory.js).
|
|
180
|
-
*/
|
|
181
|
-
this.configureAccessory = this._configureAccessory
|
|
182
|
-
}
|
|
132
|
+
this._platformName = context.platformName
|
|
133
|
+
this._pluginName = context.packageJson.name
|
|
134
|
+
this._pluginVersion = context.packageJson.version
|
|
135
|
+
|
|
183
136
|
this._accessories = {}
|
|
184
137
|
this._accessoryDelegates = {}
|
|
185
138
|
|
|
186
|
-
if (
|
|
139
|
+
if (context.platform != null) {
|
|
187
140
|
this.fatal(
|
|
188
|
-
'config.json: duplicate entry for %s platform',
|
|
141
|
+
'config.json: duplicate entry for %s platform', context.platformName
|
|
189
142
|
)
|
|
190
143
|
}
|
|
191
|
-
|
|
192
|
-
if (global[globalKey].Platform == null) {
|
|
193
|
-
this.fatal('%s platform not registered', context.libName)
|
|
194
|
-
}
|
|
144
|
+
context.platform = this
|
|
195
145
|
this._identify()
|
|
196
146
|
|
|
197
147
|
this._homebridge
|
|
@@ -205,54 +155,29 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
205
155
|
// Main platform function.
|
|
206
156
|
// Called by homebridge after restoring accessories from cache.
|
|
207
157
|
async _main () {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
this.
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
this.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
this.on('exit', () => {
|
|
232
|
-
this.debug('flush cachedAccessories')
|
|
233
|
-
this._homebridge.updatePlatformAccessories()
|
|
234
|
-
this.log('goodbye')
|
|
235
|
-
})
|
|
236
|
-
} else {
|
|
237
|
-
this.systemInfo = global[globalKey].Platform.heartbeat.systemInfo
|
|
238
|
-
}
|
|
239
|
-
if (this._isHomebridgeLib) {
|
|
240
|
-
const jobs = []
|
|
241
|
-
for (const plugin in global[globalKey]) {
|
|
242
|
-
const platform = global[globalKey][plugin].platform
|
|
243
|
-
if (
|
|
244
|
-
platform != null && platform !== this &&
|
|
245
|
-
Object.keys(platform._accessories).length === 0
|
|
246
|
-
) {
|
|
247
|
-
this.warn('waiting on %s', plugin)
|
|
248
|
-
jobs.push(events.once(platform, 'initialised'))
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
for (const job of jobs) {
|
|
252
|
-
await job
|
|
253
|
-
}
|
|
254
|
-
this.emit('initialised')
|
|
255
|
-
}
|
|
158
|
+
// process.on('unhandledRejection', (error) => {
|
|
159
|
+
// this.error('unhandled rejection: %s', error.stack)
|
|
160
|
+
// })
|
|
161
|
+
/** System information.
|
|
162
|
+
* @type {SystemInfo}
|
|
163
|
+
* @readonly
|
|
164
|
+
*/
|
|
165
|
+
this.systemInfo = new homebridgeLib.SystemInfo()
|
|
166
|
+
this.systemInfo
|
|
167
|
+
.on('error', (error) => { this.warn(error) })
|
|
168
|
+
.on('exec', (command) => { this.debug('exec: %s', command) })
|
|
169
|
+
.on('readFile', (filename) => { this.debug('read file: %s', filename) })
|
|
170
|
+
await this.systemInfo.init()
|
|
171
|
+
this.log('hardware: %s', this.systemInfo.hwInfo.prettyName)
|
|
172
|
+
this.log('os: %s', this.systemInfo.osInfo.prettyName)
|
|
173
|
+
this._heartbeatStart = new Date()
|
|
174
|
+
setTimeout(() => { this._beat(-1) }, 1000)
|
|
175
|
+
this.on('exit', () => {
|
|
176
|
+
this.debug('flush cachedAccessories')
|
|
177
|
+
this._homebridge.updatePlatformAccessories()
|
|
178
|
+
this.log('goodbye')
|
|
179
|
+
})
|
|
180
|
+
|
|
256
181
|
const n = Object.keys(this._accessories).length
|
|
257
182
|
if (n > 0) {
|
|
258
183
|
this.log('restored %d accessories from cache', n)
|
|
@@ -301,15 +226,11 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
301
226
|
this._homebridge.updatePlatformAccessories()
|
|
302
227
|
}
|
|
303
228
|
|
|
304
|
-
for (const plugin of this.heartbeatClients) {
|
|
305
|
-
global[globalKey][plugin].platform._heartbeat(beat)
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
_heartbeat (beat) {
|
|
310
229
|
if (beat % context.checkInterval === 0) {
|
|
311
|
-
this._checkLatest()
|
|
230
|
+
this._checkLatest(this._pluginName, this._pluginVersion)
|
|
231
|
+
this._checkLatest(context.libName, context.libVersion)
|
|
312
232
|
}
|
|
233
|
+
|
|
313
234
|
/** Emitted every second.
|
|
314
235
|
* @event Platform#heartbeat
|
|
315
236
|
* @param {number} beat - The sequence number of this heartbeat.
|
|
@@ -364,13 +285,10 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
364
285
|
|
|
365
286
|
// Issue an identity message.
|
|
366
287
|
_identify () {
|
|
367
|
-
const s = this._isHomebridgeLib
|
|
368
|
-
? ''
|
|
369
|
-
: ', ' + context.libName + ' v' + context.libVersion
|
|
370
288
|
this.log(
|
|
371
|
-
'%s v%s, node v%s, homebridge v%s%s',
|
|
372
|
-
this._pluginName, this._pluginVersion,
|
|
373
|
-
context.
|
|
289
|
+
'%s v%s, node v%s, homebridge v%s, %s v%s',
|
|
290
|
+
this._pluginName, this._pluginVersion, context.nodeVersion,
|
|
291
|
+
context.homebridgeVersion, context.libName, context.libVersion
|
|
374
292
|
)
|
|
375
293
|
if (context.nodeVersion !== context.recommendedNodeVersion) {
|
|
376
294
|
this.warn(
|
|
@@ -391,16 +309,16 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
391
309
|
}
|
|
392
310
|
|
|
393
311
|
// Check the NPM registry for the latest version of this plugin.
|
|
394
|
-
async _checkLatest () {
|
|
312
|
+
async _checkLatest (name, version) {
|
|
395
313
|
try {
|
|
396
|
-
if (
|
|
397
|
-
|
|
314
|
+
if (this.npmRegistry == null) {
|
|
315
|
+
this.npmRegistry = new homebridgeLib.HttpClient({
|
|
398
316
|
https: true,
|
|
399
317
|
host: 'registry.npmjs.org',
|
|
400
318
|
json: true,
|
|
401
319
|
maxSockets: 1
|
|
402
320
|
})
|
|
403
|
-
npmRegistry
|
|
321
|
+
this.npmRegistry
|
|
404
322
|
.on('error', (error) => {
|
|
405
323
|
this.log(
|
|
406
324
|
'npm registry: request %d: %s %s', error.request.id,
|
|
@@ -428,15 +346,14 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
428
346
|
response.statusCode, response.statusMessage
|
|
429
347
|
)
|
|
430
348
|
})
|
|
431
|
-
global[globalKey].Platform.npmRegistry = npmRegistry
|
|
432
349
|
}
|
|
433
|
-
const { body } = await
|
|
434
|
-
'/' +
|
|
350
|
+
const { body } = await this.npmRegistry.get(
|
|
351
|
+
'/' + name + '/latest', { Accept: 'application/json' })
|
|
435
352
|
if (body != null && body.version != null) {
|
|
436
|
-
if (body.version !==
|
|
437
|
-
this.warn('latest version: %s v%s',
|
|
353
|
+
if (body.version !== version) {
|
|
354
|
+
this.warn('latest version: %s v%s', name, body.version)
|
|
438
355
|
} else {
|
|
439
|
-
this.debug('latest version: %s v%s',
|
|
356
|
+
this.debug('latest version: %s v%s', name, body.version)
|
|
440
357
|
}
|
|
441
358
|
}
|
|
442
359
|
} catch (error) {
|
|
@@ -448,7 +365,16 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
448
365
|
|
|
449
366
|
// ===== Handle Accessories ==================================================
|
|
450
367
|
|
|
451
|
-
|
|
368
|
+
/** Configure an accessory, after it has been restored from peristent
|
|
369
|
+
* storage.
|
|
370
|
+
*
|
|
371
|
+
* Called by homebridge when restoring peristed accessories, typically from
|
|
372
|
+
* `~/.homebridge/accessories/cachedAccessories`.
|
|
373
|
+
* @method
|
|
374
|
+
* @param {!PlatformAccessory} accessory - The restored Homebridge
|
|
375
|
+
* [PlatformAccessory](https://github.com/nfarina/homebridge/blob/master/lib/platformAccessory.js).
|
|
376
|
+
*/
|
|
377
|
+
configureAccessory (accessory) {
|
|
452
378
|
const className = accessory.context.className
|
|
453
379
|
const version = accessory.context.version
|
|
454
380
|
const id = accessory.context.id
|
|
@@ -584,7 +510,7 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
584
510
|
if (this._upnpMonitor != null) {
|
|
585
511
|
throw new SyntaxError('upnpConfig(): already called')
|
|
586
512
|
}
|
|
587
|
-
this._upnpMonitor = new
|
|
513
|
+
this._upnpMonitor = new homebridgeLib.UpnpClient(config)
|
|
588
514
|
this._upnpMonitor
|
|
589
515
|
.on('error', (error) => {
|
|
590
516
|
this.error('upnp: error')
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// homebridge-lib/lib/ServiceDelegate/AccessoryInformation.js
|
|
2
|
+
//
|
|
3
|
+
// Library for Homebridge plugins.
|
|
4
|
+
// Copyright © 2017-2022 Erik Baauw. All rights reserved.
|
|
5
|
+
|
|
6
|
+
'use strict'
|
|
7
|
+
|
|
8
|
+
const homebridgeLib = require('../../index')
|
|
9
|
+
|
|
10
|
+
const { ServiceDelegate } = homebridgeLib
|
|
11
|
+
|
|
12
|
+
/** Class for an _AccessoryInformation_ service delegate.
|
|
13
|
+
*
|
|
14
|
+
* This delegate sets up a `Services.hap.AccessoryInformation` HomeKit service
|
|
15
|
+
* with the following HomeKit characteristics:
|
|
16
|
+
*
|
|
17
|
+
* key | Characteristic | isOptional
|
|
18
|
+
* -------------- | -------------------------------------- | ----------
|
|
19
|
+
* `name` | `Characteristics.hap.Name` |
|
|
20
|
+
* `id` | `Characteristics.hap.SerialNumber` |
|
|
21
|
+
* `manufacturer` | `Characteristics.hap.Manufacturer` |
|
|
22
|
+
* `model` | `Characteristics.hap.Model` |
|
|
23
|
+
* `firmware` | `Characteristics.hap.FirmwareRevision` |
|
|
24
|
+
* `hardware` | `Characteristics.hap.HardwareRevision` | Y
|
|
25
|
+
* `software` | `Characteristics.hap.SoftwareRevision` | Y
|
|
26
|
+
* @extends ServiceDelegate
|
|
27
|
+
* @memberof ServiceDelegate
|
|
28
|
+
*/
|
|
29
|
+
class AccessoryInformation extends ServiceDelegate {
|
|
30
|
+
/** Create a new instance of an _AccessoryInformation_ service delegate.
|
|
31
|
+
* @param {!AccessoryDelegate} accessoryDelegate - The delegate of the
|
|
32
|
+
* corresponding HomeKit accessory.
|
|
33
|
+
* @param {!object} params - The parameters for the
|
|
34
|
+
* _AccessoryInformation_ HomeKit service.
|
|
35
|
+
* @param {!string} params.name - Initial value for
|
|
36
|
+
* `Characteristics.hap.Name`. Also used to prefix log and error messages.
|
|
37
|
+
* @param {!string} params.id - Initial value for
|
|
38
|
+
* `Characteristics.hap.SerialNumber`.
|
|
39
|
+
* @param {!string} params.manufacturer - Initial value for
|
|
40
|
+
* `Characteristics.hap.Manufacturer`.
|
|
41
|
+
* @param {!string} params.model - Initial value for
|
|
42
|
+
* `Characteristics.hap.Model`.
|
|
43
|
+
* @param {!string} params.firmware - Initial value for
|
|
44
|
+
* `Characteristics.hap.FirmwareRevision`.
|
|
45
|
+
* @param {?string} params.hardware - Initial value for
|
|
46
|
+
* `Characteristics.hap.HardwareRevision`.
|
|
47
|
+
* @param {?string} params.software - Initial value for
|
|
48
|
+
* `Characteristics.hap.SoftwareRevision`.
|
|
49
|
+
*/
|
|
50
|
+
constructor (accessoryDelegate, params = {}) {
|
|
51
|
+
params.name = accessoryDelegate.name
|
|
52
|
+
params.Service = accessoryDelegate.Services.hap.AccessoryInformation
|
|
53
|
+
super(accessoryDelegate, params)
|
|
54
|
+
this.addCharacteristicDelegate({
|
|
55
|
+
key: 'id',
|
|
56
|
+
Characteristic: this.Characteristics.hap.SerialNumber,
|
|
57
|
+
value: params.id
|
|
58
|
+
})
|
|
59
|
+
this.addCharacteristicDelegate({
|
|
60
|
+
key: 'identify',
|
|
61
|
+
Characteristic: this.Characteristics.hap.Identify
|
|
62
|
+
})
|
|
63
|
+
this.addCharacteristicDelegate({
|
|
64
|
+
key: 'manufacturer',
|
|
65
|
+
Characteristic: this.Characteristics.hap.Manufacturer,
|
|
66
|
+
value: params.manufacturer
|
|
67
|
+
})
|
|
68
|
+
this.addCharacteristicDelegate({
|
|
69
|
+
key: 'model',
|
|
70
|
+
Characteristic: this.Characteristics.hap.Model,
|
|
71
|
+
value: params.model
|
|
72
|
+
})
|
|
73
|
+
this.addCharacteristicDelegate({
|
|
74
|
+
key: 'firmware',
|
|
75
|
+
Characteristic: this.Characteristics.hap.FirmwareRevision,
|
|
76
|
+
value: params.firmware
|
|
77
|
+
})
|
|
78
|
+
if (params.hardware != null || this._context.hardware != null) {
|
|
79
|
+
this.addCharacteristicDelegate({
|
|
80
|
+
key: 'hardware',
|
|
81
|
+
Characteristic: this.Characteristics.hap.HardwareRevision,
|
|
82
|
+
value: params.hardware
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
if (params.software != null || this._context.software != null) {
|
|
86
|
+
this.addCharacteristicDelegate({
|
|
87
|
+
key: 'software',
|
|
88
|
+
Characteristic: this.Characteristics.hap.SoftwareRevision,
|
|
89
|
+
value: params.software
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
addCharacteristicDelegate (params = {}) {
|
|
95
|
+
const delegate = super.addCharacteristicDelegate(params)
|
|
96
|
+
Object.defineProperty(this.accessoryDelegate.values, params.key, {
|
|
97
|
+
configurable: true, // make sure we can delete it again
|
|
98
|
+
writeable: true,
|
|
99
|
+
get () { return delegate.value },
|
|
100
|
+
set (value) { delegate.value = value }
|
|
101
|
+
})
|
|
102
|
+
return delegate
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
removeCharacteristicDelegate (key) {
|
|
106
|
+
delete this.accessoryDelegate.values[key]
|
|
107
|
+
super.removeCharacteristicDelegate(key)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = AccessoryInformation
|