homey-api 1.10.7 → 1.10.9

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.
@@ -48,7 +48,11 @@ class Device extends Item {
48
48
  this.__capabilityInstances[capabilityId] = this.__capabilityInstances[capabilityId] || [];
49
49
  this.__capabilityInstances[capabilityId] = this.__capabilityInstances[capabilityId].filter(i => i !== instance);
50
50
 
51
- if (Object.keys(this.__capabilityInstances[capabilityId]).length === 0) {
51
+ if (this.__capabilityInstances[capabilityId].length === 0) {
52
+ delete this.__capabilityInstances[capabilityId];
53
+ }
54
+
55
+ if (Object.keys(this.__capabilityInstances).length === 0) {
52
56
  this.__debug('No more Capability instances, disconnecting...');
53
57
  this.disconnect().catch(err => this.__debug(err));
54
58
  }
@@ -104,6 +104,13 @@ class DeviceCapability extends EventEmitter {
104
104
  this.__value = value;
105
105
  this.__lastChanged = new Date(transactionTime);
106
106
 
107
+ // Mutate the current device capabilitiesObj so it always reflects the last value.
108
+ const capabilityReference = this.device.capabilitiesObj && this.device.capabilitiesObj[this.id];
109
+ if (capabilityReference) {
110
+ capabilityReference.value = value;
111
+ capabilityReference.lastUpdated = this.__lastChanged.toISOString();
112
+ }
113
+
107
114
  this.__listener(value);
108
115
  }
109
116
 
@@ -152,6 +159,13 @@ class DeviceCapability extends EventEmitter {
152
159
 
153
160
  this.__value = value;
154
161
  this.__lastChanged = new Date();
162
+
163
+ // Mutate the current device capabilitiesObj so it always reflects the last value.
164
+ const capabilityReference = this.device.capabilitiesObj && this.device.capabilitiesObj[this.id];
165
+ if (capabilityReference) {
166
+ capabilityReference.value = value;
167
+ capabilityReference.lastUpdated = this.__lastChanged.toISOString();
168
+ }
155
169
  }
156
170
 
157
171
  }
@@ -74,6 +74,10 @@ class Item extends EventEmitter {
74
74
 
75
75
  // If disconnecting, await that first
76
76
  try {
77
+ // Ensure all microtasks are done first. E.g. if disconnect is called in the same tick as
78
+ // connect. This way the disconnect is always started first so we can await the disconnect
79
+ // promise before we try to connect again.
80
+ await Promise.resolve();
77
81
  await this.__disconnectPromise;
78
82
  } catch (err) { }
79
83
 
@@ -141,6 +145,8 @@ class Item extends EventEmitter {
141
145
  .catch(() => { })
142
146
  .finally(() => {
143
147
  delete this.__disconnectPromise;
148
+ // Delete this.io so connect can start new connections.
149
+ delete this.io;
144
150
  });
145
151
 
146
152
  await this.__disconnectPromise;
@@ -255,8 +255,25 @@ class Manager extends EventEmitter {
255
255
  args,
256
256
  operation: operationId,
257
257
  uri: this.uri,
258
- }, (error, result) => {
259
- if (error) return reject(new HomeyAPIError({ error }));
258
+ }, (err, result) => {
259
+ // String Error
260
+ if (typeof err === 'string') {
261
+ err = new HomeyAPIError({
262
+ error: err,
263
+ }, 500);
264
+ return reject(err);
265
+ }
266
+
267
+ // Object Error
268
+ if (typeof err === 'object' && err !== null) {
269
+ err = new HomeyAPIError({
270
+ stack: err.stack,
271
+ error: err.error,
272
+ error_description: err.error_description,
273
+ }, err.statusCode || 500);
274
+ return reject(err);
275
+ }
276
+
260
277
  return resolve(result);
261
278
  });
262
279
  }), $timeout);
@@ -655,7 +655,7 @@ class HomeyAPIV2 extends HomeyAPI {
655
655
  this.__io = null;
656
656
  });
657
657
  }
658
- // TODO
658
+ // TODO todo what?
659
659
  }
660
660
 
661
661
  destroy() {
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ const Manager = require('./Manager');
4
+
5
+ class ManagerFlow extends Manager {
6
+
7
+ async getFlowCardTrigger(args = {}, ...rest) {
8
+ args.uri = '';
9
+ return this.__super__getFlowCardTrigger(args, ...rest);
10
+ }
11
+
12
+ async getFlowCardCondition(args = {}, ...rest) {
13
+ args.uri = '';
14
+ return this.__super__getFlowCardCondition(args, ...rest);
15
+ }
16
+
17
+ async runFlowCardCondition(args = {}, ...rest) {
18
+ args.uri = '';
19
+ return this.__super__runFlowCardCondition(args, ...rest);
20
+ }
21
+
22
+ async getFlowCardAction(args = {}, ...rest) {
23
+ args.uri = '';
24
+ return this.__super__getFlowCardAction(args, ...rest);
25
+ }
26
+
27
+ async runFlowCardAction(args = {}, ...rest) {
28
+ args.uri = '';
29
+ return this.__super__runFlowCardAction(args, ...rest);
30
+ }
31
+
32
+ }
33
+
34
+ module.exports = ManagerFlow;
@@ -2,6 +2,8 @@
2
2
 
3
3
  const HomeyAPIV2 = require('./HomeyAPIV2');
4
4
 
5
+ const ManagerFlow = require('./HomeyAPIV3/ManagerFlow');
6
+
5
7
  /**
6
8
  * @class
7
9
  * @hideconstructor
@@ -9,6 +11,11 @@ const HomeyAPIV2 = require('./HomeyAPIV2');
9
11
  */
10
12
  class HomeyAPIV3 extends HomeyAPIV2 {
11
13
 
14
+ static MANAGERS = {
15
+ ...HomeyAPIV2.MANAGERS,
16
+ ManagerFlow,
17
+ };
18
+
12
19
  }
13
20
 
14
21
  module.exports = HomeyAPIV3;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "1.10.7",
3
+ "version": "1.10.9",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "files": [