node-poweredup 8.0.0 → 8.0.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.
@@ -329,7 +329,267 @@
329
329
  <dd class="tag-source">
330
330
  <ul class="dummy">
331
331
  <li>
332
- <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line143">line 143</a>
332
+ <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line157">line 157</a>
333
+ </li>
334
+ </ul>
335
+ </dd>
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+ </dl>
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+
354
+ <h4 class="name" id="connected">
355
+ <span class="type-signature">(readonly) </span>connected<span class="type-signature"></span>
356
+ </h4>
357
+
358
+
359
+
360
+
361
+
362
+
363
+
364
+ <h5 class="subsection-title">Properties:</h5>
365
+
366
+
367
+
368
+ <table class="props">
369
+ <thead>
370
+ <tr>
371
+
372
+ <th>Name</th>
373
+
374
+
375
+ <th>Type</th>
376
+
377
+
378
+
379
+
380
+
381
+ <th class="last">Description</th>
382
+ </tr>
383
+ </thead>
384
+
385
+ <tbody>
386
+
387
+
388
+ <tr>
389
+
390
+ <td class="name"><code>connected</code></td>
391
+
392
+
393
+ <td class="type">
394
+
395
+
396
+ <span class="param-type">
397
+ string
398
+ </span>
399
+
400
+
401
+
402
+
403
+
404
+ </td>
405
+
406
+
407
+
408
+
409
+
410
+ <td class="description last">
411
+ <p>Connected status</p>
412
+ </td>
413
+ </tr>
414
+
415
+
416
+ </tbody>
417
+ </table>
418
+
419
+
420
+
421
+
422
+ <dl class="details">
423
+
424
+
425
+
426
+
427
+
428
+
429
+ <dt class="inherited-from">Inherited From:</dt>
430
+ <dd class="inherited-from">
431
+ <ul class="dummy">
432
+ <li>
433
+ <a href="BaseHub.html#connected">BaseHub#connected</a>
434
+ </li>
435
+ </ul>
436
+ </dd>
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+
454
+
455
+
456
+
457
+
458
+ <dt class="tag-source">Source:</dt>
459
+ <dd class="tag-source">
460
+ <ul class="dummy">
461
+ <li>
462
+ <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line101">line 101</a>
463
+ </li>
464
+ </ul>
465
+ </dd>
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+ </dl>
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+ <h4 class="name" id="connecting">
485
+ <span class="type-signature">(readonly) </span>connecting<span class="type-signature"></span>
486
+ </h4>
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+ <h5 class="subsection-title">Properties:</h5>
495
+
496
+
497
+
498
+ <table class="props">
499
+ <thead>
500
+ <tr>
501
+
502
+ <th>Name</th>
503
+
504
+
505
+ <th>Type</th>
506
+
507
+
508
+
509
+
510
+
511
+ <th class="last">Description</th>
512
+ </tr>
513
+ </thead>
514
+
515
+ <tbody>
516
+
517
+
518
+ <tr>
519
+
520
+ <td class="name"><code>connecting</code></td>
521
+
522
+
523
+ <td class="type">
524
+
525
+
526
+ <span class="param-type">
527
+ string
528
+ </span>
529
+
530
+
531
+
532
+
533
+
534
+ </td>
535
+
536
+
537
+
538
+
539
+
540
+ <td class="description last">
541
+ <p>Connecting status</p>
542
+ </td>
543
+ </tr>
544
+
545
+
546
+ </tbody>
547
+ </table>
548
+
549
+
550
+
551
+
552
+ <dl class="details">
553
+
554
+
555
+
556
+
557
+
558
+
559
+ <dt class="inherited-from">Inherited From:</dt>
560
+ <dd class="inherited-from">
561
+ <ul class="dummy">
562
+ <li>
563
+ <a href="BaseHub.html#connecting">BaseHub#connecting</a>
564
+ </li>
565
+ </ul>
566
+ </dd>
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
579
+
580
+
581
+
582
+
583
+
584
+
585
+
586
+
587
+
588
+ <dt class="tag-source">Source:</dt>
589
+ <dd class="tag-source">
590
+ <ul class="dummy">
591
+ <li>
592
+ <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line108">line 108</a>
333
593
  </li>
334
594
  </ul>
