homey-api 3.0.26 → 3.1.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>;
|
|
@@ -4465,6 +4481,8 @@ export class Util {
|
|
|
4465
4481
|
|
|
4466
4482
|
static serializeQueryObject(queryObject: object): string;
|
|
4467
4483
|
|
|
4484
|
+
static encodeUrlSearchParams(params: object): string;
|
|
4485
|
+
|
|
4468
4486
|
static fetch(args: any): Promise;
|
|
4469
4487
|
|
|
4470
4488
|
static wait(ms: number): Promise<void>;
|
|
@@ -4498,6 +4516,8 @@ export class Util {
|
|
|
4498
4516
|
static promiseAny(promises: Array<Promise>): Promise<any>;
|
|
4499
4517
|
|
|
4500
4518
|
static serializeQueryObject(queryObject: object): string;
|
|
4519
|
+
|
|
4520
|
+
static encodeUrlSearchParams(params: object): string;
|
|
4501
4521
|
}
|
|
4502
4522
|
|
|
4503
4523
|
export class APIDefinition {}
|
|
@@ -5683,6 +5703,14 @@ export class AthomCloudAPI {
|
|
|
5683
5703
|
userId?: string;
|
|
5684
5704
|
}): Promise<any>;
|
|
5685
5705
|
|
|
5706
|
+
addTagToMailChimpUser(opts: {
|
|
5707
|
+
listId?: string;
|
|
5708
|
+
|
|
5709
|
+
userId?: string;
|
|
5710
|
+
|
|
5711
|
+
tag?: string;
|
|
5712
|
+
}): Promise<any>;
|
|
5713
|
+
|
|
5686
5714
|
getAppInstallsStatistics(): Promise<any>;
|
|
5687
5715
|
|
|
5688
5716
|
getAppDriversStatistics(): Promise<any>;
|
|
@@ -6207,6 +6235,14 @@ export class AthomCloudAPI {
|
|
|
6207
6235
|
userId?: string;
|
|
6208
6236
|
}): Promise<any>;
|
|
6209
6237
|
|
|
6238
|
+
addTagToMailChimpUser(opts: {
|
|
6239
|
+
listId?: string;
|
|
6240
|
+
|
|
6241
|
+
userId?: string;
|
|
6242
|
+
|
|
6243
|
+
tag?: string;
|
|
6244
|
+
}): Promise<any>;
|
|
6245
|
+
|
|
6210
6246
|
getAppInstallsStatistics(): Promise<any>;
|
|
6211
6247
|
|
|
6212
6248
|
getAppDriversStatistics(): Promise<any>;
|
|
@@ -7425,6 +7461,8 @@ export class Util {
|
|
|
7425
7461
|
|
|
7426
7462
|
static serializeQueryObject(queryObject: object): string;
|
|
7427
7463
|
|
|
7464
|
+
static encodeUrlSearchParams(params: object): string;
|
|
7465
|
+
|
|
7428
7466
|
static fetch(args: any): Promise;
|
|
7429
7467
|
|
|
7430
7468
|
static wait(ms: number): Promise<void>;
|
|
@@ -7458,6 +7496,8 @@ export class Util {
|
|
|
7458
7496
|
static promiseAny(promises: Array<Promise>): Promise<any>;
|
|
7459
7497
|
|
|
7460
7498
|
static serializeQueryObject(queryObject: object): string;
|
|
7499
|
+
|
|
7500
|
+
static encodeUrlSearchParams(params: object): string;
|
|
7461
7501
|
}
|
|
7462
7502
|
|
|
7463
7503
|
export namespace HomeyAPIV3Cloud {
|
package/lib/AthomCloudAPI.js
CHANGED
|
@@ -214,20 +214,21 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
214
214
|
throw new Error('Missing Redirect URL');
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
217
|
+
const params = {
|
|
218
|
+
client_id: this.__clientId,
|
|
219
|
+
redirect_uri: this.__redirectUrl,
|
|
220
|
+
response_type: 'code',
|
|
221
|
+
}
|
|
221
222
|
|
|
222
223
|
if (typeof state === 'string') {
|
|
223
|
-
|
|
224
|
+
params.state = state;
|
|
224
225
|
}
|
|
225
226
|
|
|
226
227
|
if (Array.isArray(scopes)) {
|
|
227
|
-
|
|
228
|
+
params.scope = scopes.join(',');
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
return `${this.baseUrl}/oauth2/authorise?${
|
|
231
|
+
return `${this.baseUrl}/oauth2/authorise?${Util.encodeUrlSearchParams(params)}`;
|
|
231
232
|
}
|
|
232
233
|
|
|
233
234
|
async getDelegatedLoginUrl(args = {}) {
|
|
@@ -240,19 +241,20 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
240
241
|
meta: args.meta,
|
|
241
242
|
});
|
|
242
243
|
|
|
243
|
-
const
|
|
244
|
-
|
|
244
|
+
const params = {
|
|
245
|
+
user_token: token,
|
|
246
|
+
}
|
|
245
247
|
|
|
246
248
|
if (typeof args.state === 'string') {
|
|
247
|
-
|
|
249
|
+
params.state = args.state;
|
|
248
250
|
}
|
|
249
251
|
|
|
250
252
|
if (typeof args.resource === 'string') {
|
|
251
|
-
|
|
253
|
+
params.resource = args.resource;
|
|
252
254
|
}
|
|
253
255
|
|
|
254
256
|
const seperator = args.baseUrl.indexOf('?') >= 0 ? '&' : '?';
|
|
255
|
-
return args.baseUrl + seperator +
|
|
257
|
+
return args.baseUrl + seperator + Util.encodeUrlSearchParams(params);
|
|
256
258
|
}
|
|
257
259
|
|
|
258
260
|
/**
|
|
@@ -366,11 +368,12 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
366
368
|
throw new Error('Missing Client Secret');
|
|
367
369
|
}
|
|
368
370
|
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
+
const params = {
|
|
372
|
+
grant_type: 'client_credentials',
|
|
373
|
+
}
|
|
371
374
|
|
|
372
375
|
const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
|
|
373
|
-
body:
|
|
376
|
+
body: Util.encodeUrlSearchParams(params),
|
|
374
377
|
method: 'post',
|
|
375
378
|
headers: {
|
|
376
379
|
Authorization: `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
@@ -427,12 +430,13 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
427
430
|
throw new Error('Missing Client Secret');
|
|
428
431
|
}
|
|
429
432
|
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
+
const params = {
|
|
434
|
+
grant_type: 'authorization_code',
|
|
435
|
+
code: code,
|
|
436
|
+
}
|
|
433
437
|
|
|
434
438
|
const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
|
|
435
|
-
body:
|
|
439
|
+
body: Util.encodeUrlSearchParams(params),
|
|
436
440
|
method: 'post',
|
|
437
441
|
headers: {
|
|
438
442
|
Authorization: `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
@@ -487,13 +491,14 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
487
491
|
throw new Error('Missing Client Secret');
|
|
488
492
|
}
|
|
489
493
|
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
+
const params = {
|
|
495
|
+
grant_type: 'password',
|
|
496
|
+
username: username,
|
|
497
|
+
password: password,
|
|
498
|
+
}
|
|
494
499
|
|
|
495
500
|
const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
|
|
496
|
-
body:
|
|
501
|
+
body: Util.encodeUrlSearchParams(params),
|
|
497
502
|
method: 'post',
|
|
498
503
|
headers: {
|
|
499
504
|
Authorization: `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
@@ -533,12 +538,13 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
533
538
|
throw new Error('Missing Refresh Token');
|
|
534
539
|
}
|
|
535
540
|
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
|
|
541
|
+
const params = {
|
|
542
|
+
grant_type: 'refresh_token',
|
|
543
|
+
refresh_token: this.__token.refresh_token,
|
|
544
|
+
}
|
|
539
545
|
|
|
540
546
|
const response = await Util.fetch(`${this.baseUrl}/oauth2/token`, {
|
|
541
|
-
body:
|
|
547
|
+
body: Util.encodeUrlSearchParams(params),
|
|
542
548
|
method: 'post',
|
|
543
549
|
headers: {
|
|
544
550
|
Authorization: `Basic ${Util.base64(`${this.__clientId}:${this.__clientSecret}`)}`,
|
|
@@ -433,7 +433,7 @@ class Manager extends EventEmitter {
|
|
|
433
433
|
}
|
|
434
434
|
|
|
435
435
|
__debug(...props) {
|
|
436
|
-
this.homey.__debug(`[${this.constructor.
|
|
436
|
+
this.homey.__debug(`[Manager${this.constructor.ID[0].toUpperCase() + this.constructor.ID.slice(1)}]`, ...props);
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
/**
|
|
@@ -625,10 +625,15 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
625
625
|
|
|
626
626
|
return {
|
|
627
627
|
unsubscribe: () => {
|
|
628
|
-
this.__homeySocket
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
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
|
}
|
|
@@ -713,9 +718,11 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
713
718
|
async disconnect() {
|
|
714
719
|
// Should we wait for connect here?
|
|
715
720
|
|
|
721
|
+
// Also disconnect __homeySocket?
|
|
722
|
+
|
|
716
723
|
if (this.__socket) {
|
|
717
724
|
await new Promise(resolve => {
|
|
718
|
-
this.__socket.once('disconnect', resolve());
|
|
725
|
+
this.__socket.once('disconnect', () => resolve());
|
|
719
726
|
this.__socket.disconnect();
|
|
720
727
|
this.__socket.removeAllListeners();
|
|
721
728
|
this.__socket = null;
|
|
@@ -726,9 +733,16 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
726
733
|
}
|
|
727
734
|
|
|
728
735
|
destroy() {
|
|
736
|
+
if (this.__homeySocket) {
|
|
737
|
+
this.__homeySocket.removeAllListeners();
|
|
738
|
+
this.__homeySocket.close();
|
|
739
|
+
this.__homeySocket = null;
|
|
740
|
+
}
|
|
741
|
+
|
|
729
742
|
if (this.__socket) {
|
|
730
743
|
this.__socket.removeAllListeners();
|
|
731
744
|
this.__socket.close();
|
|
745
|
+
this.__socket = null;
|
|
732
746
|
}
|
|
733
747
|
}
|
|
734
748
|
|
package/lib/Util.js
CHANGED
|
@@ -309,6 +309,25 @@ class Util {
|
|
|
309
309
|
return querystring.join('&');
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
+
/**
|
|
313
|
+
* We use this instead of URLSearchParams because in react-native URLSearchParams are not encoded
|
|
314
|
+
* for some reason.
|
|
315
|
+
*
|
|
316
|
+
* @param {object} params
|
|
317
|
+
* @returns {string} encoded params
|
|
318
|
+
*/
|
|
319
|
+
static encodeUrlSearchParams(params) {
|
|
320
|
+
const encodedPairs = [];
|
|
321
|
+
|
|
322
|
+
for (const [key, value] of Object.entries(params)) {
|
|
323
|
+
const encodedKey = encodeURIComponent(key);
|
|
324
|
+
const encodedValue = encodeURIComponent(value);
|
|
325
|
+
encodedPairs.push(encodedKey + "=" + encodedValue);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return encodedPairs.join("&");
|
|
329
|
+
}
|
|
330
|
+
|
|
312
331
|
}
|
|
313
332
|
|
|
314
333
|
module.exports = Util;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homey-api",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Homey API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -47,10 +47,8 @@
|
|
|
47
47
|
"node": ">=16"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"core-js": "^3.19.1",
|
|
51
50
|
"form-data": "^4.0.0",
|
|
52
51
|
"node-fetch": "^2.6.7",
|
|
53
|
-
"regenerator-runtime": "^0.13.9",
|
|
54
52
|
"socket.io-client": "^2.5.0"
|
|
55
53
|
},
|
|
56
54
|
"devDependencies": {
|