homebridge-lib 5.6.1 → 5.6.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/OptionParser.js +1 -1
- package/lib/Platform.js +1 -4
- package/lib/SystemInfo.js +109 -8
- package/package.json +3 -3
package/lib/OptionParser.js
CHANGED
|
@@ -56,7 +56,7 @@ class OptionParser extends events.EventEmitter {
|
|
|
56
56
|
static get patterns () {
|
|
57
57
|
return Object.freeze({
|
|
58
58
|
_host: /^(?:\[(.+)\]|([^:]+))(?::([0-9]{1,5}))?$/,
|
|
59
|
-
hostname: /^[a-zA-
|
|
59
|
+
hostname: /^[a-zA-Z0-9](:?[a-zA-Z0-9-]*[a-zA-Z0-9])*(:?\.[a-zA-Z0-9](:?[a-zA-Z0-9-]*[a-zA-Z0-9])*)*$/,
|
|
60
60
|
int: /^\s*([+-]?)([0-9]+(?:\.0*)?)\s*$/,
|
|
61
61
|
intBin: /^\s*([+-]?)(?:0[bB])([01]+)\s*$/,
|
|
62
62
|
intOct: /^\s*([+-]?)(?:0[oO])([0-8]+)\s*$/,
|
package/lib/Platform.js
CHANGED
|
@@ -101,10 +101,7 @@ class Platform extends homebridgeLib.Delegate {
|
|
|
101
101
|
my: Object.freeze(my.Characteristics)
|
|
102
102
|
})
|
|
103
103
|
}
|
|
104
|
-
context[Platform.name] = {
|
|
105
|
-
packageJson: packageJson,
|
|
106
|
-
platformName: platformName
|
|
107
|
-
}
|
|
104
|
+
context[Platform.name] = { packageJson, platformName }
|
|
108
105
|
homebridge.registerPlatform(
|
|
109
106
|
packageJson.name, platformName, Platform, true
|
|
110
107
|
)
|
package/lib/SystemInfo.js
CHANGED
|
@@ -173,13 +173,22 @@ class SystemInfo extends events.EventEmitter {
|
|
|
173
173
|
async init () {
|
|
174
174
|
switch (process.platform) {
|
|
175
175
|
case 'linux':
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
176
|
+
if (await this.existsFile('/etc/synoinfo.conf')) {
|
|
177
|
+
try {
|
|
178
|
+
this.osInfo = await this.getDsmInfo()
|
|
179
|
+
} catch (error) { this.emit('error', error) }
|
|
180
180
|
try {
|
|
181
|
-
this.hwInfo = await this.
|
|
181
|
+
this.hwInfo = await this.getSynoInfo()
|
|
182
182
|
} catch (error) { this.emit('error', error) }
|
|
183
|
+
} else {
|
|
184
|
+
try {
|
|
185
|
+
this.osInfo = await this.getPiOsInfo()
|
|
186
|
+
} catch (error) { this.emit('error', error) }
|
|
187
|
+
if (['arm', 'arm64'].includes(process.arch)) {
|
|
188
|
+
try {
|
|
189
|
+
this.hwInfo = await this.getRpiInfo()
|
|
190
|
+
} catch (error) { this.emit('error', error) }
|
|
191
|
+
}
|
|
183
192
|
}
|
|
184
193
|
break
|
|
185
194
|
case 'darwin':
|
|
@@ -293,10 +302,12 @@ class SystemInfo extends events.EventEmitter {
|
|
|
293
302
|
'plutil', '-p',
|
|
294
303
|
process.env.HOME + '/Library/Preferences/com.apple.SystemProfiler.plist'
|
|
295
304
|
)
|
|
296
|
-
const regexp = RegExp(
|
|
305
|
+
const regexp = RegExp(
|
|
306
|
+
'"(' + id.slice(-4) + '|' + id.slice(-3) + ').*" => "(.*)"'
|
|
307
|
+
)
|
|
297
308
|
const a = regexp.exec(text)
|
|
298
|
-
if (a
|
|
299
|
-
prettyName = a[
|
|
309
|
+
if (a != null) {
|
|
310
|
+
prettyName = a[2]
|
|
300
311
|
}
|
|
301
312
|
} else { // Apple silicon
|
|
302
313
|
text = await this.execShell('ioreg -l | grep product-description')
|
|
@@ -365,6 +376,84 @@ class SystemInfo extends events.EventEmitter {
|
|
|
365
376
|
}
|
|
366
377
|
}
|
|
367
378
|
|
|
379
|
+
/** Extract Synology info from `/etc/synoinfo.conf`
|
|
380
|
+
* @return {object} - The extracted info.
|
|
381
|
+
*/
|
|
382
|
+
async getSynoInfo () {
|
|
383
|
+
let device = ''
|
|
384
|
+
let id
|
|
385
|
+
let model = ''
|
|
386
|
+
const text = await this.readTextFile('/etc/synoinfo.conf')
|
|
387
|
+
const lines = text.replace(/"/g, '').split('\n')
|
|
388
|
+
for (const line of lines) {
|
|
389
|
+
const fields = line.split('=')
|
|
390
|
+
if (fields.length === 2) {
|
|
391
|
+
switch (fields[0].trim()) {
|
|
392
|
+
case 'pushservice_dsserial':
|
|
393
|
+
id = fields[1] // e.g 1970PDN255608
|
|
394
|
+
break
|
|
395
|
+
case 'upnpdevicetype':
|
|
396
|
+
device = fields[1] // e.g. DiskStation
|
|
397
|
+
break
|
|
398
|
+
case 'upnpmodelname':
|
|
399
|
+
model = fields[1] // e.g. DS918+
|
|
400
|
+
break
|
|
401
|
+
default:
|
|
402
|
+
break
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
id,
|
|
408
|
+
manufacturer: 'Synology',
|
|
409
|
+
model: [device, model].join(' '),
|
|
410
|
+
prettyName: ['Synologgy', device, model].join(' ')
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** Extract DSM info from `/etc/VERSION`.
|
|
415
|
+
* @return {object} - The extracted info.
|
|
416
|
+
*/
|
|
417
|
+
async getDsmInfo () {
|
|
418
|
+
let build, prettyName, update, version
|
|
419
|
+
const text = await this.readTextFile('/etc/VERSION')
|
|
420
|
+
const lines = text.replace(/"/g, '').split('\n')
|
|
421
|
+
for (const line of lines) {
|
|
422
|
+
const fields = line.split('=')
|
|
423
|
+
if (fields.length === 2) {
|
|
424
|
+
switch (fields[0].trim()) {
|
|
425
|
+
case 'buildnumber':
|
|
426
|
+
build = fields[1] // e.g. 42661
|
|
427
|
+
break
|
|
428
|
+
case 'productversion':
|
|
429
|
+
version = fields[1] // e.g. 7.1
|
|
430
|
+
break
|
|
431
|
+
case 'smallfixnumber':
|
|
432
|
+
update = fields[1] // e.g. 3
|
|
433
|
+
break
|
|
434
|
+
default:
|
|
435
|
+
break
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
prettyName = 'DSM'
|
|
440
|
+
if (version != null) {
|
|
441
|
+
prettyName += ' ' + version
|
|
442
|
+
if (build != null) {
|
|
443
|
+
prettyName += '-' + build
|
|
444
|
+
}
|
|
445
|
+
if (update != null) {
|
|
446
|
+
prettyName += ' Update ' + update
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return {
|
|
450
|
+
build,
|
|
451
|
+
prettyName,
|
|
452
|
+
update,
|
|
453
|
+
version
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
368
457
|
/** Execute a command on the local machine.
|
|
369
458
|
* @param {string} command - The command.
|
|
370
459
|
* @param {...string} ...args - The command parameters.
|
|
@@ -402,6 +491,18 @@ class SystemInfo extends events.EventEmitter {
|
|
|
402
491
|
})
|
|
403
492
|
}
|
|
404
493
|
|
|
494
|
+
/** Check if file exists.
|
|
495
|
+
* @param {string} fileName - The file name.
|
|
496
|
+
* @return {bool} - True iff file exists,
|
|
497
|
+
*/
|
|
498
|
+
async existsFile (fileName) {
|
|
499
|
+
try {
|
|
500
|
+
await fs.access(fileName)
|
|
501
|
+
return true
|
|
502
|
+
} catch (error) {}
|
|
503
|
+
return false
|
|
504
|
+
}
|
|
505
|
+
|
|
405
506
|
/** Read a text file.
|
|
406
507
|
* @param {string} fileName - The file name.
|
|
407
508
|
* @return {string} - The contents of the file.
|
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.
|
|
6
|
+
"version": "5.6.4",
|
|
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.
|
|
25
|
-
"node": "^16.
|
|
24
|
+
"homebridge": "^1.5.0",
|
|
25
|
+
"node": "^16.16.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@homebridge/plugin-ui-utils": "~0.0.19",
|