hb-nb-tools 2.0.6 → 2.0.8
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/NbTool.js +43 -44
- package/package.json +2 -2
package/lib/NbTool.js
CHANGED
|
@@ -18,7 +18,7 @@ const { UsageError } = CommandLineParser
|
|
|
18
18
|
const usage = {
|
|
19
19
|
nb: `${b('nb')} [${b('-hVD')}] [${b('-H')} ${u('hostname')}[${b(':')}${u('port')}]] [${b('-T')} ${u('token')}] [${b('-E')} [${b('none')}|${b('hasedToken')}|${b('encryptedToken')}]] [${b('-t')} ${u('timeout')}] ${u('command')} [${u('argument')} ...]`,
|
|
20
20
|
|
|
21
|
-
discover: `${b('discover')} [${b('-h')}]
|
|
21
|
+
discover: `${b('discover')} [${b('-h')}]`,
|
|
22
22
|
|
|
23
23
|
auth: `${b('auth')} [${b('-h')}]`,
|
|
24
24
|
info: `${b('info')} [${b('-h')}]`,
|
|
@@ -316,6 +316,7 @@ class NbTool extends CommandLineTool {
|
|
|
316
316
|
const clargs = {
|
|
317
317
|
options: {
|
|
318
318
|
host: process.env.NB_HOST,
|
|
319
|
+
timeout: 5,
|
|
319
320
|
token: process.env.NB_TOKEN
|
|
320
321
|
}
|
|
321
322
|
}
|
|
@@ -365,7 +366,41 @@ class NbTool extends CommandLineTool {
|
|
|
365
366
|
this.usage = usage.nb
|
|
366
367
|
const clargs = this.parseArguments()
|
|
367
368
|
this.jsonFormatter = new JsonFormatter({ sortKeys: true })
|
|
368
|
-
if (clargs.command
|
|
369
|
+
if (clargs.command === 'discover') {
|
|
370
|
+
this.nbDiscovery = new NbDiscovery({
|
|
371
|
+
timeout: clargs.options.timeout
|
|
372
|
+
})
|
|
373
|
+
this.nbDiscovery
|
|
374
|
+
.on('error', (error) => {
|
|
375
|
+
this.log(
|
|
376
|
+
'%s: request %d: %s %s', error.request.name, error.request.id,
|
|
377
|
+
error.request.method, error.request.resource
|
|
378
|
+
)
|
|
379
|
+
this.warn(
|
|
380
|
+
'%s: request %d: error: %s', error.request.name, error.request.id, error
|
|
381
|
+
)
|
|
382
|
+
})
|
|
383
|
+
.on('request', (request) => {
|
|
384
|
+
this.debug(
|
|
385
|
+
'%s: request %d: %s %s', request.name, request.id,
|
|
386
|
+
request.method, request.resource
|
|
387
|
+
)
|
|
388
|
+
this.vdebug(
|
|
389
|
+
'%s: request %d: %s %s', request.name, request.id,
|
|
390
|
+
request.method, request.url
|
|
391
|
+
)
|
|
392
|
+
})
|
|
393
|
+
.on('response', (response) => {
|
|
394
|
+
this.vdebug(
|
|
395
|
+
'%s: request %d: response: %j', response.request.name, response.request.id,
|
|
396
|
+
response.body
|
|
397
|
+
)
|
|
398
|
+
this.debug(
|
|
399
|
+
'%s: request %d: %d %s', response.request.name, response.request.id,
|
|
400
|
+
response.statusCode, response.statusMessage
|
|
401
|
+
)
|
|
402
|
+
})
|
|
403
|
+
} else {
|
|
369
404
|
if (clargs.options.host == null) {
|
|
370
405
|
await this.fatal(`Missing host. Set ${b('NB_HOST')} or specify ${b('-H')}.`)
|
|
371
406
|
}
|
|
@@ -425,44 +460,8 @@ class NbTool extends CommandLineTool {
|
|
|
425
460
|
}
|
|
426
461
|
|
|
427
462
|
async discover (...args) {
|
|
428
|
-
|
|
429
|
-
this.
|
|
430
|
-
.option('t', 'timeout', (value, key) => {
|
|
431
|
-
options.timeout = OptionParser.toInt('timeout', value, 1, 60, true)
|
|
432
|
-
})
|
|
433
|
-
.parse(...args)
|
|
434
|
-
const nbDiscovery = new NbDiscovery(options)
|
|
435
|
-
nbDiscovery
|
|
436
|
-
.on('error', (error) => {
|
|
437
|
-
this.log(
|
|
438
|
-
'%s: request %d: %s %s', error.request.name, error.request.id,
|
|
439
|
-
error.request.method, error.request.resource
|
|
440
|
-
)
|
|
441
|
-
this.warn(
|
|
442
|
-
'%s: request %d: error: %s', error.request.name, error.request.id, error
|
|
443
|
-
)
|
|
444
|
-
})
|
|
445
|
-
.on('request', (request) => {
|
|
446
|
-
this.debug(
|
|
447
|
-
'%s: request %d: %s %s', request.name, request.id,
|
|
448
|
-
request.method, request.resource
|
|
449
|
-
)
|
|
450
|
-
this.vdebug(
|
|
451
|
-
'%s: request %d: %s %s', request.name, request.id,
|
|
452
|
-
request.method, request.url
|
|
453
|
-
)
|
|
454
|
-
})
|
|
455
|
-
.on('response', (response) => {
|
|
456
|
-
this.vdebug(
|
|
457
|
-
'%s: request %d: response: %j', response.request.name, response.request.id,
|
|
458
|
-
response.body
|
|
459
|
-
)
|
|
460
|
-
this.debug(
|
|
461
|
-
'%s: request %d: %d %s', response.request.name, response.request.id,
|
|
462
|
-
response.statusCode, response.statusMessage
|
|
463
|
-
)
|
|
464
|
-
})
|
|
465
|
-
const bridges = await nbDiscovery.discover()
|
|
463
|
+
this.parser.parse(...args)
|
|
464
|
+
const bridges = await this.nbDiscovery.discover()
|
|
466
465
|
this.print(this.jsonFormatter.stringify(bridges))
|
|
467
466
|
}
|
|
468
467
|
|
|
@@ -517,7 +516,7 @@ class NbTool extends CommandLineTool {
|
|
|
517
516
|
nukiId = OptionParser.toInt('nukiId', value, 0, Infinity, true)
|
|
518
517
|
})
|
|
519
518
|
.parameter('deviceType', (value) => {
|
|
520
|
-
deviceType = OptionParser.toInt('deviceType', value, 0,
|
|
519
|
+
deviceType = OptionParser.toInt('deviceType', value, 0, 4, true)
|
|
521
520
|
})
|
|
522
521
|
.parse(...args)
|
|
523
522
|
const response = await this.client.lockState(nukiId, deviceType)
|
|
@@ -532,7 +531,7 @@ class NbTool extends CommandLineTool {
|
|
|
532
531
|
nukiId = OptionParser.toInt('nukiId', value, 0, Infinity, true)
|
|
533
532
|
})
|
|
534
533
|
.parameter('deviceType', (value) => {
|
|
535
|
-
deviceType = OptionParser.toInt('deviceType', value, 0,
|
|
534
|
+
deviceType = OptionParser.toInt('deviceType', value, 0, 4, true)
|
|
536
535
|
})
|
|
537
536
|
.parse(...args)
|
|
538
537
|
const response = await this.client.lock(nukiId, deviceType)
|
|
@@ -547,7 +546,7 @@ class NbTool extends CommandLineTool {
|
|
|
547
546
|
nukiId = OptionParser.toInt('nukiId', value, 0, Infinity, true)
|
|
548
547
|
})
|
|
549
548
|
.parameter('deviceType', (value) => {
|
|
550
|
-
deviceType = OptionParser.toInt('deviceType', value, 0,
|
|
549
|
+
deviceType = OptionParser.toInt('deviceType', value, 0, 4, true)
|
|
551
550
|
})
|
|
552
551
|
.parse(...args)
|
|
553
552
|
const response = await this.client.unlock(nukiId, deviceType)
|
|
@@ -563,7 +562,7 @@ class NbTool extends CommandLineTool {
|
|
|
563
562
|
nukiId = OptionParser.toInt('nukiId', value, 0, Infinity, true)
|
|
564
563
|
})
|
|
565
564
|
.parameter('deviceType', (value) => {
|
|
566
|
-
deviceType = OptionParser.toInt('deviceType', value, 0,
|
|
565
|
+
deviceType = OptionParser.toInt('deviceType', value, 0, 4, true)
|
|
567
566
|
})
|
|
568
567
|
.parameter('action', (value) => {
|
|
569
568
|
action = OptionParser.toInt('action', value, 1, 5, true)
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"ebaauw"
|
|
7
7
|
],
|
|
8
8
|
"license": "Apache-2.0",
|
|
9
|
-
"version": "2.0.
|
|
9
|
+
"version": "2.0.8",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
"./*": "./lib/*.js"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"node": "^22||^20||^18"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"hb-lib-tools": "~2.
|
|
27
|
+
"hb-lib-tools": "~2.1.2",
|
|
28
28
|
"tweetnacl": "~1.0.3"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|