homey-api 3.4.25 → 3.4.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.
@@ -17,6 +17,8 @@ const ManagerInsights = require('./HomeyAPIV2/ManagerInsights');
17
17
  */
18
18
  class HomeyAPIV2 extends HomeyAPIV3 {
19
19
 
20
+ static DEFAULT_TIMEOUT = 1000 * 30;
21
+
20
22
  static MANAGERS = {
21
23
  ...super.MANAGERS,
22
24
  ManagerFlow,
@@ -102,7 +102,7 @@ class Manager extends EventEmitter {
102
102
  $validate = true,
103
103
  $cache = true,
104
104
  $updateCache = true,
105
- $timeout = operation.timeout ?? 5000,
105
+ $timeout = operation.timeout ?? this.homey.constructor.DEFAULT_TIMEOUT,
106
106
  $socket = operation.socket ?? true,
107
107
  $body = {},
108
108
  $query = {},
@@ -36,6 +36,10 @@ class HomeyAPIV3 extends HomeyAPI {
36
36
  ManagerUsers,
37
37
  };
38
38
 
39
+ static DEFAULT_TIMEOUT = 1000 * 10;
40
+ static HANDSHAKE_TIMEOUT = 1000 * 10;
41
+ static SUBSCRIBE_TIMEOUT = 1000 * 10;
42
+
39
43
  constructor({
40
44
  properties,
41
45
  strategy = [
@@ -274,6 +278,7 @@ class HomeyAPIV3 extends HomeyAPI {
274
278
  if (text === 'false') throw new Error('Invalid Homey ID');
275
279
 
276
280
  const homeyId = res.headers.get('X-Homey-ID');
281
+
277
282
  if (homeyId) {
278
283
  if (homeyId !== this.id) throw new Error('Invalid Homey ID'); // TODO: Add to Homey Connect
279
284
  }
@@ -414,13 +419,13 @@ class HomeyAPIV3 extends HomeyAPI {
414
419
  return promise;
415
420
  }
416
421
 
417
- async call({
418
- $timeout = 10000,
419
- method,
420
- headers,
421
- path,
422
- body,
423
- json = true,
422
+ async call({
423
+ $timeout = this.constructor.DEFAULT_TIMEOUT,
424
+ method,
425
+ headers,
426
+ path,
427
+ body,
428
+ json = true,
424
429
  isRetryAfterRefresh = false,
425
430
  shouldRetry = true,
426
431
  }) {
@@ -626,9 +631,9 @@ class HomeyAPIV3 extends HomeyAPI {
626
631
  .finally(() => {
627
632
  // Delete after 30 seconds some requests might still be pending an they should be able
628
633
  // to receive a rejected promise for this token.
629
- this.__refreshMap[token+'timeout'] = setTimeout(() => {
634
+ this.__refreshMap[token + 'timeout'] = setTimeout(() => {
630
635
  delete this.__refreshMap[token];
631
- delete this.__refreshMap[token+'timeout'];
636
+ delete this.__refreshMap[token + 'timeout'];
632
637
  }, 30 * 1000);
633
638
  });
634
639
  }
@@ -678,8 +683,8 @@ class HomeyAPIV3 extends HomeyAPI {
678
683
  return resolve();
679
684
  });
680
685
  }),
681
- 10000,
682
- `Failed to subscribe to ${uri} (Timeout after 10000ms).`
686
+ this.constructor.SUBSCRIBE_TIMEOUT,
687
+ `Failed to subscribe to ${uri} (Timeout after ${this.constructor.SUBSCRIBE_TIMEOUT}ms).`
683
688
  );
684
689
 
685
690
  // On Connect
@@ -722,8 +727,8 @@ class HomeyAPIV3 extends HomeyAPI {
722
727
  return resolve();
723
728
  });
724
729
  }),
725
- 10000,
726
- `Failed to subscribe to ${uri} (Timeout after 10000ms).`
730
+ this.constructor.SUBSCRIBE_TIMEOUT,
731
+ `Failed to subscribe to ${uri} (Timeout after ${this.constructor.SUBSCRIBE_TIMEOUT}ms).`
727
732
  );
728
733
 
729
734
  this.__homeySocket.on(uri, __onEvent);
@@ -975,8 +980,8 @@ class HomeyAPIV3 extends HomeyAPI {
975
980
  try {
976
981
  const result = await Util.timeout(
977
982
  handshakeClient(token),
978
- 5000,
979
- `Failed to handshake client (Timeout after 5000ms).`
983
+ this.constructor.HANDSHAKE_TIMEOUT,
984
+ `Failed to handshake client (Timeout after ${this.constructor.HANDSHAKE_TIMEOUT}ms).`
980
985
  );
981
986
 
982
987
  return onResult(result);
@@ -986,8 +991,8 @@ class HomeyAPIV3 extends HomeyAPI {
986
991
  await this.refreshForToken(token, false);
987
992
  const result = await Util.timeout(
988
993
  handshakeClient(this.__token),
989
- 5000,
990
- `Failed to handshake client (Timeout after 5000ms).`
994
+ this.constructor.HANDSHAKE_TIMEOUT,
995
+ `Failed to handshake client (Timeout after ${this.constructor.HANDSHAKE_TIMEOUT}ms).`
991
996
  );
992
997
 
993
998
  return onResult(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "3.4.25",
3
+ "version": "3.4.26",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "files": [