homey-api 1.4.4 → 1.5.3

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 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",
@@ -108,11 +142,34 @@
108
142
  }
109
143
  }
110
144
  },
145
+ "getHighlightedAppsV2": {
146
+ "path": "/app/highlight2",
147
+ "method": "get",
148
+ "parameters": {
149
+ "platform": {
150
+ "in": "query",
151
+ "type": "array"
152
+ },
153
+ "language": {
154
+ "in": "query",
155
+ "type": "string"
156
+ },
157
+ "tags": {
158
+ "in": "query",
159
+ "type": "array"
160
+ }
161
+ }
162
+ },
111
163
  "getMyApps": {
112
164
  "path": "/app/me",
113
165
  "method": "get",
114
166
  "parameters": {}
115
167
  },
168
+ "getAllLiveAppIDs": {
169
+ "path": "/app/ids",
170
+ "method": "get",
171
+ "parameters": {}
172
+ },
116
173
  "getReviewApps": {
117
174
  "path": "/app/review",
118
175
  "method": "get",
@@ -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
 
@@ -240,11 +283,43 @@
240
283
 
241
284
 
242
285
 
286
+ ):
287
+ Promise<any>;
288
+
289
+ getHighlightedAppsV2(
290
+
291
+
292
+
293
+
294
+ opts: {
295
+
296
+
297
+ platform: Array<any>,
298
+
299
+
300
+
301
+ language: string,
302
+
303
+
304
+
305
+ tags: Array<any>,
306
+
307
+
308
+ },
309
+
310
+
311
+
312
+
243
313
  ):
244
314
  Promise<any>;
245
315
 
246
316
  getMyApps(
247
317
 
318
+ ):
319
+ Promise<any>;
320
+
321
+ getAllLiveAppIDs(
322
+
248
323
  ):
249
324
  Promise<any>;
250
325
 
@@ -277,6 +352,25 @@
277
352
 
278
353
 
279
354
 
355
+ opts: {
356
+
357
+
358
+ appId: string,
359
+
360
+
361
+ },
362
+
363
+
364
+
365
+
366
+ ):
367
+ Promise<any>;
368
+
369
+ getAppChangelog(
370
+
371
+
372
+
373
+
280
374
  opts: {
281
375
 
282
376
 
@@ -4905,6 +4999,53 @@
4905
4999
 
4906
5000
 
4907
5001
 
5002
+ __(
5003
+
5004
+
5005
+
5006
+
5007
+ input: {
5008
+
5009
+
5010
+ en: string,
5011
+
5012
+
5013
+
5014
+ nl: string,
5015
+
5016
+
5017
+ },
5018
+
5019
+
5020
+
5021
+
5022
+ ):
5023
+ string | null;
5024
+
5025
+ }
5026
+
5027
+ export class HomeyAPIApp extends HomeyAPIV2 {
5028
+
5029
+ constructor(
5030
+
5031
+
5032
+
5033
+
5034
+ homey: Homey,
5035
+
5036
+
5037
+
5038
+ debug: boolean,
5039
+
5040
+
5041
+
5042
+
5043
+ )
5044
+
5045
+
5046
+
5047
+
5048
+
4908
5049
  __(
4909
5050
 
4910
5051
 
@@ -5528,6 +5669,8 @@
5528
5669
 
5529
5670
 
5530
5671
 
5672
+
5673
+
5531
5674
 
5532
5675
 
5533
5676
 
package/index.js CHANGED
@@ -21,4 +21,5 @@ module.exports = {
21
21
  AthomWeatherAPI: require('./lib/AthomWeatherAPI'),
22
22
  AthomWebhooksAPI: require('./lib/AthomWebhooksAPI'),
23
23
  HomeyCloudAPI: require('./lib/HomeyCloudAPI'),
24
+ HomeyAPIApp: require('./lib/HomeyAPI/HomeyAPIApp'),
24
25
  };
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "1.4.4",
3
+ "version": "1.5.3",
4
4
  "description": "Homey API",
5
5
  "main": "src/index.js",
6
6
  "types": "assets/types/homey-api.d.ts",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "core-js": "^3.19.1",
42
- "node-fetch": "^2.6.6",
42
+ "node-fetch": "^2.6.7",
43
43
  "regenerator-runtime": "^0.13.9",
44
44
  "socket.io-client": "^1.7.4"
45
45
  },