335
595
  </dd>
@@ -459,7 +719,7 @@
459
719
  <dd class="tag-source">
460
720
  <ul class="dummy">
461
721
  <li>
462
- <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line115">line 115</a>
722
+ <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line129">line 129</a>
463
723
  </li>
464
724
  </ul>
465
725
  </dd>
@@ -589,7 +849,7 @@
589
849
  <dd class="tag-source">
590
850
  <ul class="dummy">
591
851
  <li>
592
- <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line122">line 122</a>
852
+ <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line136">line 136</a>
593
853
  </li>
594
854
  </ul>
595
855
  </dd>
@@ -849,7 +1109,7 @@
849
1109
  <dd class="tag-source">
850
1110
  <ul class="dummy">
851
1111
  <li>
852
- <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line108">line 108</a>
1112
+ <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line122">line 122</a>
853
1113
  </li>
854
1114
  </ul>
855
1115
  </dd>
@@ -979,7 +1239,7 @@
979
1239
  <dd class="tag-source">
980
1240
  <ul class="dummy">
981
1241
  <li>
982
- <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line129">line 129</a>
1242
+ <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line143">line 143</a>
983
1243
  </li>
984
1244
  </ul>
985
1245
  </dd>
@@ -1109,7 +1369,7 @@
1109
1369
  <dd class="tag-source">
1110
1370
  <ul class="dummy">
1111
1371
  <li>
1112
- <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line150">line 150</a>
1372
+ <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line164">line 164</a>
1113
1373
  </li>
1114
1374
  </ul>
1115
1375
  </dd>
@@ -1239,7 +1499,7 @@
1239
1499
  <dd class="tag-source">
1240
1500
  <ul class="dummy">
1241
1501
  <li>
1242
- <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line101">line 101</a>
1502
+ <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line115">line 115</a>
1243
1503
  </li>
1244
1504
  </ul>
1245
1505
  </dd>
@@ -1369,7 +1629,7 @@
1369
1629
  <dd class="tag-source">
1370
1630
  <ul class="dummy">
1371
1631
  <li>
1372
- <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line136">line 136</a>
1632
+ <a href="hubs_basehub.js.html">hubs/basehub.js</a>, <a href="hubs_basehub.js.html#line150">line 150</a>
1373
1633
  </li>
1374
1634
  </ul>
1375
1635
  </dd>
