homey-api 3.0.27 → 3.2.0

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.
@@ -1095,6 +1095,25 @@
1095
1095
  }
1096
1096
  }
1097
1097
  },
1098
+ "addTagToMailChimpUser": {
1099
+ "path": "/mail/mailchimp/tag",
1100
+ "method": "post",
1101
+ "private": true,
1102
+ "parameters": {
1103
+ "listId": {
1104
+ "type": "string",
1105
+ "in": "body"
1106
+ },
1107
+ "userId": {
1108
+ "type": "string",
1109
+ "in": "body"
1110
+ },
1111
+ "tag": {
1112
+ "type": "string",
1113
+ "in": "body"
1114
+ }
1115
+ }
1116
+ },
1098
1117
  "getAppInstallsStatistics": {
1099
1118
  "path": "/stats/app-installs",
1100
1119
  "method": "get",
@@ -2659,6 +2659,14 @@ export class AthomCloudAPI {
2659
2659
  userId?: string;
2660
2660
  }): Promise<any>;
2661
2661
 
2662
+ addTagToMailChimpUser(opts: {
2663
+ listId?: string;
2664
+
2665
+ userId?: string;
2666
+
2667
+ tag?: string;
2668
+ }): Promise<any>;
2669
+
2662
2670
  getAppInstallsStatistics(): Promise<any>;
2663
2671
 
2664
2672
  getAppDriversStatistics(): Promise<any>;
@@ -3183,6 +3191,14 @@ export class AthomCloudAPI {
3183
3191
  userId?: string;
3184
3192
  }): Promise<any>;
3185
3193
 
3194
+ addTagToMailChimpUser(opts: {
3195
+ listId?: string;
3196
+
3197
+ userId?: string;
3198
+
3199
+ tag?: string;
3200
+ }): Promise<any>;
3201
+
3186
3202
  getAppInstallsStatistics(): Promise<any>;
3187
3203
 
3188
3204
  getAppDriversStatistics(): Promise<any>;
@@ -5687,6 +5703,14 @@ export class AthomCloudAPI {
5687
5703
  userId?: string;
5688
5704
  }): Promise<any>;
5689
5705
 
5706
+ addTagToMailChimpUser(opts: {
5707
+ listId?: string;
5708
+
5709
+ userId?: string;
5710
+
5711
+ tag?: string;
5712
+ }): Promise<any>;
5713
+
5690
5714
  getAppInstallsStatistics(): Promise<any>;
5691
5715
 
5692
5716
  getAppDriversStatistics(): Promise<any>;
@@ -6211,6 +6235,14 @@ export class AthomCloudAPI {
6211
6235
  userId?: string;
6212
6236
  }): Promise<any>;
6213
6237
 
6238
+ addTagToMailChimpUser(opts: {
6239
+ listId?: string;
6240
+
6241
+ userId?: string;
6242
+
6243
+ tag?: string;
6244
+ }): Promise<any>;
6245
+
6214
6246
  getAppInstallsStatistics(): Promise<any>;
6215
6247
 
6216
6248
  getAppDriversStatistics(): Promise<any>;
@@ -433,7 +433,7 @@ class Manager extends EventEmitter {
433
433
  }
434
434
 
435
435
  __debug(...props) {
436
- this.homey.__debug(`[${this.constructor.name}]`, ...props);
436
+ this.homey.__debug(`[Manager${this.constructor.ID[0].toUpperCase() + this.constructor.ID.slice(1)}]`, ...props);
437
437
  }
438
438
 
