homey-api 3.0.0-rc.14 → 3.0.0-rc.16

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.
@@ -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
- AthomAppsAPI: require('./lib/AthomAppsAPI'),
7
- AthomBackupAPI: require('./lib/AthomBackupAPI'),
8
- AthomCallbackAPI: require('./lib/AthomCallbackAPI'),
9
- AthomCloudAPI: require('./lib/AthomCloudAPI'),
10
- AthomConnectAPI: require('./lib/AthomConnectAPI'),
11
- AthomDNSAPI: require('./lib/AthomDNSAPI'),
12
- AthomFirmwareAPI: require('./lib/AthomFirmwareAPI'),
13
- AthomFlowAPI: require('./lib/AthomFlowAPI'),
14
- AthomGeolocateAPI: require('./lib/AthomGeolocateAPI'),
15
- AthomIconsAPI: require('./lib/AthomIconsAPI'),
16
- AthomInfraredAPI: require('./lib/AthomInfraredAPI'),
17
- AthomNotificationsAPI: require('./lib/AthomNotificationsAPI'),
18
- AthomSetupAPI: require('./lib/AthomSetupAPI'),
19
- AthomStoreAPI: require('./lib/AthomStoreAPI'),
20
- AthomWeatherAPI: require('./lib/AthomWeatherAPI'),
21
- AthomWebhooksAPI: require('./lib/AthomWebhooksAPI'),
22
- HomeyCloudAPI: require('./lib/HomeyCloudAPI'),
23
- HomeyAPI: require('./lib/HomeyAPI/HomeyAPI'),
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');
@@ -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
- * Create a {@link HomeyAPIV3Local} instance for use in the Apps SDK.
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;
@@ -424,7 +424,7 @@ class Manager extends EventEmitter {
424
424
  });
425
425
  this.__cache[itemId][data.id] = item;
426
426
 
427
- break;
427
+ return this.emit(event, item);
428
428
  }
429
429
  case 'update': {
430
430
  data = Item.transformGet(data);
@@ -432,6 +432,7 @@ class Manager extends EventEmitter {
432
432
  if (this.__cache[itemId][data.id]) {
433
433
  const item = this.__cache[itemId][data.id];
434
434
  item.__update(data);
435
+ return this.emit(event, item);
435
436
  }
436
437
 
437
438
  break;
@@ -443,6 +444,9 @@ class Manager extends EventEmitter {
443
444
  const item = this.__cache[itemId][data.id];
444
445
  item.__delete();
445
446
  delete this.__cache[itemId][item.id];
447
+ return this.emit(event, {
448
+ id: item.id,
449
+ });
446
450
  }
447
451
 
448
452
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "3.0.0-rc.14",
3
+ "version": "3.0.0-rc.16",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "files": [