homey-api 1.5.15 → 1.5.18
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.
|
@@ -50,9 +50,20 @@ class DeviceCapability extends EventEmitter {
|
|
|
50
50
|
|
|
51
51
|
// Set Value
|
|
52
52
|
Object.defineProperty(this, '__value', {
|
|
53
|
-
value: device.
|
|
54
|
-
? device.
|
|
55
|
-
? device.
|
|
53
|
+
value: device.capabilitiesObj
|
|
54
|
+
? device.capabilitiesObj[this.id]
|
|
55
|
+
? device.capabilitiesObj[this.id].value
|
|
56
|
+
: null
|
|
57
|
+
: null,
|
|
58
|
+
enumerable: false,
|
|
59
|
+
writable: true,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Set Last Changed
|
|
63
|
+
Object.defineProperty(this, '__lastChanged', {
|
|
64
|
+
value: device.capabilitiesObj
|
|
65
|
+
? device.capabilitiesObj[this.id]
|
|
66
|
+
? device.capabilitiesObj[this.id].lastUpdated
|
|
56
67
|
: null
|
|
57
68
|
: null,
|
|
58
69
|
enumerable: false,
|
|
@@ -91,6 +102,7 @@ class DeviceCapability extends EventEmitter {
|
|
|
91
102
|
|
|
92
103
|
if (value === this.__value) return;
|
|
93
104
|
this.__value = value;
|
|
105
|
+
this.__lastChanged = new Date(transactionTime);
|
|
94
106
|
|
|
95
107
|
this.__listener(value);
|
|
96
108
|
}
|
|
@@ -103,7 +115,20 @@ class DeviceCapability extends EventEmitter {
|
|
|
103
115
|
* @type {boolean|number|string|null}
|
|
104
116
|
*/
|
|
105
117
|
get value() {
|
|
106
|
-
return this.__value
|
|
118
|
+
return typeof this.__value !== 'undefined'
|
|
119
|
+
? this.__value
|
|
120
|
+
: null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @type {Date|null}
|
|
125
|
+
*/
|
|
126
|
+
get lastChanged() {
|
|
127
|
+
return (this.__lastChanged instanceof Date)
|
|
128
|
+
? this.__lastChanged
|
|
129
|
+
: (typeof this.__lastChanged === 'string')
|
|
130
|
+
? new Date(this.__lastChanged)
|
|
131
|
+
: null;
|
|
107
132
|
}
|
|
108
133
|
|
|
109
134
|
/**
|
|
@@ -126,6 +151,7 @@ class DeviceCapability extends EventEmitter {
|
|
|
126
151
|
});
|
|
127
152
|
|
|
128
153
|
this.__value = value;
|
|
154
|
+
this.__lastChanged = new Date();
|
|
129
155
|
}
|
|
130
156
|
|
|
131
157
|
}
|
|
@@ -167,10 +167,7 @@ class Manager extends EventEmitter {
|
|
|
167
167
|
}
|
|
168
168
|
case 'body': {
|
|
169
169
|
if (parameter.root) {
|
|
170
|
-
body =
|
|
171
|
-
...body,
|
|
172
|
-
...value,
|
|
173
|
-
};
|
|
170
|
+
body = value;
|
|
174
171
|
} else {
|
|
175
172
|
body[parameterId] = value;
|
|
176
173
|
}
|
|
@@ -253,6 +250,7 @@ class Manager extends EventEmitter {
|
|
|
253
250
|
} else {
|
|
254
251
|
// Get from HTTP
|
|
255
252
|
result = await this.homey.call({
|
|
253
|
+
$timeout,
|
|
256
254
|
headers,
|
|
257
255
|
body,
|
|
258
256
|
path: `/api/manager/${this.id}${path}`,
|
|
@@ -288,8 +288,6 @@ class HomeyAPIV2 extends HomeyAPI {
|
|
|
288
288
|
promises.push(pings[HomeyAPI.DISCOVERY_STRATEGIES.MDNS]);
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
// TODO: Move this to the catch handler to always fallback on cloud
|
|
292
|
-
// Now mdns or local will error first and cloud won't have a chance!!
|
|
293
291
|
if (pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]) {
|
|
294
292
|
promises.push(pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]);
|
|
295
293
|
}
|
|
@@ -301,7 +299,16 @@ class HomeyAPIV2 extends HomeyAPI {
|
|
|
301
299
|
return Promise.race(promises);
|
|
302
300
|
})
|
|
303
301
|
.then(result => resolve(result))
|
|
304
|
-
.catch(
|
|
302
|
+
.catch(err => {
|
|
303
|
+
// Last resort: try cloud
|
|
304
|
+
if (pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]) {
|
|
305
|
+
return pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD].catch(err => {
|
|
306
|
+
throw new HomeyOfflineError(err);
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
reject(new HomeyOfflineError(err));
|
|
311
|
+
});
|
|
305
312
|
} else if (pings[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL]) {
|
|
306
313
|
pings[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL]
|
|
307
314
|
.then(result => resolve(result))
|