homey-api 1.4.2 → 1.5.1
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/README.md +4 -0
- package/assets/specifications/AthomAppsAPI.json +45 -0
- package/assets/types/homey-api.d.ts +49 -0
- package/assets/types/homey-api.private.d.ts +111 -0
- package/index.js +1 -0
- package/lib/HomeyAPI/HomeyAPIApp.js +126 -0
- package/lib/HomeyAPI/HomeyAPIV2.js +29 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,6 +40,10 @@ Include Homey API from our CDN:
|
|
|
40
40
|
|
|
41
41
|
You can then access the APIs using `window.AthomCloudAPI` etc.
|
|
42
42
|
|
|
43
|
+
### In-app
|
|
44
|
+
|
|
45
|
+
To use Homey API inside of an Homey Pro app with the `homey:manager:api` permission, see {@link HomeyAPIApp}.
|
|
46
|
+
|
|
43
47
|
## Issues
|
|
44
48
|
|
|
45
49
|
Please report any issues you find in the [Web API Issue Tracker](https://github.com/athombv/homey-web-api-issues/issues).
|
|
@@ -82,6 +82,40 @@
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
|
+
"browseApps": {
|
|
86
|
+
"path": "/app/browse",
|
|
87
|
+
"method": "get",
|
|
88
|
+
"parameters": {
|
|
89
|
+
"query": {
|
|
90
|
+
"in": "query",
|
|
91
|
+
"type": "string"
|
|
92
|
+
},
|
|
93
|
+
"language": {
|
|
94
|
+
"in": "query",
|
|
95
|
+
"type": "string"
|
|
96
|
+
},
|
|
97
|
+
"platform": {
|
|
98
|
+
"in": "query",
|
|
99
|
+
"type": "array"
|
|
100
|
+
},
|
|
101
|
+
"connectivity": {
|
|
102
|
+
"in": "query",
|
|
103
|
+
"type": "array"
|
|
104
|
+
},
|
|
105
|
+
"category": {
|
|
106
|
+
"in": "query",
|
|
107
|
+
"type": "array"
|
|
108
|
+
},
|
|
109
|
+
"limit": {
|
|
110
|
+
"in": "query",
|
|
111
|
+
"type": "number"
|
|
112
|
+
},
|
|
113
|
+
"offset": {
|
|
114
|
+
"in": "query",
|
|
115
|
+
"type": "number"
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
85
119
|
"syncApps": {
|
|
86
120
|
"path": "/app/sync",
|
|
87
121
|
"method": "post",
|
|
@@ -140,6 +174,17 @@
|
|
|
140
174
|
}
|
|
141
175
|
}
|
|
142
176
|
},
|
|
177
|
+
"getAppChangelog": {
|
|
178
|
+
"path": "/app/{appId}/changelog",
|
|
179
|
+
"method": "get",
|
|
180
|
+
"parameters": {
|
|
181
|
+
"appId": {
|
|
182
|
+
"in": "path",
|
|
183
|
+
"type": "string",
|
|
184
|
+
"required": true
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
},
|
|
143
188
|
"updateAppAuthor": {
|
|
144
189
|
"path": "/app/{appId}/author",
|
|
145
190
|
"method": "put",
|
|
@@ -185,6 +185,53 @@
|
|
|
185
185
|
|
|
186
186
|
|
|
187
187
|
|
|
188
|
+
__(
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
input: {
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
en: string,
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
nl: string,
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
):
|
|
209
|
+
string | null;
|
|
210
|
+
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export class HomeyAPIApp extends HomeyAPIV2 {
|
|
214
|
+
|
|
215
|
+
constructor(
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
homey: Homey,
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
debug: boolean,
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
188
235
|
__(
|
|
189
236
|
|
|
190
237
|
|
|
@@ -603,6 +650,8 @@
|
|
|
603
650
|
|
|
604
651
|
|
|
605
652
|
|
|
653
|
+
|
|
654
|
+
|
|
606
655
|
|
|
607
656
|
|
|
608
657
|
|
|
@@ -197,6 +197,49 @@
|
|
|
197
197
|
|
|
198
198
|
|
|
199
199
|
|
|
200
|
+
):
|
|
201
|
+
Promise<any>;
|
|
202
|
+
|
|
203
|
+
browseApps(
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
opts: {
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
query: string,
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
language: string,
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
platform: Array<any>,
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
connectivity: Array<any>,
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
category: Array<any>,
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
limit: number,
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
offset: number,
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
200
243
|
):
|
|
201
244
|
Promise<any>;
|
|
202
245
|
|
|
@@ -277,6 +320,25 @@
|
|
|
277
320
|
|
|
278
321
|
|
|
279
322
|
|
|
323
|
+
opts: {
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
appId: string,
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
},
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
):
|
|
335
|
+
Promise<any>;
|
|
336
|
+
|
|
337
|
+
getAppChangelog(
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
280
342
|
opts: {
|
|
281
343
|
|
|
282
344
|
|
|
@@ -4905,6 +4967,53 @@
|
|
|
4905
4967
|
|
|
4906
4968
|
|
|
4907
4969
|
|
|
4970
|
+
__(
|
|
4971
|
+
|
|
4972
|
+
|
|
4973
|
+
|
|
4974
|
+
|
|
4975
|
+
input: {
|
|
4976
|
+
|
|
4977
|
+
|
|
4978
|
+
en: string,
|
|
4979
|
+
|
|
4980
|
+
|
|
4981
|
+
|
|
4982
|
+
nl: string,
|
|
4983
|
+
|
|
4984
|
+
|
|
4985
|
+
},
|
|
4986
|
+
|
|
4987
|
+
|
|
4988
|
+
|
|
4989
|
+
|
|
4990
|
+
):
|
|
4991
|
+
string | null;
|
|
4992
|
+
|
|
4993
|
+
}
|
|
4994
|
+
|
|
4995
|
+
export class HomeyAPIApp extends HomeyAPIV2 {
|
|
4996
|
+
|
|
4997
|
+
constructor(
|
|
4998
|
+
|
|
4999
|
+
|
|
5000
|
+
|
|
5001
|
+
|
|
5002
|
+
homey: Homey,
|
|
5003
|
+
|
|
5004
|
+
|
|
5005
|
+
|
|
5006
|
+
debug: boolean,
|
|
5007
|
+
|
|
5008
|
+
|
|
5009
|
+
|
|
5010
|
+
|
|
5011
|
+
)
|
|
5012
|
+
|
|
5013
|
+
|
|
5014
|
+
|
|
5015
|
+
|
|
5016
|
+
|
|
4908
5017
|
__(
|
|
4909
5018
|
|
|
4910
5019
|
|
|
@@ -5528,6 +5637,8 @@
|
|
|
5528
5637
|
|
|
5529
5638
|
|
|
5530
5639
|
|
|
5640
|
+
|
|
5641
|
+
|
|
5531
5642
|
|
|
5532
5643
|
|
|
5533
5644
|
|
package/index.js
CHANGED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const HomeyAPI = require('./HomeyAPI');
|
|
4
|
+
const HomeyAPIV2 = require('./HomeyAPIV2');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Use this class to utilize Homey Pro's Web API from inside an app.
|
|
8
|
+
*
|
|
9
|
+
* > This class only works on apps using Apps SDK v3 running on Homey Pro.
|
|
10
|
+
*
|
|
11
|
+
* > Make sure your app has the `homey:manager:api` permission.
|
|
12
|
+
*
|
|
13
|
+
* @class
|
|
14
|
+
* @extends HomeyAPIV2
|
|
15
|
+
* @example
|
|
16
|
+
* // app.json
|
|
17
|
+
* {
|
|
18
|
+
* ...
|
|
19
|
+
* "platforms": [ "local" ],
|
|
20
|
+
* "permissions": [ "homey:manager:api" ],
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* // app.js
|
|
24
|
+
* const Homey = require('homey');
|
|
25
|
+
* const { HomeyAPIApp } = require('homey-api');
|
|
26
|
+
*
|
|
27
|
+
* class MyApp extends Homey.App {
|
|
28
|
+
*
|
|
29
|
+
* async onInit() {
|
|
30
|
+
* const api = new HomeyAPIApp({
|
|
31
|
+
* homey: this.homey,
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* const devices = await api.devices.getDevices();
|
|
35
|
+
* this.log('Devices:', devices);
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
class HomeyAPIApp extends HomeyAPIV2 {
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Possible Discovery Strategies
|
|
44
|
+
* @static
|
|
45
|
+
* @property {object} DISCOVERY_STRATEGIES
|
|
46
|
+
* @property {string} DISCOVERY_STRATEGIES.LOCAL - Local HTTP, e.g. `http://192.168.1.100`.
|
|
47
|
+
*/
|
|
48
|
+
static DISCOVERY_STRATEGIES = {};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {Homey} homey - The Homey instance of your app, usually `this.homey`.
|
|
52
|
+
* @param {boolean} [debug=false] - Enable debug logs.
|
|
53
|
+
*/
|
|
54
|
+
constructor({
|
|
55
|
+
homey,
|
|
56
|
+
debug = false,
|
|
57
|
+
...props
|
|
58
|
+
}) {
|
|
59
|
+
super({
|
|
60
|
+
...props,
|
|
61
|
+
api: null,
|
|
62
|
+
properties: {
|
|
63
|
+
id: 'local',
|
|
64
|
+
softwareVersion: null,
|
|
65
|
+
},
|
|
66
|
+
strategy: [
|
|
67
|
+
HomeyAPI.DISCOVERY_STRATEGIES.LOCAL,
|
|
68
|
+
],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
Object.defineProperty(this, '__homeySDK', {
|
|
72
|
+
value: homey,
|
|
73
|
+
enumerable: false,
|
|
74
|
+
writable: true,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
Object.defineProperty(this, '__debugEnabled', {
|
|
78
|
+
value: !!debug,
|
|
79
|
+
enumerable: false,
|
|
80
|
+
writable: true,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
__debug(...props) {
|
|
85
|
+
if (!this.__debugEnabled) return;
|
|
86
|
+
this.__homeySDK.log('[homey-api]', `[${this.constructor.name}]`, ...props);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async login() {
|
|
90
|
+
if (!this.__loginPromise) {
|
|
91
|
+
this.__loginPromise = Promise.resolve().then(async () => {
|
|
92
|
+
const token = await this.__homeySDK.api.getOwnerApiToken();
|
|
93
|
+
this.__debug(`Local Token: ${token}`);
|
|
94
|
+
return token;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
this.__loginPromise
|
|
98
|
+
.then(token => {
|
|
99
|
+
this.__token = token;
|
|
100
|
+
})
|
|
101
|
+
.catch(err => {
|
|
102
|
+
this.__debug('Error Logging In:', err);
|
|
103
|
+
})
|
|
104
|
+
.finally(() => {
|
|
105
|
+
this.__loginPromise = null;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return this.__loginPromise;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async discoverBaseUrl() {
|
|
113
|
+
this.__baseUrl = await this.__homeySDK.api.getLocalUrl();
|
|
114
|
+
this.__strategyId = 'local';
|
|
115
|
+
|
|
116
|
+
this.__debug(`Local URL: ${this.__baseUrl}`);
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
baseUrl: this.__baseUrl,
|
|
120
|
+
strategyId: this.__strategyId,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
module.exports = HomeyAPIApp;
|
|
@@ -275,24 +275,30 @@ class HomeyAPIV2 extends HomeyAPI {
|
|
|
275
275
|
pings[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL_SECURE]
|
|
276
276
|
.then(result => resolve(result))
|
|
277
277
|
.catch(() => {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
278
|
+
const promises = [];
|
|
279
|
+
|
|
280
|
+
if (pings[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL]) {
|
|
281
|
+
promises.push(pings[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL]);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (pings[HomeyAPI.DISCOVERY_STRATEGIES.MDNS]) {
|
|
285
|
+
promises.push(pings[HomeyAPI.DISCOVERY_STRATEGIES.MDNS]);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// TODO: Move this to the catch handler to always fallback on cloud
|
|
289
|
+
// Now mdns or local will error first and cloud won't have a chance!!
|
|
290
|
+
if (pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]) {
|
|
291
|
+
promises.push(pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (!promises.length) {
|
|
295
|
+
throw new HomeyOfflineError();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return Promise.race(promises);
|
|
299
|
+
})
|
|
300
|
+
.then(result => resolve(result))
|
|
301
|
+
.catch(() => reject(new HomeyOfflineError()));
|
|
296
302
|
} else if (pings[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL]) {
|
|
297
303
|
pings[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL]
|
|
298
304
|
.then(result => resolve(result))
|
|
@@ -466,11 +472,11 @@ class HomeyAPIV2 extends HomeyAPI {
|
|
|
466
472
|
}
|
|
467
473
|
|
|
468
474
|
async subscribe(uri, {
|
|
469
|
-
onConnect = () => {},
|
|
470
|
-
onReconnect = () => {},
|
|
471
|
-
onReconnectError = () => {},
|
|
472
|
-
onDisconnect = () => {},
|
|
473
|
-
onEvent = () => {},
|
|
475
|
+
onConnect = () => { },
|
|
476
|
+
onReconnect = () => { },
|
|
477
|
+
onReconnectError = () => { },
|
|
478
|
+
onDisconnect = () => { },
|
|
479
|
+
onEvent = () => { },
|
|
474
480
|
}) {
|
|
475
481
|
this.__debug('subscribe', uri);
|
|
476
482
|
|