homey-api 3.0.24 → 3.0.26
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
|
@@ -489,8 +489,8 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
489
489
|
|
|
490
490
|
const body = new URLSearchParams();
|
|
491
491
|
body.append('grant_type', 'password');
|
|
492
|
-
body.append('username', username);
|
|
493
|
-
body.append('password', password);
|
|
492
|
+
body.append('username', encodeURIComponent(username));
|
|
493
|
+
body.append('password', encodeURIComponent(password));
|
|
494
494
|
|
|
495
495
|
const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
|
|
496
496
|
body: body.toString(),
|
|
@@ -735,70 +735,71 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
735
735
|
async __handshakeClient() {
|
|
736
736
|
this.__debug('__handshakeClient');
|
|
737
737
|
|
|
738
|
-
|
|
739
|
-
this.
|
|
740
|
-
token: this.__token,
|
|
741
|
-
homeyId: this.id,
|
|
742
|
-
}, (err, result) => {
|
|
743
|
-
if (err) return reject(err);
|
|
744
|
-
return resolve(result);
|
|
745
|
-
});
|
|
746
|
-
})
|
|
747
|
-
.catch(async err => {
|
|
748
|
-
// If token is expired, try to refresh, statusCode is for apiVersion 3 and code for apiVersion 2.
|
|
749
|
-
if (err.statusCode === 401 || err.code === 401) {
|
|
750
|
-
this.__debug('Token expired, refreshing...');
|
|
751
|
-
await this.logout();
|
|
752
|
-
await this.login();
|
|
753
|
-
|
|
754
|
-
return new Promise((resolve, reject) => {
|
|
755
|
-
this.__socket.emit('handshakeClient', {
|
|
756
|
-
token: this.__token,
|
|
757
|
-
homeyId: this.id,
|
|
758
|
-
}, (err, result) => {
|
|
759
|
-
if (err) return reject(err);
|
|
760
|
-
return resolve(result);
|
|
761
|
-
});
|
|
762
|
-
});
|
|
763
|
-
}
|
|
738
|
+
const onResult = ({ namespace }) => {
|
|
739
|
+
this.__debug('SocketIOClient.onHandshakeClientSuccess', `Namespace: ${namespace}`);
|
|
764
740
|
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
.then(({ namespace }) => {
|
|
768
|
-
this.__debug('SocketIOClient.onHandshakeClientSuccess', `Namespace: ${namespace}`);
|
|
741
|
+
return new Promise((resolve, reject) => {
|
|
742
|
+
this.__homeySocket = this.__socket.io.socket(namespace);
|
|
769
743
|
|
|
770
|
-
|
|
771
|
-
this.
|
|
744
|
+
this.__homeySocket.once('connect', () => {
|
|
745
|
+
this.__debug(`SocketIOClient.Namespace[${namespace}].onConnect`);
|
|
746
|
+
resolve();
|
|
747
|
+
});
|
|
772
748
|
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
749
|
+
this.__homeySocket.once('connect_error', err => {
|
|
750
|
+
this.__debug(`SocketIOClient.Namespace[${namespace}].onConnectError`, err.message);
|
|
751
|
+
reject(err);
|
|
752
|
+
});
|
|
777
753
|
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
});
|
|
754
|
+
this.__homeySocket.on('disconnect', reason => {
|
|
755
|
+
this.__debug(`SocketIOClient.Namespace[${namespace}].onDisconnect`, reason);
|
|
756
|
+
});
|
|
782
757
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
758
|
+
this.__homeySocket.on('reconnecting', attempt => {
|
|
759
|
+
this.__debug(`SocketIOClient.Namespace[${namespace}].onReconnecting (Attempt #${attempt})`);
|
|
760
|
+
});
|
|
786
761
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
762
|
+
this.__homeySocket.on('reconnect', () => {
|
|
763
|
+
this.__debug(`SocketIOClient.Namespace[${namespace}].onReconnect`);
|
|
764
|
+
});
|
|
790
765
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
766
|
+
this.__homeySocket.on('reconnect_error', err => {
|
|
767
|
+
this.__debug(`SocketIOClient.Namespace[${namespace}].onReconnectError`, err.message);
|
|
768
|
+
});
|
|
794
769
|
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
770
|
+
this.__homeySocket.open();
|
|
771
|
+
});
|
|
772
|
+
}
|
|
798
773
|
|
|
799
|
-
|
|
774
|
+
const handshakeClient = async () => {
|
|
775
|
+
return new Promise((resolve, reject) => {
|
|
776
|
+
this.__socket.emit('handshakeClient', {
|
|
777
|
+
token: this.__token,
|
|
778
|
+
homeyId: this.id,
|
|
779
|
+
}, (err, result) => {
|
|
780
|
+
if (err) return reject(err);
|
|
781
|
+
return resolve(result);
|
|
800
782
|
});
|
|
801
783
|
});
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
try {
|
|
787
|
+
const result = await Util.timeout(handshakeClient(), 5000, `Failed to handshake client (Timeout after 5000ms).`);
|
|
788
|
+
|
|
789
|
+
return onResult(result);
|
|
790
|
+
} catch (err) {
|
|
791
|
+
if (err.statusCode === 401 || err.code === 401) {
|
|
792
|
+
this.__debug('Token expired, refreshing...');
|
|
793
|
+
await this.logout();
|
|
794
|
+
await this.login();
|
|
795
|
+
|
|
796
|
+
const result = await Util.timeout(handshakeClient(), 5000, `Failed to handshake client (Timeout after 5000ms).`);
|
|
797
|
+
|
|
798
|
+
return onResult(result);
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
throw err;
|
|
802
|
+
}
|
|
802
803
|
}
|
|
803
804
|
|
|
804
805
|
hasScope(scope) {
|