439
439
  /**
@@ -625,15 +625,30 @@ class HomeyAPIV3 extends HomeyAPI {
625
625
 
626
626
  return {
627
627
  unsubscribe: () => {
628
- this.__homeySocket.emit('unsubscribe', uri);
629
- this.__homeySocket.removeListener(uri, __onEvent);
630
- this.__socket.removeListener('disconnect', __onDisconnect);
631
- this.__socket.removeListener('reconnect', __onReconnect);
628
+ if (this.__homeySocket) {
629
+ this.__homeySocket.emit('unsubscribe', uri);
630
+ this.__homeySocket.removeListener(uri, __onEvent);
631
+ }
632
+
633
+ if (this.__socket) {
634
+ this.__socket.removeListener('disconnect', __onDisconnect);
635
+ this.__socket.removeListener('reconnect', __onReconnect);
636
+ }
632
637
  },
633
638
  };
634
639
  }
635
640
 
636
- async connect() {
641
+ async connect({
642
+ onDisconnect = () => {},
643
+ onError = () => {},
644
+ onReconnect = () => {},
645
+ onReconnectAttempt = () => {},
646
+ onReconnecting = () => {},
647
+ onReconnectError = () => {},
648
+ onConnect = () => {},
649
+ onConnectError = () => {},
650
+ reconnect = true
651
+ } = {}) {
637
652
  if (!this.__connectPromise) {
638
653
  this.__connectPromise = Promise.resolve().then(async () => {
639
654
  // Ensure Base URL
@@ -652,40 +667,48 @@ class HomeyAPIV3 extends HomeyAPI {
652
667
  pingTimeout: 8000,
653
668
  pingInterval: 5000,
654
669
  },
655
- reconnection: true,
670
+ reconnection: reconnect,
656
671
  });
657
672
 
658
673
  this.__socket.on('disconnect', reason => {
659
674
  this.__debug('SocketIOClient.onDisconnect', reason);
675
+ onDisconnect(reason);
660
676
  });
661
677
 
662
678
  this.__socket.on('error', err => {
663
679
  this.__debug('SocketIOClient.onError', err.message);
680
+ onError(err);
664
681
  });
665
682
 
666
683
  this.__socket.on('reconnect', () => {
667
684
  this.__debug('SocketIOClient.onReconnect');
685
+ onReconnect();
668
686
  });
669
687
 
670
688
  this.__socket.on('reconnect_attempt', () => {
671
689
  this.__debug(`SocketIOClient.onReconnectAttempt`);
690
+ onReconnectAttempt();
672
691
  });
673
692
 
674
693
  this.__socket.on('reconnecting', attempt => {
675
694
  this.__debug(`SocketIOClient.onReconnecting (Attempt #${attempt})`);
695
+ onReconnecting(attempt);
676
696
  });
677
697
 
678
698
  this.__socket.on('reconnect_error', err => {
679
- this.__debug('SocketIOClient.onReconnectError', err.message);
699
+ this.__debug('SocketIOClient.onReconnectError', err.message, err);
700
+ onReconnectError(err);
680
701
  });
681
702
 
682
703
  this.__socket.on('connect_error', err => {
683
704
  this.__debug('SocketIOClient.onConnectError', err.message);
705
+ onConnectError(err);
684
706
  reject(err);
685
707
  });
686
708
 
687
709
  this.__socket.on('connect', () => {
688
710
  this.__debug('SocketIOClient.onConnect');
711
+ onConnect();
689
712
  this.__handshakeClient()
690
713
  .then(() => {
691
714
  this.__debug('SocketIOClient.onConnect.onHandshakeClientSuccess');
@@ -713,10 +736,16 @@ class HomeyAPIV3 extends HomeyAPI {
713
736
  async disconnect() {
714
737
  // Should we wait for connect here?
715
738
 
739
+ // Also disconnect __homeySocket?
740
+
716
741
  if (this.__socket) {
717
742
  await new Promise(resolve => {
718
- this.__socket.once('disconnect', resolve());
719
- this.__socket.disconnect();
743
+ if (this.__socket.connected) {
744
+ this.__socket.once('disconnect', () => resolve());
745
+ this.__socket.disconnect();
746
+ } else {
747
+ resolve();
748
+ }
720
749
  this.__socket.removeAllListeners();
721
750
  this.__socket = null;
722
751
  });
@@ -726,9 +755,16 @@ class HomeyAPIV3 extends HomeyAPI {
726
755
  }
727
756
 
728
757
  destroy() {
758
+ if (this.__homeySocket) {
759
+ this.__homeySocket.removeAllListeners();
760
+ this.__homeySocket.close();
761
+ this.__homeySocket = null;
762
+ }
763
+
729
764
  if (this.__socket) {
730
765
  this.__socket.removeAllListeners();
731
766
  this.__socket.close();
767
+ this.__socket = null;
732
768
  }
733
769
  }
734
770
 
package/lib/Util.js CHANGED
@@ -93,6 +93,7 @@ class Util {
93
93
  * @returns {boolean}
94
94
  */
95
95
  static isHTTPUnsecureSupported() {
96
+ if (this.isReactNative()) return true;
96
97
  if (typeof window === 'undefined') return true;
97
98
  if (typeof window.location === 'undefined') return false;
98
99
  return window.location.protocol === 'http:';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "3.0.27",
3
+ "version": "3.2.0",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "files": [