homey-api 3.0.0-rc.13 → 3.0.0-rc.15
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/types/homey-api.d.ts +27 -0
- package/assets/types/homey-api.private.d.ts +27 -0
- package/index.js +19 -20
- package/lib/HomeyAPI/HomeyAPI.js +52 -3
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow/AdvancedFlow.js +3 -1
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/AdvancedFlow.js +119 -0
- package/package.json +1 -1
|
@@ -287,6 +287,33 @@
|
|
|
287
287
|
|
|
288
288
|
|
|
289
289
|
|
|
290
|
+
):
|
|
291
|
+
Promise<any>;
|
|
292
|
+
|
|
293
|
+
createLocalAPI(
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
opts: {
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
address: String,
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
token: String,
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
debug: function | null,
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
},
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
290
317
|
):
|
|
291
318
|
Promise<any>;
|
|
292
319
|
|
|
@@ -5402,6 +5402,33 @@
|
|
|
5402
5402
|
|
|
5403
5403
|
|
|
5404
5404
|
|
|
5405
|
+
):
|
|
5406
|
+
Promise<any>;
|
|
5407
|
+
|
|
5408
|
+
createLocalAPI(
|
|
5409
|
+
|
|
5410
|
+
|
|
5411
|
+
|
|
5412
|
+
|
|
5413
|
+
opts: {
|
|
5414
|
+
|
|
5415
|
+
|
|
5416
|
+
address: String,
|
|
5417
|
+
|
|
5418
|
+
|
|
5419
|
+
|
|
5420
|
+
token: String,
|
|
5421
|
+
|
|
5422
|
+
|
|
5423
|
+
|
|
5424
|
+
debug: function | null,
|
|
5425
|
+
|
|
5426
|
+
|
|
5427
|
+
},
|
|
5428
|
+
|
|
5429
|
+
|
|
5430
|
+
|
|
5431
|
+
|
|
5405
5432
|
):
|
|
5406
5433
|
Promise<any>;
|
|
5407
5434
|
|
package/index.js
CHANGED
|
@@ -2,23 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
module.exports = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
5
|
+
module.exports = {};
|
|
6
|
+
module.exports.AthomAppsAPI = require('./lib/AthomAppsAPI');
|
|
7
|
+
module.exports.AthomBackupAPI = require('./lib/AthomBackupAPI');
|
|
8
|
+
module.exports.AthomCallbackAPI = require('./lib/AthomCallbackAPI');
|
|
9
|
+
module.exports.AthomCloudAPI = require('./lib/AthomCloudAPI');
|
|
10
|
+
module.exports.AthomConnectAPI = require('./lib/AthomConnectAPI');
|
|
11
|
+
module.exports.AthomDNSAPI = require('./lib/AthomDNSAPI');
|
|
12
|
+
module.exports.AthomFirmwareAPI = require('./lib/AthomFirmwareAPI');
|
|
13
|
+
module.exports.AthomFlowAPI = require('./lib/AthomFlowAPI');
|
|
14
|
+
module.exports.AthomGeolocateAPI = require('./lib/AthomGeolocateAPI');
|
|
15
|
+
module.exports.AthomIconsAPI = require('./lib/AthomIconsAPI');
|
|
16
|
+
module.exports.AthomInfraredAPI = require('./lib/AthomInfraredAPI');
|
|
17
|
+
module.exports.AthomNotificationsAPI = require('./lib/AthomNotificationsAPI');
|
|
18
|
+
module.exports.AthomSetupAPI = require('./lib/AthomSetupAPI');
|
|
19
|
+
module.exports.AthomStoreAPI = require('./lib/AthomStoreAPI');
|
|
20
|
+
module.exports.AthomWeatherAPI = require('./lib/AthomWeatherAPI');
|
|
21
|
+
module.exports.AthomWebhooksAPI = require('./lib/AthomWebhooksAPI');
|
|
22
|
+
module.exports.HomeyCloudAPI = require('./lib/HomeyCloudAPI');
|
|
23
|
+
module.exports.HomeyAPI = require('./lib/HomeyAPI/HomeyAPI');
|
package/lib/HomeyAPI/HomeyAPI.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const Util = require('../Util');
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* A Homey API, to be extended.
|
|
5
7
|
* @hideconstructor
|
|
@@ -126,10 +128,10 @@ class HomeyAPI {
|
|
|
126
128
|
}
|
|
127
129
|
|
|
128
130
|
/**
|
|
129
|
-
*
|
|
131
|
+
* Creates a {@link HomeyAPIV3Local} or {@link HomeyAPIV2} instance for use in the Apps SDK.
|
|
130
132
|
* @param {Object} opts
|
|
131
|
-
* @param {Homey} opts.homey — Homey instance
|
|
132
|
-
* @param {Function|null} opts.debug — Debug function, defaults to `null
|
|
133
|
+
* @param {Homey} opts.homey — Homey (Apps SDK) instance.
|
|
134
|
+
* @param {Function|null} opts.debug — Debug function, defaults to `null`.
|
|
133
135
|
*/
|
|
134
136
|
static async createAppAPI({
|
|
135
137
|
homey,
|
|
@@ -172,6 +174,53 @@ class HomeyAPI {
|
|
|
172
174
|
throw new Error(`Invalid Homey Platform Version: ${homey.platformVersion}`);
|
|
173
175
|
}
|
|
174
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Creates a {@link HomeyAPIV3Local} instance for use in a project.
|
|
179
|
+
* @param {Object} opts
|
|
180
|
+
* @param {String} opts.address — The address of the Homey, e.g. `http://192.168.1.123:80`.
|
|
181
|
+
* @param {String} opts.token — A Personal Access Token created in the Homey Web App.
|
|
182
|
+
* @param {Function|null} opts.debug — Debug function, defaults to `null`.
|
|
183
|
+
* @example
|
|
184
|
+
* import { HomeyAPI } from 'homey-api';
|
|
185
|
+
* const homeyApi = await HomeyAPI.createLocalAPI({
|
|
186
|
+
* address: 'http://192.169.1.123',
|
|
187
|
+
* token: '<my_personal_access_token>',
|
|
188
|
+
* });
|
|
189
|
+
* const devices = await homeyApi.devices.getDevices();
|
|
190
|
+
*/
|
|
191
|
+
static async createLocalAPI({
|
|
192
|
+
address,
|
|
193
|
+
token,
|
|
194
|
+
debug = null,
|
|
195
|
+
}) {
|
|
196
|
+
if (!address) {
|
|
197
|
+
throw new Error('Invalid Address');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (!token) {
|
|
201
|
+
throw new Error('Invalid Token');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const res = await Util.fetch(`${address}/api/manager/system/ping`);
|
|
205
|
+
if (!res.headers.has('X-Homey-ID')) {
|
|
206
|
+
throw new Error(`No Homey Found At Address: ${address}`);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const props = {
|
|
210
|
+
token,
|
|
211
|
+
debug: debug ?? function debug() { },
|
|
212
|
+
baseUrl: address,
|
|
213
|
+
strategy: [],
|
|
214
|
+
properties: {
|
|
215
|
+
id: res.headers.get('X-Homey-ID'),
|
|
216
|
+
softwareVersion: res.headers.get('X-Homey-Version'),
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const HomeyAPIV3Local = require('./HomeyAPIV3Local');
|
|
221
|
+
return new HomeyAPIV3Local(props);
|
|
222
|
+
}
|
|
223
|
+
|
|
175
224
|
}
|
|
176
225
|
|
|
177
226
|
module.exports = HomeyAPI;
|
|
@@ -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;
|