homey-api 1.5.23 → 1.5.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.
@@ -13,7 +13,7 @@ class Item extends EventEmitter {
13
13
  }) {
14
14
  super();
15
15
 
16
- // Set Manager
16
+ // Set Homey
17
17
  Object.defineProperty(this, 'homey', {
18
18
  value: homey,
19
19
  enumerable: false,
@@ -98,10 +98,9 @@ class Item extends EventEmitter {
98
98
  this.onReconnect();
99
99
  },
100
100
  onEvent: (event, data) => {
101
- // // Fire event listeners
102
- if (Array.isArray(this.__listeners[event])) {
103
- this.__listeners[event].forEach(listener => listener(data));
104
- }
101
+ this.__debug('onEvent', event, data);
102
+
103
+ this.emit(event, data);
105
104
  },
106
105
  });
107
106
  }
@@ -352,6 +352,7 @@ class Manager extends EventEmitter {
352
352
  result = new ItemClass({
353
353
  key,
354
354
  uri,
355
+ homey: this.homey,
355
356
  manager: this,
356
357
  properties: result,
357
358
  });
@@ -415,8 +416,8 @@ class Manager extends EventEmitter {
415
416
  this.__debug('onConnect');
416
417
  this.__connected = true;
417
418
  },
418
- onDisconnect: () => {
419
- this.__debug('onDisconnect');
419
+ onDisconnect: reason => {
420
+ this.__debug(`onDisconnect Reason:${reason}`);
420
421
  this.__connected = false;
421
422
 
422
423
  // Clear CRUD Item cache
@@ -447,6 +448,7 @@ class Manager extends EventEmitter {
447
448
  this.__cache[itemId][key] = new ItemClass({
448
449
  key,
449
450
  uri,
451
+ homey: this.homey,
450
452
  manager: this,
451
453
  properties: { ...data },
452
454
  });
@@ -464,6 +466,7 @@ class Manager extends EventEmitter {
464
466
  this.__cache[itemId][key] = new ItemClass({
465
467
  key,
466
468
  uri,
469
+ homey: this.homey,
467
470
  manager: this,
468
471
  properties: { ...data },
469
472
  });
@@ -437,7 +437,10 @@ class HomeyAPIV2 extends HomeyAPI {
437
437
  // and then sending the JWT token to Homey.
438
438
  this.__debug('Retrieving token...');
439
439
  const jwtToken = await this.__api.createDelegationToken({ audience: 'homey' });
440
- const token = await this.users.login({ token: jwtToken });
440
+ const token = await this.users.login({
441
+ $socket: false,
442
+ token: jwtToken,
443
+ });
441
444
  await this.__setStore({ token });
442
445
  this.__debug('Got token');
443
446
 
@@ -486,6 +489,7 @@ class HomeyAPIV2 extends HomeyAPI {
486
489
 
487
490
  await this.connect();
488
491
  await new Promise((resolve, reject) => {
492
+ this.__ioNamespace.once('disconnect', reject);
489
493
  this.__ioNamespace.emit('subscribe', uri, err => {
490
494
  if (err) return reject(err);
491
495
  return resolve();
@@ -501,8 +505,8 @@ class HomeyAPIV2 extends HomeyAPI {
501
505
  onConnect();
502
506
 
503
507
  // On Disconnect
504
- const __onDisconnect = () => {
505
- onDisconnect();
508
+ const __onDisconnect = reason => {
509
+ onDisconnect(reason);
506
510
  };
507
511
  this.__io.on('disconnect', __onDisconnect);
508
512
 
@@ -546,6 +550,7 @@ class HomeyAPIV2 extends HomeyAPI {
546
550
  return new Promise((resolve, reject) => {
547
551
  this.__debug(`SocketIOClient ${baseUrl}`);
548
552
  this.__io = SocketIOClient(baseUrl, {
553
+ autoConnect: false,
549
554
  transports: ['websocket'],
550
555
  transportOptions: {
551
556
  pingTimeout: 8000,
@@ -603,6 +608,7 @@ class HomeyAPIV2 extends HomeyAPI {
603
608
  reject(err);
604
609
  });
605
610
  });
611
+ this.__io.connect();
606
612
  });
607
613
  });
608
614
  this.io.catch(err => {
@@ -663,28 +669,29 @@ class HomeyAPIV2 extends HomeyAPI {
663
669
  throw err;
664
670
  })
665
671
  .then(({ namespace }) => {
672
+ this.__debug('SocketIOClient.onHandshakeClientSuccess', `Namespace: ${namespace}`);
673
+
666
674
  return new Promise((resolve, reject) => {
667
- this.__debug('SocketIOClient.onHandshakeClientSuccess', `Namespace: ${namespace}`);
668
675
  this.__ioNamespace = this.__io.io.socket(namespace);
669
676
  this.__ioNamespace.once('connect', () => {
670
- this.__debug('SocketIOClient.Namespace.onConnect');
677
+ this.__debug(`SocketIOClient.Namespace[${namespace}].onConnect`);
671
678
  resolve();
672
679
  });
673
680
  this.__ioNamespace.once('connect_error', err => {
674
- this.__debug('SocketIOClient.Namespace.onConnectError', err.message);
681
+ this.__debug(`SocketIOClient.Namespace[${namespace}].onConnectError`, err.message);
675
682
  reject(err);
676
683
  });
677
684
  this.__ioNamespace.on('reconnecting', attempt => {
678
- this.__debug(`SocketIOClient.Namespace.onReconnecting (Attempt #${attempt})`);
685
+ this.__debug(`SocketIOClient.Namespace[${namespace}].onReconnecting (Attempt #${attempt})`);
679
686
  });
680
687
  this.__ioNamespace.on('reconnect', () => {
681
- this.__debug('SocketIOClient.Namespace.onReconnect');
688
+ this.__debug(`SocketIOClient.Namespace[${namespace}].onReconnect`);
682
689
  });
683
690
  this.__ioNamespace.on('reconnect_error', err => {
684
- this.__debug('SocketIOClient.Namespace.onReconnectError', err.message);
691
+ this.__debug(`SocketIOClient.Namespace[${namespace}].onReconnectError`, err.message);
685
692
  });
686
693
  this.__ioNamespace.on('disconnect', reason => {
687
- this.__debug('SocketIOClient.Namespace.onDisconnect', reason);
694
+ this.__debug(`SocketIOClient.Namespace[${namespace}].onDisconnect`, reason);
688
695
  });
689
696
  this.__ioNamespace.connect();
690
697
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "1.5.23",
3
+ "version": "1.5.26",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "types": "assets/types/homey-api.d.ts",