homebridge-lib 5.6.2 → 5.6.5
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/SystemInfo.js +104 -5
- package/package.json +2 -2
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/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':
|
|
@@ -367,6 +376,84 @@ class SystemInfo extends events.EventEmitter {
|
|
|
367
376
|
}
|
|
368
377
|
}
|
|
369
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
|
+
|
|
370
457
|
/** Execute a command on the local machine.
|
|
371
458
|
* @param {string} command - The command.
|
|
372
459
|
* @param {...string} ...args - The command parameters.
|
|
@@ -404,6 +491,18 @@ class SystemInfo extends events.EventEmitter {
|
|
|
404
491
|
})
|
|
405
492
|
}
|
|
406
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
|
+
|
|
407
506
|
/** Read a text file.
|
|
408
507
|
* @param {string} fileName - The file name.
|
|
409
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.5",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"homekit",
|
|
9
9
|
"homebridge"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"engines": {
|
|
24
24
|
"homebridge": "^1.5.0",
|
|
25
|
-
"node": "^16.
|
|
25
|
+
"node": "^16.17.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@homebridge/plugin-ui-utils": "~0.0.19",
|