homey-api 1.5.8 → 1.5.11
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.
- package/lib/API.js +4 -0
- package/lib/EventEmitter.js +19 -1
- package/lib/HomeyAPI/HomeyAPIV2/Device.js +18 -1
- package/lib/HomeyAPI/HomeyAPIV2/Manager.js +17 -5
- package/lib/Util.js +12 -1
- package/package.json +1 -1
package/lib/API.js
CHANGED
|
@@ -68,6 +68,8 @@ class API {
|
|
|
68
68
|
|
|
69
69
|
this[operationId] = async ({
|
|
70
70
|
$validate = true,
|
|
71
|
+
$timeout = 10000,
|
|
72
|
+
$timeoutMessage = null,
|
|
71
73
|
$body = {},
|
|
72
74
|
$query = {},
|
|
73
75
|
$headers = {},
|
|
@@ -144,6 +146,8 @@ class API {
|
|
|
144
146
|
body,
|
|
145
147
|
path: pathWithParameters,
|
|
146
148
|
context: { operation },
|
|
149
|
+
timeout: $timeout,
|
|
150
|
+
timeoutMessage: $timeoutMessage,
|
|
147
151
|
});
|
|
148
152
|
};
|
|
149
153
|
}
|
package/lib/EventEmitter.js
CHANGED
|
@@ -26,6 +26,16 @@ class EventEmitter {
|
|
|
26
26
|
listener(...data);
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
+
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {string} event
|
|
35
|
+
* @param {function} callback
|
|
36
|
+
*/
|
|
37
|
+
addListener(event, callback) {
|
|
38
|
+
return this.on(event, callback);
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
/**
|
|
@@ -37,6 +47,8 @@ class EventEmitter {
|
|
|
37
47
|
|
|
38
48
|
this.__listeners[event] = this.__listeners[event] || [];
|
|
39
49
|
this.__listeners[event].push(callback);
|
|
50
|
+
|
|
51
|
+
return this;
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
/**
|
|
@@ -53,6 +65,8 @@ class EventEmitter {
|
|
|
53
65
|
|
|
54
66
|
this.__listeners[event] = this.__listeners[event] || [];
|
|
55
67
|
this.__listeners[event].push(callback_);
|
|
68
|
+
|
|
69
|
+
return this;
|
|
56
70
|
}
|
|
57
71
|
|
|
58
72
|
/**
|
|
@@ -63,6 +77,8 @@ class EventEmitter {
|
|
|
63
77
|
this.__debug(`.off('${event}')`);
|
|
64
78
|
|
|
65
79
|
this.__listeners[event] = this.__listeners[event].filter(cb => cb !== callback);
|
|
80
|
+
|
|
81
|
+
return this;
|
|
66
82
|
}
|
|
67
83
|
|
|
68
84
|
/**
|
|
@@ -71,7 +87,7 @@ class EventEmitter {
|
|
|
71
87
|
* @param {function} callback
|
|
72
88
|
*/
|
|
73
89
|
removeListener(event, callback) {
|
|
74
|
-
this.off(event, callback);
|
|
90
|
+
return this.off(event, callback);
|
|
75
91
|
}
|
|
76
92
|
|
|
77
93
|
/**
|
|
@@ -79,6 +95,8 @@ class EventEmitter {
|
|
|
79
95
|
*/
|
|
80
96
|
removeAllListeners(event) {
|
|
81
97
|
this.__listeners[event] = [];
|
|
98
|
+
|
|
99
|
+
return this;
|
|
82
100
|
}
|
|
83
101
|
|
|
84
102
|
}
|
|
@@ -76,7 +76,16 @@ class Device extends Item {
|
|
|
76
76
|
* @returns {Promise<void>}
|
|
77
77
|
* @function HomeyAPIV2.ManagerDevices.Device#setCapabilityValue
|
|
78
78
|
*/
|
|
79
|
-
async setCapabilityValue({
|
|
79
|
+
async setCapabilityValue(options, ...args) {
|
|
80
|
+
// Legacy compatibility from node-athom-api
|
|
81
|
+
if (typeof options === 'string') {
|
|
82
|
+
return this.setCapabilityValueLegacy(options, ...args);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return this.__setCapabilityValue(options);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async __setCapabilityValue({
|
|
80
89
|
capabilityId,
|
|
81
90
|
value,
|
|
82
91
|
opts,
|
|
@@ -93,6 +102,14 @@ class Device extends Item {
|
|
|
93
102
|
});
|
|
94
103
|
}
|
|
95
104
|
|
|
105
|
+
async setCapabilityValueLegacy(capabilityId, value, opts) {
|
|
106
|
+
return this.__setCapabilityValue({
|
|
107
|
+
capabilityId,
|
|
108
|
+
value,
|
|
109
|
+
opts,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
96
113
|
async connect() {
|
|
97
114
|
this.__debug('connect');
|
|
98
115
|
|
|
@@ -215,15 +215,15 @@ class Manager extends EventEmitter {
|
|
|
215
215
|
case 'getAll': {
|
|
216
216
|
// If array (uri + id)
|
|
217
217
|
if (this.__cache[itemId]
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
&& this.__cacheAllComplete[itemId]
|
|
219
|
+
&& itemType === 'filter') {
|
|
220
220
|
this.__debug(`Serving ${itemId}:all from cache`);
|
|
221
221
|
return Object.values(this.__cache[itemId]);
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
// If object (id)
|
|
225
225
|
if (this.__cache[itemId]
|
|
226
|
-
|
|
226
|
+
&& this.__cacheAllComplete[itemId]) {
|
|
227
227
|
this.__debug(`Serving ${itemId}:all from cache`);
|
|
228
228
|
return this.__cache[itemId];
|
|
229
229
|
}
|
|
@@ -382,8 +382,8 @@ class Manager extends EventEmitter {
|
|
|
382
382
|
|
|
383
383
|
// Transform & add to cache if this is a CRUD event
|
|
384
384
|
if (event.endsWith('.create')
|
|
385
|
-
|
|
386
|
-
|
|
385
|
+
|| event.endsWith('.update')
|
|
386
|
+
|| event.endsWith('.delete')) {
|
|
387
387
|
const [itemId, operation] = event.split('.');
|
|
388
388
|
const ItemClass = this.constructor.ITEMS[itemId] || Item;
|
|
389
389
|
const itemType = this.__itemsById[itemId].type;
|
|
@@ -449,6 +449,18 @@ class Manager extends EventEmitter {
|
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
451
|
|
|
452
|
+
destroy() {
|
|
453
|
+
for (const id of Object.keys(this.__cache)) {
|
|
454
|
+
this.__cache[id] = {};
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
for (const id of Object.keys(this.__cacheAllComplete)) {
|
|
458
|
+
this.__cacheAllComplete[id] = false;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
this.disconnect().catch(() => { });
|
|
462
|
+
}
|
|
463
|
+
|
|
452
464
|
}
|
|
453
465
|
|
|
454
466
|
module.exports = Manager;
|
package/lib/Util.js
CHANGED
|
@@ -86,6 +86,13 @@ class Util {
|
|
|
86
86
|
return (typeof window !== 'undefined');
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* @returns {boolean}
|
|
91
|
+
*/
|
|
92
|
+
static isNodeJS() {
|
|
93
|
+
return (typeof process !== 'undefined');
|
|
94
|
+
}
|
|
95
|
+
|
|
89
96
|
/**
|
|
90
97
|
* @param {string} name - Query parameter name
|
|
91
98
|
* @returns {string|null}
|
|
@@ -148,7 +155,11 @@ class Util {
|
|
|
148
155
|
return window.localStorage.getItem(key) || null;
|
|
149
156
|
}
|
|
150
157
|
|
|
151
|
-
|
|
158
|
+
if (this.isNodeJS()) {
|
|
159
|
+
return process.env[key] || null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return null;
|
|
152
163
|
}
|
|
153
164
|
|
|
154
165
|
static envKey(key) {
|