homey-api 3.0.0-rc.13 → 3.0.0-rc.14
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const AdvancedFlowV3 = require('../../HomeyAPIV3/ManagerFlow/
|
|
3
|
+
const AdvancedFlowV3 = require('../../HomeyAPIV3/ManagerFlow/AdvancedFlow');
|
|
4
4
|
|
|
5
5
|
class AdvancedFlow extends AdvancedFlowV3 {
|
|
6
6
|
|
|
@@ -11,6 +11,8 @@ class AdvancedFlow extends AdvancedFlowV3 {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
delete item.broken;
|
|
15
|
+
|
|
14
16
|
return item;
|
|
15
17
|
}
|
|
16
18
|
|
|
@@ -1,9 +1,128 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
2
|
+
|
|
1
3
|
'use strict';
|
|
2
4
|
|
|
3
5
|
const Item = require('../Item');
|
|
4
6
|
|
|
5
7
|
class AdvancedFlow extends Item {
|
|
6
8
|
|
|
9
|
+
async isBroken() {
|
|
10
|
+
const managerFlow = this.homey.flow;
|
|
11
|
+
if (!managerFlow.isConnected()) {
|
|
12
|
+
throw new Error('Flow.isBroken requires ManagerFlow to be connected.');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const managerFlowToken = this.homey.flowtoken;
|
|
16
|
+
if (!managerFlowToken.isConnected()) {
|
|
17
|
+
throw new Error('Flow.isBroken requires ManagerFlowToken to be connected.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Array of local & global Token IDs.
|
|
21
|
+
// For example [ 'foo', 'homey:x:y|abc' ]
|
|
22
|
+
const tokenIds = [];
|
|
23
|
+
|
|
24
|
+
const checkToken = async tokenId => {
|
|
25
|
+
// If this is a global Token, fetch all FlowTokens
|
|
26
|
+
if (tokenId.includes('|')) {
|
|
27
|
+
const flowTokens = await managerFlowToken.getFlowTokens(); // Fill the cache
|
|
28
|
+
for (const flowTokenId of Object.keys(flowTokens)) {
|
|
29
|
+
tokenIds.push(flowTokenId);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
tokenId = tokenId.replace('|', ':');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!tokenIds.includes(tokenId)) {
|
|
36
|
+
throw new Error(`Missing Token: ${tokenId}`);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const checkTokens = async card => {
|
|
41
|
+
// Check droptoken
|
|
42
|
+
if (card.droptoken) {
|
|
43
|
+
await checkToken(card.droptoken);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (typeof card.args === 'object') {
|
|
47
|
+
for (const arg of Object.values(card.args)) {
|
|
48
|
+
if (typeof arg !== 'string') continue;
|
|
49
|
+
for (const [tokenMatch, tokenId] of arg.matchAll(/\[\[(.*?)\]\]/g)) {
|
|
50
|
+
await checkToken(tokenId);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Check if FlowCards exist, and add Tokens
|
|
57
|
+
for (const [cardId, card] of Object.entries(this.cards)) {
|
|
58
|
+
switch (card.type) {
|
|
59
|
+
case 'trigger': {
|
|
60
|
+
try {
|
|
61
|
+
await managerFlow.getFlowCardTriggers(); // Fill the cache
|
|
62
|
+
const triggerCard = await this.manager.getFlowCardTrigger({ id: card.id });
|
|
63
|
+
|
|
64
|
+
// Add FlowCardTrigger.tokens to internal tokens cache
|
|
65
|
+
if (Array.isArray(triggerCard.tokens)) {
|
|
66
|
+
for (const token of Object.values(triggerCard.tokens)) {
|
|
67
|
+
tokenIds.push(`trigger::${cardId}::${token.id}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
break;
|
|
72
|
+
} catch (err) {
|
|
73
|
+
this.__debug(err);
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
case 'condition': {
|
|
78
|
+
try {
|
|
79
|
+
await managerFlow.getFlowCardConditions(); // Fill the cache
|
|
80
|
+
const conditionCard = await this.manager.getFlowCardCondition({ id: card.id });
|
|
81
|
+
|
|
82
|
+
// Add Error Token
|
|
83
|
+
tokenIds.push(`card::${cardId}::error`);
|
|
84
|
+
|
|
85
|
+
break;
|
|
86
|
+
} catch (err) {
|
|
87
|
+
this.__debug(err);
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
case 'action': {
|
|
92
|
+
try {
|
|
93
|
+
await managerFlow.getFlowCardActions(); // Fill the cache
|
|
94
|
+
const actionCard = await this.manager.getFlowCardAction({ id: card.id });
|
|
95
|
+
|
|
96
|
+
// Add Error Token
|
|
97
|
+
tokenIds.push(`card::${cardId}::error`);
|
|
98
|
+
|
|
99
|
+
// Add FlowCardAction.tokens to internal tokens cache
|
|
100
|
+
if (Array.isArray(actionCard.tokens)) {
|
|
101
|
+
for (const token of Object.values(actionCard.tokens)) {
|
|
102
|
+
tokenIds.push(`action::${cardId}::${token.id}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
break;
|
|
107
|
+
} catch (err) {
|
|
108
|
+
this.__debug(err);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
default: {
|
|
113
|
+
// Do nothing
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Check Tokens
|
|
119
|
+
for (const card of Object.values(this.cards)) {
|
|
120
|
+
await checkTokens(card);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
7
126
|
}
|
|
8
127
|
|
|
9
128
|
module.exports = AdvancedFlow;
|