homey-api 3.0.0-rc.1 → 3.0.0-rc.10
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/assets/specifications/HomeyAPIV3Local.json +269 -5
- package/assets/types/homey-api.d.ts +267 -59
- package/assets/types/homey-api.private.d.ts +267 -59
- package/lib/HomeyAPI/HomeyAPI.js +12 -7
- package/lib/HomeyAPI/HomeyAPIV2/ManagerDevices/Capability.js +2 -2
- package/lib/HomeyAPI/HomeyAPIV2/ManagerDevices/Device.js +2 -2
- package/lib/HomeyAPI/HomeyAPIV2/ManagerDevices.js +0 -14
- package/lib/HomeyAPI/HomeyAPIV2/ManagerDrivers/Driver.js +2 -2
- package/lib/HomeyAPI/HomeyAPIV2/ManagerDrivers/PairSession.js +20 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerDrivers.js +17 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow/AdvancedFlow.js +16 -3
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow/Flow.js +25 -2
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow/FlowCardAction.js +2 -2
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow/FlowCardCondition.js +2 -2
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow/FlowCardTrigger.js +2 -2
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow.js +36 -13
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlowToken/FlowToken.js +3 -3
- package/lib/HomeyAPI/HomeyAPIV2/ManagerInsights/Log.js +2 -3
- package/lib/HomeyAPI/HomeyAPIV2/ManagerInsights.js +17 -0
- package/lib/HomeyAPI/HomeyAPIV3/Item.js +14 -1
- package/lib/HomeyAPI/HomeyAPIV3/Manager.js +25 -43
- package/lib/HomeyAPI/HomeyAPIV3/ManagerDevices/Device.js +12 -12
- package/lib/HomeyAPI/HomeyAPIV3/ManagerDevices/DeviceCapability.js +1 -1
- package/lib/HomeyAPI/HomeyAPIV3/ManagerDrivers/PairSession.js +9 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerDrivers.js +2 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/Flow.js +8 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/FlowCard.js +8 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlowToken/FlowToken.js +4 -1
- package/lib/HomeyAPI/HomeyAPIV3/ManagerInsights/Log.js +14 -0
- package/package.json +1 -1
|
@@ -18,22 +18,45 @@ class ManagerFlow extends Manager {
|
|
|
18
18
|
FlowCardAction,
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// async createAdvancedFlow() {
|
|
21
|
+
async createFlow({
|
|
22
|
+
flow,
|
|
23
|
+
...props
|
|
24
|
+
}) {
|
|
25
|
+
return this.__super__.createFlow({
|
|
26
|
+
flow: Flow.transformSet(flow),
|
|
27
|
+
...props,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
async updateFlow({
|
|
32
|
+
flow,
|
|
33
|
+
...props
|
|
34
|
+
}) {
|
|
35
|
+
return this.__super__.updateFlow({
|
|
36
|
+
flow: Flow.transformSet(flow),
|
|
37
|
+
...props,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
33
40
|
|
|
34
|
-
|
|
41
|
+
async createAdvancedFlow({
|
|
42
|
+
advancedflow,
|
|
43
|
+
...props
|
|
44
|
+
}) {
|
|
45
|
+
return this.__super__.createAdvancedFlow({
|
|
46
|
+
advancedflow: AdvancedFlow.transformSet(advancedflow),
|
|
47
|
+
...props,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
35
50
|
|
|
36
|
-
|
|
51
|
+
async updateAdvancedFlow({
|
|
52
|
+
advancedflow,
|
|
53
|
+
...props
|
|
54
|
+
}) {
|
|
55
|
+
return this.__super__.updateAdvancedFlow({
|
|
56
|
+
advancedflow: AdvancedFlow.transformSet(advancedflow),
|
|
57
|
+
...props,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
37
60
|
|
|
38
61
|
async getFlowCardTrigger({
|
|
39
62
|
$cache = true,
|
|
@@ -4,15 +4,15 @@ const FlowTokenV3 = require('../../HomeyAPIV3/ManagerFlowToken/FlowToken');
|
|
|
4
4
|
|
|
5
5
|
class FlowToken extends FlowTokenV3 {
|
|
6
6
|
|
|
7
|
-
static
|
|
7
|
+
static transformGet(item) {
|
|
8
8
|
// TODO: Remove FlowTokenV3.transform and uncomment this after front-end does not use FlowToken.uri|id|uriObj anymore!
|
|
9
|
-
// item = super.
|
|
9
|
+
// item = super.transformGet(item);
|
|
10
10
|
|
|
11
11
|
item.ownerUri = item.uri;
|
|
12
12
|
item.ownerId = item.id;
|
|
13
|
-
item.ownerName = item.uriObj.name;
|
|
14
13
|
item.id = `${item.ownerUri}:${item.ownerId}`;
|
|
15
14
|
|
|
15
|
+
delete item.ownerName; // Prepare for back-end change
|
|
16
16
|
delete item.uri;
|
|
17
17
|
delete item.uriObj;
|
|
18
18
|
|
|
@@ -4,12 +4,11 @@ const LogV3 = require('../../HomeyAPIV3/ManagerInsights/Log');
|
|
|
4
4
|
|
|
5
5
|
class Log extends LogV3 {
|
|
6
6
|
|
|
7
|
-
static
|
|
8
|
-
item = super.
|
|
7
|
+
static transformGet(item) {
|
|
8
|
+
item = super.transformGet(item);
|
|
9
9
|
|
|
10
10
|
item.ownerId = item.id;
|
|
11
11
|
item.ownerUri = item.uri;
|
|
12
|
-
item.ownerName = item.uriObj.name;
|
|
13
12
|
item.id = `${item.uri}:${item.id}`;
|
|
14
13
|
|
|
15
14
|
delete item.uri;
|
|
@@ -24,6 +24,23 @@ class ManagerInsights extends ManagerInsightsV3 {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
async getLogEntries({ id }) {
|
|
28
|
+
return this.__super__getLogEntries({
|
|
29
|
+
id: id.split(':').reverse()[0],
|
|
30
|
+
uri: id.split(':', 3).join(':'),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async deleteLogEntries({ id }) {
|
|
35
|
+
return this.__super__deleteLogEntries({
|
|
36
|
+
id: id.split(':').reverse()[0],
|
|
37
|
+
uri: id.split(':', 3).join(':'),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// deleteLog
|
|
42
|
+
// updateLog
|
|
43
|
+
|
|
27
44
|
}
|
|
28
45
|
|
|
29
46
|
module.exports = ManagerInsights;
|
|
@@ -64,8 +64,17 @@ class Item extends EventEmitter {
|
|
|
64
64
|
|
|
65
65
|
__update(properties) {
|
|
66
66
|
for (const [key, value] of Object.entries(properties)) {
|
|
67
|
+
if (key === 'id') continue;
|
|
68
|
+
|
|
67
69
|
this[key] = value;
|
|
68
70
|
}
|
|
71
|
+
|
|
72
|
+
this.emit('update', properties);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
__delete() {
|
|
76
|
+
this.destroy();
|
|
77
|
+
this.emit('delete');
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
async connect() {
|
|
@@ -171,7 +180,11 @@ class Item extends EventEmitter {
|
|
|
171
180
|
this.disconnect().catch(() => { });
|
|
172
181
|
}
|
|
173
182
|
|
|
174
|
-
static
|
|
183
|
+
static transformGet(item) {
|
|
184
|
+
return item;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
static transformSet(item) {
|
|
175
188
|
return item;
|
|
176
189
|
}
|
|
177
190
|
|
|
@@ -258,9 +258,8 @@ class Manager extends EventEmitter {
|
|
|
258
258
|
switch (operation.crud.type) {
|
|
259
259
|
case 'getOne': {
|
|
260
260
|
let item = { ...result };
|
|
261
|
-
item = Item.
|
|
261
|
+
item = Item.transformGet(item);
|
|
262
262
|
item = new Item({
|
|
263
|
-
itemId,
|
|
264
263
|
id: item.id,
|
|
265
264
|
homey: this.homey,
|
|
266
265
|
manager: this,
|
|
@@ -278,13 +277,12 @@ class Manager extends EventEmitter {
|
|
|
278
277
|
|
|
279
278
|
// Add all to cache
|
|
280
279
|
for (let item of Object.values(result)) {
|
|
281
|
-
item = Item.
|
|
280
|
+
item = Item.transformGet(item);
|
|
282
281
|
if (this.__cache[itemId][item.id]) {
|
|
283
|
-
this.__cache[itemId][item.id].__update(item);
|
|
284
282
|
items[item.id] = this.__cache[itemId][item.id];
|
|
283
|
+
items[item.id].__update(item);
|
|
285
284
|
} else {
|
|
286
285
|
items[item.id] = new Item({
|
|
287
|
-
itemId,
|
|
288
286
|
id: item.id,
|
|
289
287
|
homey: this.homey,
|
|
290
288
|
manager: this,
|
|
@@ -316,13 +314,14 @@ class Manager extends EventEmitter {
|
|
|
316
314
|
case 'createOne':
|
|
317
315
|
case 'updateOne': {
|
|
318
316
|
let item = { ...result };
|
|
319
|
-
item = Item.
|
|
317
|
+
item = Item.transformGet(item);
|
|
318
|
+
|
|
320
319
|
if (this.__cache[itemId][item.id]) {
|
|
321
|
-
item = this.__cache[itemId][item.id]
|
|
320
|
+
item = this.__cache[itemId][item.id];
|
|
321
|
+
item.__update(item);
|
|
322
322
|
} else {
|
|
323
|
-
item = Item.
|
|
323
|
+
item = Item.transformGet(item);
|
|
324
324
|
item = new Item({
|
|
325
|
-
itemId,
|
|
326
325
|
id: item.id,
|
|
327
326
|
homey: this.homey,
|
|
328
327
|
manager: this,
|
|
@@ -413,55 +412,38 @@ class Manager extends EventEmitter {
|
|
|
413
412
|
|
|
414
413
|
switch (operation) {
|
|
415
414
|
case 'create': {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
item = new Item({
|
|
419
|
-
|
|
420
|
-
id: item.id,
|
|
415
|
+
data = Item.transformGet(data);
|
|
416
|
+
|
|
417
|
+
const item = new Item({
|
|
418
|
+
id: data.id,
|
|
421
419
|
homey: this.homey,
|
|
422
420
|
manager: this,
|
|
423
|
-
properties: { ...
|
|
421
|
+
properties: { ...data },
|
|
424
422
|
});
|
|
423
|
+
this.__cache[itemId][data.id] = item;
|
|
425
424
|
|
|
426
|
-
|
|
427
|
-
this.__cache[itemId][item.id].emit('create');
|
|
428
|
-
|
|
429
|
-
return this.emit(`${itemId}.create`, item);
|
|
425
|
+
break;
|
|
430
426
|
}
|
|
431
427
|
case 'update': {
|
|
432
|
-
|
|
433
|
-
item = Item.transform(item);
|
|
428
|
+
data = Item.transformGet(data);
|
|
434
429
|
|
|
435
|
-
if (this.__cache[itemId][
|
|
436
|
-
item = this.__cache[itemId][
|
|
437
|
-
item.__update(
|
|
438
|
-
item.emit('update');
|
|
439
|
-
} else {
|
|
440
|
-
item = new Item({
|
|
441
|
-
itemId,
|
|
442
|
-
id: item.id,
|
|
443
|
-
homey: this.homey,
|
|
444
|
-
manager: this,
|
|
445
|
-
properties: { ...item },
|
|
446
|
-
});
|
|
447
|
-
this.__cache[itemId][item.id] = item;
|
|
430
|
+
if (this.__cache[itemId][data.id]) {
|
|
431
|
+
const item = this.__cache[itemId][data.id];
|
|
432
|
+
item.__update(data);
|
|
448
433
|
}
|
|
449
434
|
|
|
450
|
-
|
|
435
|
+
break;
|
|
451
436
|
}
|
|
452
437
|
case 'delete': {
|
|
453
|
-
|
|
454
|
-
item = Item.transform(item);
|
|
438
|
+
data = Item.transformGet(data);
|
|
455
439
|
|
|
456
|
-
if (this.__cache[itemId][
|
|
457
|
-
this.__cache[itemId][
|
|
458
|
-
|
|
440
|
+
if (this.__cache[itemId][data.id]) {
|
|
441
|
+
const item = this.__cache[itemId][data.id];
|
|
442
|
+
item.__delete();
|
|
459
443
|
delete this.__cache[itemId][item.id];
|
|
460
444
|
}
|
|
461
445
|
|
|
462
|
-
|
|
463
|
-
id: item.id,
|
|
464
|
-
});
|
|
446
|
+
break;
|
|
465
447
|
}
|
|
466
448
|
default:
|
|
467
449
|
break;
|
|
@@ -17,17 +17,13 @@ class Device extends Item {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
get uri() {
|
|
21
|
-
return `homey:device:${this.id}`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
20
|
/**
|
|
25
|
-
* Creates an {@link
|
|
21
|
+
* Creates an {@link HomeyAPIV3.DeviceCapability} for realtime capability updates.
|
|
26
22
|
* @param {string} capabilityId
|
|
27
23
|
* @param {Function} listener
|
|
28
24
|
* @param {number|boolean|string} listener.value
|
|
29
|
-
* @returns {
|
|
30
|
-
* @function
|
|
25
|
+
* @returns {HomeyAPIV3.ManagerDevices.Device.DeviceCapability}
|
|
26
|
+
* @function HomeyAPIV3.ManagerDevices.Device#makeCapabilityInstance
|
|
31
27
|
* @example
|
|
32
28
|
*
|
|
33
29
|
* const onOffInstance = device.makeCapabilityInstance('onoff', value => {
|
|
@@ -76,7 +72,7 @@ class Device extends Item {
|
|
|
76
72
|
* @param {object} [opts.opts]
|
|
77
73
|
* @param {number} [opts.opts.duration]
|
|
78
74
|
* @returns {Promise<void>}
|
|
79
|
-
* @function
|
|
75
|
+
* @function HomeyAPIV3.ManagerDevices.Device#setCapabilityValue
|
|
80
76
|
*/
|
|
81
77
|
async setCapabilityValue(options, ...args) {
|
|
82
78
|
// Legacy compatibility from node-athom-api
|
|
@@ -199,10 +195,14 @@ class Device extends Item {
|
|
|
199
195
|
}), {});
|
|
200
196
|
}
|
|
201
197
|
|
|
202
|
-
static
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
198
|
+
static transformGet(item) {
|
|
199
|
+
item = super.transformGet(item);
|
|
200
|
+
|
|
201
|
+
if (item.capabilitiesObj) {
|
|
202
|
+
for (const capabilityObj of Object.values(item.capabilitiesObj)) {
|
|
203
|
+
if (capabilityObj.lastUpdated) {
|
|
204
|
+
capabilityObj.lastUpdated = new Date(capabilityObj.lastUpdated);
|
|
205
|
+
}
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
|
|
@@ -108,7 +108,7 @@ class DeviceCapability extends EventEmitter {
|
|
|
108
108
|
const capabilityReference = this.device.capabilitiesObj && this.device.capabilitiesObj[this.id];
|
|
109
109
|
if (capabilityReference) {
|
|
110
110
|
capabilityReference.value = value;
|
|
111
|
-
capabilityReference.lastUpdated = this.__lastChanged
|
|
111
|
+
capabilityReference.lastUpdated = this.__lastChanged;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
this.__listener(value);
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
const Manager = require('./Manager');
|
|
4
4
|
const Driver = require('./ManagerDrivers/Driver');
|
|
5
|
+
const PairSession = require('./ManagerDrivers/PairSession');
|
|
5
6
|
|
|
6
7
|
class ManagerDrivers extends Manager {
|
|
7
8
|
|
|
8
9
|
static CRUD = {
|
|
9
10
|
...super.CRUD,
|
|
10
11
|
Driver,
|
|
12
|
+
PairSession,
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
}
|
|
@@ -4,6 +4,14 @@ const Item = require('../Item');
|
|
|
4
4
|
|
|
5
5
|
class Flow extends Item {
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Check whether this Flow misses one or more {@link FlowCard} or {@link FlowToken}.
|
|
9
|
+
* @returns Promise<Boolean>
|
|
10
|
+
*/
|
|
11
|
+
async isBroken() {
|
|
12
|
+
throw new Error('Not Implemented');
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
}
|
|
8
16
|
|
|
9
17
|
module.exports = Flow;
|
|
@@ -4,6 +4,14 @@ const Item = require('../Item');
|
|
|
4
4
|
|
|
5
5
|
class FlowCard extends Item {
|
|
6
6
|
|
|
7
|
+
static transformGet(item) {
|
|
8
|
+
item = super.transformGet(item);
|
|
9
|
+
|
|
10
|
+
delete item.ownerName; // Prepare for back-end change
|
|
11
|
+
|
|
12
|
+
return item;
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
}
|
|
8
16
|
|
|
9
17
|
module.exports = FlowCard;
|
|
@@ -5,10 +5,13 @@ const Item = require('../Item');
|
|
|
5
5
|
class FlowToken extends Item {
|
|
6
6
|
|
|
7
7
|
// TODO: Remove when back-end has removed these properties.
|
|
8
|
-
static
|
|
8
|
+
static transformGet(item) {
|
|
9
|
+
item = super.transformGet(item);
|
|
10
|
+
|
|
9
11
|
delete item.uri;
|
|
10
12
|
delete item.id;
|
|
11
13
|
delete item.uriObj;
|
|
14
|
+
delete item.ownerName; // Prepare for back-end change
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
}
|
|
@@ -4,6 +4,20 @@ const Item = require('../Item');
|
|
|
4
4
|
|
|
5
5
|
class Log extends Item {
|
|
6
6
|
|
|
7
|
+
async getEntries() {
|
|
8
|
+
return this.manager.getLogEntries({
|
|
9
|
+
id: this.id,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static transformGet(item) {
|
|
14
|
+
item = super.transformGet(item);
|
|
15
|
+
|
|
16
|
+
delete item.ownerName; // Prepare for back-end change
|
|
17
|
+
|
|
18
|
+
return item;
|
|
19
|
+
}
|
|
20
|
+
|
|
7
21
|
}
|
|
8
22
|
|
|
9
23
|
module.exports = Log;
|