@@ -186,6 +186,20 @@ class BaseHub extends events_1.EventEmitter {
186
186
  get name() {
187
187
  return this._bleDevice.name;
188
188
  }
189
+ /**
190
+ * @readonly
191
+ * @property {string} connected Connected status
192
+ */
193
+ get connected() {
194
+ return this._bleDevice.connected;
195
+ }
196
+ /**
197
+ * @readonly
198
+ * @property {string} connecting Connecting status
199
+ */
200
+ get connecting() {
201
+ return this._bleDevice.connecting;
202
+ }
189
203
  /**
190
204
  * @readonly
191
205
  * @property {string} type Hub type
@@ -128,11 +128,12 @@ const noble = require("@abandonware/noble");
128
128
  const technicsmallhub_1 = require("./hubs/technicsmallhub");
129
129
  let ready = false;
130
130
  let wantScan = false;
131
- let discoveryEventAttached = false;
132
131
  const startScanning = () => {
133
132
  noble.startScanning([
134
133
  Consts.BLEService.LPF2_HUB,
135
- Consts.BLEService.WEDO2_SMART_HUB
134
+ Consts.BLEService.LPF2_HUB.replace(/-/g, ""),
135
+ Consts.BLEService.WEDO2_SMART_HUB,
136
+ Consts.BLEService.WEDO2_SMART_HUB.replace(/-/g, "")
136
137
  ]);
137
138
  };
138
139
  noble.on("stateChange", (state) => {
@@ -168,10 +169,9 @@ class PoweredUP extends events_1.EventEmitter {
168
169
  */
169
170
  async scan() {
170
171
  wantScan = true;
171
- if (!discoveryEventAttached) {
172
- noble.on("discover", this._discoveryEventHandler);
173
- discoveryEventAttached = true;
174
- }
172
+ // @ts-ignore
173
+ noble.removeAllListeners();
174
+ noble.on("discover", this._discoveryEventHandler);
175
175
  if (ready) {
176
176
  debug("Scanning started");
177
177
  startScanning();
@@ -184,10 +184,9 @@ class PoweredUP extends events_1.EventEmitter {
184
184
  */
185
185
  stop() {
186
186
  wantScan = false;
187
- if (discoveryEventAttached) {
188
- noble.removeListener("discover", this._discoveryEventHandler);
189
- discoveryEventAttached = false;
190
- }
187
+ // @ts-ignore
188
+ noble.removeAllListeners();
189
+ noble.removeListener("discover", this._discoveryEventHandler);
191
190
  noble.stopScanning();
192
191
  }
193
192
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-poweredup",
3
- "version": "8.0.0",
3
+ "version": "8.0.4",
4
4
  "description": "A Javascript module to interface with LEGO Powered Up components.",
5
5
  "homepage": "https://github.com/nathankellenicki/node-poweredup/",
6
6
  "main": "dist/node/index-node.js",
@@ -92,6 +92,24 @@ export class BaseHub extends EventEmitter {
92
92
  }
93
93
 
94
94
 
95
+ /**
96
+ * @readonly
97
+ * @property {string} connected Connected status
98
+ */
99
+ public get connected () {
100
+ return this._bleDevice.connected;
101
+ }
102
+
103
+
104
+ /**
105
+ * @readonly
106
+ * @property {string} connecting Connecting status
107
+ */
108
+ public get connecting () {
109
+ return this._bleDevice.connecting;
110
+ }
111
+
112
+
95
113
  /**
96
114
  * @readonly
97
115
  * @property {string} type Hub type
@@ -79,6 +79,8 @@ export class NobleDevice extends EventEmitter implements IBLEAbstraction {
79
79
  public disconnect () {
80
80
  return new Promise<void>((resolve) => {
81
81
  this._noblePeripheral.disconnect();
82
+ this._connecting = false;
83
+ this._connected = false;
82
84
  return resolve();
83
85
  });
84
86
  }
@@ -22,12 +22,13 @@ import { TechnicSmallHub } from "./hubs/technicsmallhub";
22
22
 
23
23
  let ready = false;
24
24
  let wantScan = false;
25
- let discoveryEventAttached = false;
26
25
 
27
26
  const startScanning = () => {
28
27
  noble.startScanning([
29
28
  Consts.BLEService.LPF2_HUB,
30
- Consts.BLEService.WEDO2_SMART_HUB
29
+ Consts.BLEService.LPF2_HUB.replace(/-/g, ""),
30
+ Consts.BLEService.WEDO2_SMART_HUB,
31
+ Consts.BLEService.WEDO2_SMART_HUB.replace(/-/g, "")
31
32
  ]);
32
33
  };
33
34
 
@@ -70,11 +71,9 @@ export class PoweredUP extends EventEmitter {
70
71
  */
71
72
  public async scan () {
72
73
  wantScan = true;
73
-
74
- if (!discoveryEventAttached) {
75
- noble.on("discover", this._discoveryEventHandler);
76
- discoveryEventAttached = true;
77
- }
74
+ // @ts-ignore
75
+ noble.removeAllListeners();
76
+ noble.on("discover", this._discoveryEventHandler);
78
77
 
79
78
  if (ready) {
80
79
  debug("Scanning started");
@@ -91,12 +90,9 @@ export class PoweredUP extends EventEmitter {
91
90
  */
92
91
  public stop () {
93
92
  wantScan = false;
94
-
95
- if (discoveryEventAttached) {
96
- noble.removeListener("discover", this._discoveryEventHandler);
97
- discoveryEventAttached = false;
98
- }
99
-
93
+ // @ts-ignore
94
+ noble.removeAllListeners();
95
+ noble.removeListener("discover", this._discoveryEventHandler);
100
96
  noble.stopScanning();
101
97
  }
102
98
 
@@ -68,6 +68,7 @@ export class WebBLEDevice extends EventEmitter implements IBLEAbstraction {
68
68
  public disconnect () {
69
69
  return new Promise<void>((resolve) => {
70
70
  this._webBLEServer.device.gatt.disconnect();
71
+ this._connected = false;
71
72
  return resolve();
72
73
  });
73
74
  }