homey-api 3.4.2 → 3.4.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.
package/lib/AthomCloudAPI.js
CHANGED
|
@@ -381,7 +381,12 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
381
381
|
},
|
|
382
382
|
});
|
|
383
383
|
|
|
384
|
-
|
|
384
|
+
let responseBody;
|
|
385
|
+
try {
|
|
386
|
+
responseBody = await response.json();
|
|
387
|
+
} catch (err) {
|
|
388
|
+
throw new APIError(`Invalid response from server: ${response.text()}`, response.status);
|
|
389
|
+
}
|
|
385
390
|
|
|
386
391
|
if (!response.ok) {
|
|
387
392
|
throw new APIError(responseBody.error_description || responseBody.error, response.status);
|
|
@@ -444,7 +449,12 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
444
449
|
},
|
|
445
450
|
});
|
|
446
451
|
|
|
447
|
-
|
|
452
|
+
let responseBody;
|
|
453
|
+
try {
|
|
454
|
+
responseBody = await response.json();
|
|
455
|
+
} catch (err) {
|
|
456
|
+
throw new APIError(`Invalid response from server: ${response.text()}`, response.status);
|
|
457
|
+
}
|
|
448
458
|
|
|
449
459
|
if (!response.ok) {
|
|
450
460
|
throw new APIError(responseBody.error_description || responseBody.error, response.status);
|
|
@@ -506,7 +516,12 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
506
516
|
},
|
|
507
517
|
});
|
|
508
518
|
|
|
509
|
-
|
|
519
|
+
let responseBody;
|
|
520
|
+
try {
|
|
521
|
+
responseBody = await response.json();
|
|
522
|
+
} catch (err) {
|
|
523
|
+
throw new APIError(`Invalid response from server: ${response.text()}`, response.status);
|
|
524
|
+
}
|
|
510
525
|
|
|
511
526
|
if (!response.ok) {
|
|
512
527
|
throw new APIError(responseBody.error_description || responseBody.error, response.status);
|
|
@@ -552,7 +567,12 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
552
567
|
},
|
|
553
568
|
});
|
|
554
569
|
|
|
555
|
-
|
|
570
|
+
let responseBody;
|
|
571
|
+
try {
|
|
572
|
+
responseBody = await response.json();
|
|
573
|
+
} catch (err) {
|
|
574
|
+
throw new APIError(`Invalid response from server: ${response.text()}`, response.status);
|
|
575
|
+
}
|
|
556
576
|
|
|
557
577
|
if (!response.ok) {
|
|
558
578
|
throw new APIError(responseBody.error_description || responseBody.error, response.status);
|
|
@@ -639,14 +639,6 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
639
639
|
}
|
|
640
640
|
|
|
641
641
|
async connect({
|
|
642
|
-
onDisconnect = () => {},
|
|
643
|
-
onError = () => {},
|
|
644
|
-
onReconnect = () => {},
|
|
645
|
-
onReconnectAttempt = () => {},
|
|
646
|
-
onReconnecting = () => {},
|
|
647
|
-
onReconnectError = () => {},
|
|
648
|
-
onConnect = () => {},
|
|
649
|
-
onConnectError = () => {},
|
|
650
642
|
reconnect = true
|
|
651
643
|
} = {}) {
|
|
652
644
|
if (!this.__connectPromise) {
|
|
@@ -672,43 +664,43 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
672
664
|
|
|
673
665
|
this.__socket.on('disconnect', reason => {
|
|
674
666
|
this.__debug('SocketIOClient.onDisconnect', reason);
|
|
675
|
-
|
|
667
|
+
this.emit('disconnect', reason);
|
|
676
668
|
});
|
|
677
669
|
|
|
678
670
|
this.__socket.on('error', err => {
|
|
679
671
|
this.__debug('SocketIOClient.onError', err.message);
|
|
680
|
-
|
|
672
|
+
this.emit('error', err);
|
|
681
673
|
});
|
|
682
674
|
|
|
683
675
|
this.__socket.on('reconnect', () => {
|
|
684
676
|
this.__debug('SocketIOClient.onReconnect');
|
|
685
|
-
|
|
677
|
+
this.emit('reconnect');
|
|
686
678
|
});
|
|
687
679
|
|
|
688
680
|
this.__socket.on('reconnect_attempt', () => {
|
|
689
681
|
this.__debug(`SocketIOClient.onReconnectAttempt`);
|
|
690
|
-
|
|
682
|
+
this.emit('reconnect_attempt');
|
|
691
683
|
});
|
|
692
684
|
|
|
693
685
|
this.__socket.on('reconnecting', attempt => {
|
|
694
686
|
this.__debug(`SocketIOClient.onReconnecting (Attempt #${attempt})`);
|
|
695
|
-
|
|
687
|
+
this.emit('reconnecting');
|
|
696
688
|
});
|
|
697
689
|
|
|
698
690
|
this.__socket.on('reconnect_error', err => {
|
|
699
691
|
this.__debug('SocketIOClient.onReconnectError', err.message, err);
|
|
700
|
-
|
|
692
|
+
this.emit('reconnect_error');
|
|
701
693
|
});
|
|
702
694
|
|
|
703
695
|
this.__socket.on('connect_error', err => {
|
|
704
696
|
this.__debug('SocketIOClient.onConnectError', err.message);
|
|
705
|
-
|
|
697
|
+
this.emit('connect_error');
|
|
706
698
|
reject(err);
|
|
707
699
|
});
|
|
708
700
|
|
|
709
701
|
this.__socket.on('connect', () => {
|
|
710
702
|
this.__debug('SocketIOClient.onConnect');
|
|
711
|
-
|
|
703
|
+
this.emit('connect');
|
|
712
704
|
this.__handshakeClient()
|
|
713
705
|
.then(() => {
|
|
714
706
|
this.__debug('SocketIOClient.onConnect.onHandshakeClientSuccess');
|
|
@@ -766,6 +758,8 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
766
758
|
this.__socket.close();
|
|
767
759
|
this.__socket = null;
|
|
768
760
|
}
|
|
761
|
+
|
|
762
|
+
this.removeAllListeners();
|
|
769
763
|
}
|
|
770
764
|
|
|
771
765
|
async __handshakeClient() {
|