homey-api 1.4.3 → 1.5.2

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,6 +142,24 @@
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",
@@ -140,6 +192,17 @@
140
192
  }
141
193
  }
142
194
  },
195
+ "getAppChangelog": {
196
+ "path": "/app/{appId}/changelog",
197
+ "method": "get",
198
+ "parameters": {
199
+ "appId": {
200
+ "in": "path",
201
+ "type": "string",
202
+ "required": true
203
+ }
204
+ }
205
+ },
143
206
  "updateAppAuthor": {
144
207
  "path": "/app/{appId}/author",
145
208
  "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
 
@@ -240,6 +283,33 @@
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
 
@@ -277,6 +347,25 @@
277
347
 
278
348
 
279
349
 
350
+ opts: {
351
+
352
+
353
+ appId: string,
354
+
355
+
356
+ },
357
+
358
+
359
+
360
+
361
+ ):
362
+ Promise<any>;
363
+
364
+ getAppChangelog(
365
+
366
+
367
+
368
+
280
369
  opts: {
281
370
 
282
371
 
@@ -4905,6 +4994,53 @@
4905
4994
 
4906
4995
 
4907
4996
 
4997
+ __(
4998
+
4999
+
5000
+
5001
+
5002
+ input: {
5003
+
5004
+
5005
+ en: string,
5006
+
5007
+
5008
+
5009
+ nl: string,
5010
+
5011
+
5012
+ },
5013
+
5014
+
5015
+
5016
+
5017
+ ):
5018
+ string | null;
5019
+
5020
+ }
5021
+
5022
+ export class HomeyAPIApp extends HomeyAPIV2 {
5023
+
5024
+ constructor(
5025
+
5026
+
5027
+
5028
+
5029
+ homey: Homey,
5030
+
5031
+
5032
+
5033
+ debug: boolean,
5034
+
5035
+
5036
+
5037
+
5038
+ )
5039
+
5040
+
5041
+
5042
+
5043
+
4908
5044
  __(
4909
5045
 
4910
5046
 
@@ -5528,6 +5664,8 @@
5528
5664
 
5529
5665
 
5530
5666
 
5667
+
5668
+
5531
5669
 
5532
5670
 
5533
5671
 
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;
@@ -285,6 +285,8 @@ class HomeyAPIV2 extends HomeyAPI {
285
285
  promises.push(pings[HomeyAPI.DISCOVERY_STRATEGIES.MDNS]);
286
286
  }
287
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!!
288
290
  if (pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]) {
289
291
  promises.push(pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]);
290
292
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "1.4.3",
3
+ "version": "1.5.2",
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
  },