homey-api 3.0.23 → 3.0.24

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.
@@ -480,11 +480,17 @@ class Manager extends EventEmitter {
480
480
  this.__debug(`onDisconnect Reason:${reason}`);
481
481
  this.__connected = false;
482
482
 
483
+ // Disable for now. We should probably only set the cache to invalid.
484
+
483
485
  // Clear CRUD Item cache
484
- for (const itemId of Object.keys(this.__cache)) {
485
- this.__cache[itemId] = {};
486
- this.__cacheAllComplete[itemId] = false;
487
- }
486
+ // for (const itemId of Object.keys(this.__cache)) {
487
+ // this.__cache[itemId] = {};
488
+ // this.__cacheAllComplete[itemId] = false;
489
+ // }
490
+ },
491
+ onReconnect: () => {
492
+ this.__debug(`onReconnect`);
493
+ this.__connected = true;
488
494
  },
489
495
  onEvent: (event, data) => {
490
496
  this.__debug('onEvent', event);
@@ -566,7 +566,7 @@ class HomeyAPIV3 extends HomeyAPI {
566
566
  this.__debug('subscribe', uri);
567
567
 
568
568
  await this.connect();
569
- await new Promise((resolve, reject) => {
569
+ await Util.timeout(new Promise((resolve, reject) => {
570
570
  this.__homeySocket.once('disconnect', (reason) => {
571
571
  reject(new Error(reason));
572
572
  });
@@ -580,7 +580,7 @@ class HomeyAPIV3 extends HomeyAPI {
580
580
  this.__debug('subscribed', uri);
581
581
  return resolve();
582
582
  });
583
- });
583
+ }), 5000, `Failed to subscribe to ${uri} (Timeout after 5000ms).`);
584
584
 
585
585
  // On Connect
586
586
  const __onEvent = (event, data) => {
@@ -600,16 +600,21 @@ class HomeyAPIV3 extends HomeyAPI {
600
600
  const __onReconnect = () => {
601
601
  Promise.resolve().then(async () => {
602
602
  await this.connect();
603
- await new Promise((resolve, reject) => {
603
+ await Util.timeout(new Promise((resolve, reject) => {
604
+ this.__homeySocket.once('disconnect', (reason) => {
605
+ reject(new Error(reason));
606
+ });
607
+ this.__debug('subscribing', uri);
604
608
  this.__homeySocket.emit('subscribe', uri, err => {
605
609
  if (err) {
606
610
  this.__debug('Failed to subscribe', uri, err);
607
611
  return reject(err)
608
612
  }
609
-
613
+
614
+ this.__debug('subscribed', uri);
610
615
  return resolve();
611
616
  });
612
- });
617
+ }), 5000, `Failed to subscribe to ${uri} (Timeout after 5000ms).`);
613
618
 
614
619
  this.__homeySocket.on(uri, __onEvent);
615
620
 
@@ -652,23 +657,6 @@ class HomeyAPIV3 extends HomeyAPI {
652
657
 
653
658
  this.__socket.on('disconnect', reason => {
654
659
  this.__debug('SocketIOClient.onDisconnect', reason);
655
- // this.emit('state', {
656
- // socketConnected: this.__socket.connected,
657
- // homeySocketConnected: this.__homeySocket && this.__homeySocket.connected
658
- // });
659
-
660
- if (this.__homeySocket) {
661
- this.__homeySocket.disconnect();
662
- this.__homeySocket.destroy();
663
- this.__homeySocket.removeAllListeners();
664
- }
665
-
666
- if (reason === 'io server disconnect') {
667
- // The disconnect was initiated by the server.
668
- // this.__socket.open();
669
- }
670
-
671
- reject(new Error('Disconnected'));
672
660
  });
673
661
 
674
662
  this.__socket.on('error', err => {
@@ -677,15 +665,6 @@ class HomeyAPIV3 extends HomeyAPI {
677
665
 
678
666
  this.__socket.on('reconnect', () => {
679
667
  this.__debug('SocketIOClient.onReconnect');
680
- this.__handshakeClient()
681
- .then(() => {
682
- this.__debug('SocketIOClient.onReconnect.onHandshakeClientSuccess');
683
- resolve();
684
- })
685
- .catch(err => {
686
- this.__debug('SocketIOClient.onReconnect.onHandshakeClientError', err.message);
687
- reject(err);
688
- });
689
668
  });
690
669
 
691
670
  this.__socket.on('reconnect_attempt', () => {
@@ -706,7 +685,6 @@ class HomeyAPIV3 extends HomeyAPI {
706
685
  });
707
686
 
708
687
  this.__socket.on('connect', () => {
709
- // this.emit('state', { connected: this.__homeySocket?.connected });
710
688
  this.__debug('SocketIOClient.onConnect');
711
689
  this.__handshakeClient()
712
690
  .then(() => {
@@ -725,6 +703,7 @@ class HomeyAPIV3 extends HomeyAPI {
725
703
 
726
704
  this.__connectPromise.catch(err => {
727
705
  this.__debug('SocketIOClient Error', err.message);
706
+ delete this.__connectPromise;
728
707
  });
729
708
  }
730
709
 
@@ -732,6 +711,8 @@ class HomeyAPIV3 extends HomeyAPI {
732
711
  }
733
712
 
734
713
  async disconnect() {
714
+ // Should we wait for connect here?
715
+
735
716
  if (this.__socket) {
736
717
  await new Promise(resolve => {
737
718
  this.__socket.once('disconnect', resolve());
@@ -740,6 +721,7 @@ class HomeyAPIV3 extends HomeyAPI {
740
721
  this.__socket = null;
741
722
  });
742
723
  }
724
+
743
725
  // TODO todo what?
744
726
  }
745
727
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "3.0.23",
3
+ "version": "3.0.24",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "files": [