homey-api 3.0.1 → 3.0.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.
Files changed (28) hide show
  1. package/assets/specifications/HomeyAPIV3Local.json +0 -22
  2. package/assets/types/homey-api.d.ts +222 -300
  3. package/assets/types/homey-api.private.d.ts +222 -300
  4. package/lib/HomeyAPI/HomeyAPIV2/Manager.js +1 -0
  5. package/lib/HomeyAPI/HomeyAPIV2/ManagerDevices.js +2 -2
  6. package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow.js +2 -2
  7. package/lib/HomeyAPI/HomeyAPIV3/Item.js +43 -4
  8. package/lib/HomeyAPI/HomeyAPIV3/Manager.js +19 -3
  9. package/lib/HomeyAPI/HomeyAPIV3/ManagerApps/App.js +14 -4
  10. package/lib/HomeyAPI/HomeyAPIV3/ManagerDevices/Capability.js +6 -0
  11. package/lib/HomeyAPI/HomeyAPIV3/ManagerDevices/Device.js +26 -0
  12. package/lib/HomeyAPI/HomeyAPIV3/ManagerDevices/DeviceCapability.js +1 -0
  13. package/lib/HomeyAPI/HomeyAPIV3/ManagerDrivers/Driver.js +6 -1
  14. package/lib/HomeyAPI/HomeyAPIV3/ManagerDrivers/PairSession.js +6 -1
  15. package/lib/HomeyAPI/HomeyAPIV3/ManagerDrivers.js +6 -0
  16. package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/AdvancedFlow.js +10 -0
  17. package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/Flow.js +7 -1
  18. package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/FlowCard.js +6 -0
  19. package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/FlowCardAction.js +6 -0
  20. package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/FlowCardCondition.js +6 -0
  21. package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/FlowCardTrigger.js +6 -0
  22. package/lib/HomeyAPI/HomeyAPIV3/ManagerFlowToken/FlowToken.js +6 -0
  23. package/lib/HomeyAPI/HomeyAPIV3/ManagerInsights/Log.js +6 -0
  24. package/lib/HomeyAPI/HomeyAPIV3.js +7 -3
  25. package/lib/HomeyAPI/HomeyAPIV3Cloud/Item.js +6 -0
  26. package/lib/HomeyAPI/HomeyAPIV3Local/Item.js +6 -0
  27. package/lib/HomeyAPI/HomeyAPIV3Local/ManagerDevkit.js +11 -1
  28. package/package.json +1 -1
@@ -7,6 +7,7 @@ const HomeyAPIV3Manager = require('../HomeyAPIV3/Manager');
7
7
  /**
8
8
  * @class
9
9
  * @hideconstructor
10
+ * @extends HomeyAPIV3.Manager
10
11
  * @memberof HomeyAPIV2
11
12
  */
12
13
  class Manager extends HomeyAPIV3Manager {
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const Manager = require('./Manager');
3
+ const ManagerDevicesV3 = require('../HomeyAPIV3/ManagerDevices');
4
4
  const Capability = require('./ManagerDevices/Capability');
5
5
  const Device = require('./ManagerDevices/Device');
6
6
 
7
- class ManagerDevices extends Manager {
7
+ class ManagerDevices extends ManagerDevicesV3 {
8
8
 
9
9
  static CRUD = {
10
10
  ...super.CRUD,
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- const Manager = require('./Manager');
3
+ const ManagerFlowV3 = require('../HomeyAPIV3/ManagerFlow');
4
4
  const Flow = require('./ManagerFlow/Flow');
5
5
  const AdvancedFlow = require('./ManagerFlow/AdvancedFlow');
6
6
  const FlowCardTrigger = require('./ManagerFlow/FlowCardTrigger');
7
7
  const FlowCardCondition = require('./ManagerFlow/FlowCardCondition');
8
8
  const FlowCardAction = require('./ManagerFlow/FlowCardAction');
9
9
 
10
- class ManagerFlow extends Manager {
10
+ class ManagerFlow extends ManagerFlowV3 {
11
11
 
12
12
  static CRUD = {
13
13
  ...super.CRUD,
@@ -2,6 +2,12 @@
2
2
 
3
3
  const EventEmitter = require('../../EventEmitter');
4
4
 
5
+ /**
6
+ * A superclass for all CRUD Items.
7
+ * @class
8
+ * @hideconstructor
9
+ * @memberof HomeyAPIV3
10
+ */
5
11
  class Item extends EventEmitter {
6
12
 
7
13
  static ID = null; // Set by Manager.js
@@ -14,22 +20,21 @@ class Item extends EventEmitter {
14
20
  }) {
15
21
  super();
16
22
 
17
- // Set ID
18
- Object.defineProperty(this, 'id', {
23
+ Object.defineProperty(this, '__id', {
19
24
  value: id,
20
25
  enumerable: true,
21
26
  writable: false,
22
27
  });
23
28
 
24
29
  // Set Homey
25
- Object.defineProperty(this, 'homey', {
30
+ Object.defineProperty(this, '__homey', {
26
31
  value: homey,
27
32
  enumerable: false,
28
33
  writable: false,
29
34
  });
30
35
 
31
36
  // Set Manager
32
- Object.defineProperty(this, 'manager', {
37
+ Object.defineProperty(this, '__manager', {
33
38
  value: manager,
34
39
  enumerable: false,
35
40
  writable: false,
@@ -54,10 +59,38 @@ class Item extends EventEmitter {
54
59
  }
55
60
  }
56
61
 
62
+ /**
63
+ * The ID of the Item.
64
+ * @type {String}
65
+ */
66
+ get id() {
67
+ return this.__id;
68
+ }
69
+
70
+ /**
71
+ * The URI of the Item, e.g. `homey:foo:bar`.
72
+ * @type {String}
73
+ */
57
74
  get uri() {
58
75
  return `homey:${this.constructor.ID}:${this.id}`;
59
76
  }
60
77
 
78
+ /**
79
+ * The Manager of the Item.
80
+ * @type {HomeyAPIV3.Manager}
81
+ */
82
+ get manager() {
83
+ return this.__manager;
84
+ }
85
+
86
+ /**
87
+ * The Homey of the Item.
88
+ * @type {HomeyAPIV3}
89
+ */
90
+ get homey() {
91
+ return this.__homey;
92
+ }
93
+
61
94
  __debug(...props) {
62
95
  this.manager.__debug(`[${this.constructor.name}:${this.id}]`, ...props);
63
96
  }
@@ -77,6 +110,9 @@ class Item extends EventEmitter {
77
110
  this.emit('delete');
78
111
  }
79
112
 
113
+ /**
114
+ * Connect to this item's Socket.io namespace.
115
+ */
80
116
  async connect() {
81
117
  this.__debug('connect');
82
118
 
@@ -130,6 +166,9 @@ class Item extends EventEmitter {
130
166
  await this.__connectPromise;
131
167
  }
132
168
 
169
+ /**
170
+ * Discconnect from this item's Socket.io namespace.
171
+ */
133
172
  async disconnect() {
134
173
  this.__debug('disconnect');
135
174
 
@@ -12,6 +12,7 @@ const Item = require('./Item');
12
12
  /**
13
13
  * @class
14
14
  * @hideconstructor
15
+ * @extends EventEmitter
15
16
  * @memberof HomeyAPIV3
16
17
  */
17
18
  class Manager extends EventEmitter {
@@ -27,7 +28,7 @@ class Manager extends EventEmitter {
27
28
  super();
28
29
 
29
30
  // Set Homey
30
- Object.defineProperty(this, 'homey', {
31
+ Object.defineProperty(this, '__homey', {
31
32
  value: homey,
32
33
  enumerable: false,
33
34
  writable: false,
@@ -357,6 +358,18 @@ class Manager extends EventEmitter {
357
358
  }
358
359
  }
359
360
 
361
+ /**
362
+ * The Homey of the Manager.
363
+ * @type {HomeyAPIV3}
364
+ */
365
+ get homey() {
366
+ return this.__homey;
367
+ }
368
+
369
+ /**
370
+ * The URI of the Item, e.g. `homey:manager:bar`.
371
+ * @type {String}
372
+ */
360
373
  get uri() {
361
374
  return `homey:manager:${this.constructor.ID}`;
362
375
  }
@@ -374,7 +387,7 @@ class Manager extends EventEmitter {
374
387
  }
375
388
 
376
389
  /**
377
- * Connect to the realtime namespace.
390
+ * Connect to this manager's Socket.io namespace.
378
391
  * @returns {Promise<void>}
379
392
  */
380
393
  async connect() {
@@ -476,7 +489,7 @@ class Manager extends EventEmitter {
476
489
  }
477
490
 
478
491
  /**
479
- * Disconnect from the realtime namespace.
492
+ * Discconnect from this manager's Socket.io namespace.
480
493
  * @returns {Promise<void>}
481
494
  */
482
495
  async disconnect() {
@@ -509,6 +522,9 @@ class Manager extends EventEmitter {
509
522
  await this.__disconnectPromise;
510
523
  }
511
524
 
525
+ /**
526
+ * Destroy this Manager by cleaning up all references, unbinding event listeners and disconnecting from the Socket.io namespace.
527
+ */
512
528
  destroy() {
513
529
  // Clear cache
514
530
  for (const id of Object.keys(this.__cache)) {
@@ -2,8 +2,22 @@
2
2
 
3
3
  const Item = require('../Item');
4
4
 
5
+ /**
6
+ * @class
7
+ * @hideconstructor
8
+ * @extends HomeyAPIV3.Item
9
+ * @memberof HomeyAPIV3.ManagerApps
10
+ */
5
11
  class App extends Item {
6
12
 
13
+ /**
14
+ * Call the app's API endpoint.
15
+ * @param {Object} opts
16
+ * @param {('GET'|'POST'|'PUT'|'DELETE')} opts.method HTTP Method of the API endpoint.
17
+ * @param {String} opts.path - Path to the API endpoint.
18
+ * @param {mixed} opts.body
19
+ * @returns {Promise<any>}
20
+ */
7
21
  async call({
8
22
  method,
9
23
  path,
@@ -35,7 +49,6 @@ class App extends Item {
35
49
  * @param {object} opts
36
50
  * @param {string} opts.path
37
51
  * @returns {Promise<any>}
38
- * @function HomeyAPIV2.ManagerApps.App#get
39
52
  */
40
53
  async get({ path }) {
41
54
  return this.call({
@@ -50,7 +63,6 @@ class App extends Item {
50
63
  * @param {string} opts.path
51
64
  * @param {object} opts.body
52
65
  * @returns {Promise<any>}
53
- * @function HomeyAPIV2.ManagerApps.App#post
54
66
  */
55
67
  async post({ path, body }) {
56
68
  return this.call({
@@ -66,7 +78,6 @@ class App extends Item {
66
78
  * @param {string} opts.path
67
79
  * @param {object} opts.body
68
80
  * @returns {Promise<any>}
69
- * @function HomeyAPIV2.ManagerApps.App#put
70
81
  */
71
82
  async put({ path, body }) {
72
83
  return this.call({
@@ -81,7 +92,6 @@ class App extends Item {
81
92
  * @param {object} opts
82
93
  * @param {string} opts.path
83
94
  * @returns {Promise<any>}
84
- * @function HomeyAPIV2.ManagerApps.App#delete
85
95
  */
86
96
  async delete({ path }) {
87
97
  return this.call({
@@ -2,6 +2,12 @@
2
2
 
3
3
  const Item = require('../Item');
4
4
 
5
+ /**
6
+ * @class
7
+ * @hideconstructor
8
+ * @extends HomeyAPIV3.Item
9
+ * @memberof HomeyAPIV3.ManagerDevices
10
+ */
5
11
  class Capability extends Item {
6
12
 
7
13
  }
@@ -4,6 +4,12 @@ const Util = require('../../../Util');
4
4
  const Item = require('../Item');
5
5
  const DeviceCapability = require('./DeviceCapability');
6
6
 
7
+ /**
8
+ * @class
9
+ * @hideconstructor
10
+ * @extends HomeyAPIV3.Item
11
+ * @memberof HomeyAPIV3.ManagerDevices
12
+ */
7
13
  class Device extends Item {
8
14
 
9
15
  constructor(...props) {
@@ -134,18 +140,30 @@ class Device extends Item {
134
140
  }
135
141
  }
136
142
 
143
+ /**
144
+ * Get the device's zone.
145
+ * @returns {Promise<HomeyAPIV3.ManagerZones.Zone>}
146
+ */
137
147
  async getZone() {
138
148
  return this.homey.zones.getZone({
139
149
  id: this.zone,
140
150
  });
141
151
  }
142
152
 
153
+ /**
154
+ * Get the device's driver.
155
+ * @returns {Promise<HomeyAPIV3.ManagerDrivers.Driver>}
156
+ */
143
157
  async getDriver() {
144
158
  return this.homey.drivers.getDriver({
145
159
  id: this.driverId,
146
160
  });
147
161
  }
148
162
 
163
+ /**
164
+ * Get the device's logs.
165
+ * @returns {Promise<{String, HomeyAPIV3.ManagerInsights.Log}>}
166
+ */
149
167
  async getLogs() {
150
168
  const logs = await this.homey.insights.getLogs();
151
169
  return Object.values(logs)
@@ -156,6 +174,10 @@ class Device extends Item {
156
174
  }), {});
157
175
  }
158
176
 
177
+ /**
178
+ * Get the device's flows.
179
+ * @returns {Promise<{String, HomeyAPIV3.ManagerFlow.Flow}>}
180
+ */
159
181
  async getFlows() {
160
182
  const flows = await this.homey.flow.getFlows();
161
183
  return Object.values(flows)
@@ -175,6 +197,10 @@ class Device extends Item {
175
197
  }), {});
176
198
  }
177
199
 
200
+ /**
201
+ * @returns {Promise<{String, HomeyAPIV3.ManagerFlow.AdvancedFlow}>}
202
+ * @returns {Promise<Object>}
203
+ */
178
204
  async getAdvancedFlows() {
179
205
  const advancedFlows = await this.homey.flow.getAdvancedFlows();
180
206
  return Object.values(advancedFlows)
@@ -6,6 +6,7 @@ const EventEmitter = require('../../../EventEmitter');
6
6
  /**
7
7
  * @class
8
8
  * @hideconstructor
9
+ * @extends EventEmitter
9
10
  * @memberof HomeyAPIV3.ManagerDevices.Device
10
11
  */
11
12
  class DeviceCapability extends EventEmitter {
@@ -1,7 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  const Item = require('../Item');
4
-
4
+ /**
5
+ * @class
6
+ * @hideconstructor
7
+ * @extends HomeyAPIV3.Item
8
+ * @memberof HomeyAPIV3.ManagerDrivers
9
+ */
5
10
  class Driver extends Item {
6
11
 
7
12
  }
@@ -1,7 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  const Item = require('../Item');
4
-
4
+ /**
5
+ * @class
6
+ * @hideconstructor
7
+ * @extends HomeyAPIV3.Item
8
+ * @memberof HomeyAPIV3.ManagerDrivers
9
+ */
5
10
  class PairSession extends Item {
6
11
 
7
12
  }
@@ -4,6 +4,12 @@ const Manager = require('./Manager');
4
4
  const Driver = require('./ManagerDrivers/Driver');
5
5
  const PairSession = require('./ManagerDrivers/PairSession');
6
6
 
7
+ /**
8
+ * @class
9
+ * @hideconstructor
10
+ * @extends HomeyAPIV3.Manager
11
+ * @memberof HomeyAPIV3
12
+ */
7
13
  class ManagerDrivers extends Manager {
8
14
 
9
15
  static CRUD = {
@@ -4,8 +4,18 @@
4
4
 
5
5
  const Item = require('../Item');
6
6
 
7
+ /**
8
+ * @class
9
+ * @hideconstructor
10
+ * @extends HomeyAPIV3.Item
11
+ * @memberof HomeyAPIV3.ManagerFlow
12
+ */
7
13
  class AdvancedFlow extends Item {
8
14
 
15
+ /**
16
+ * Check whether this Flow misses one or more {@link FlowCard} or {@link FlowToken}.
17
+ * @returns Promise<Boolean> - A boolean whether this Flow is broken.
18
+ */
9
19
  async isBroken() {
10
20
  const managerFlow = this.homey.flow;
11
21
  if (!managerFlow.isConnected()) {
@@ -4,11 +4,17 @@
4
4
 
5
5
  const Item = require('../Item');
6
6
 
7
+ /**
8
+ * @class
9
+ * @hideconstructor
10
+ * @extends HomeyAPIV3.Item
11
+ * @memberof HomeyAPIV3.ManagerFlow
12
+ */
7
13
  class Flow extends Item {
8
14
 
9
15
  /**
10
16
  * Check whether this Flow misses one or more {@link FlowCard} or {@link FlowToken}.
11
- * @returns Promise<Boolean>
17
+ * @returns Promise<Boolean> - A boolean whether this Flow is broken.
12
18
  */
13
19
  async isBroken() {
14
20
  const managerFlow = this.homey.flow;
@@ -2,6 +2,12 @@
2
2
 
3
3
  const Item = require('../Item');
4
4
 
5
+ /**
6
+ * @class
7
+ * @hideconstructor
8
+ * @extends HomeyAPIV3.Item
9
+ * @memberof HomeyAPIV3.ManagerFlow
10
+ */
5
11
  class FlowCard extends Item {
6
12
 
7
13
  static transformGet(item) {
@@ -2,6 +2,12 @@
2
2
 
3
3
  const FlowCard = require('./FlowCard');
4
4
 
5
+ /**
6
+ * @class
7
+ * @hideconstructor
8
+ * @extends HomeyAPIV3.Item
9
+ * @memberof HomeyAPIV3.ManagerFlow
10
+ */
5
11
  class FlowCardAction extends FlowCard {
6
12
 
7
13
  }
@@ -2,6 +2,12 @@
2
2
 
3
3
  const FlowCard = require('./FlowCard');
4
4
 
5
+ /**
6
+ * @class
7
+ * @hideconstructor
8
+ * @extends HomeyAPIV3.Item
9
+ * @memberof HomeyAPIV3.ManagerFlow
10
+ */
5
11
  class FlowCardCondition extends FlowCard {
6
12
 
7
13
  }
@@ -2,6 +2,12 @@
2
2
 
3
3
  const FlowCard = require('./FlowCard');
4
4
 
5
+ /**
6
+ * @class
7
+ * @hideconstructor
8
+ * @extends HomeyAPIV3.Item
9
+ * @memberof HomeyAPIV3.ManagerFlow
10
+ */
5
11
  class FlowCardTrigger extends FlowCard {
6
12
 
7
13
  }
@@ -2,6 +2,12 @@
2
2
 
3
3
  const Item = require('../Item');
4
4
 
5
+ /**
6
+ * @class
7
+ * @hideconstructor
8
+ * @extends HomeyAPIV3.Item
9
+ * @memberof HomeyAPIV3.ManagerFlowToken
10
+ */
5
11
  class FlowToken extends Item {
6
12
 
7
13
  static transformGet(item) {
@@ -2,6 +2,12 @@
2
2
 
3
3
  const Item = require('../Item');
4
4
 
5
+ /**
6
+ * @class
7
+ * @hideconstructor
8
+ * @extends HomeyAPIV3.Item
9
+ * @memberof HomeyAPIV3.ManagerInsights
10
+ */
5
11
  class Log extends Item {
6
12
 
7
13
  async getEntries() {
@@ -395,9 +395,13 @@ class HomeyAPIV3 extends HomeyAPI {
395
395
  headers['Authorization'] = `Bearer ${this.__token}`;
396
396
  }
397
397
 
398
- if (body && json === true && ['PUT', 'POST'].includes(method)) {
399
- headers['Content-Type'] = 'application/json';
400
- body = JSON.stringify(body);
398
+ if (['PUT', 'POST'].includes(method)) {
399
+ if (body && json === true) {
400
+ headers['Content-Type'] = 'application/json';
401
+ body = JSON.stringify(body);
402
+ }
403
+ } else {
404
+ body = undefined;
401
405
  }
402
406
 
403
407
  this.__debug(method, `${baseUrl}${path}`);
@@ -2,6 +2,12 @@
2
2
 
3
3
  const HomeyAPIV3Item = require('../HomeyAPIV3/Item');
4
4
 
5
+ /**
6
+ * @class
7
+ * @hideconstructor
8
+ * @memberof HomeyAPIV3Cloud
9
+ * @extends HomeyAPIV3.Item
10
+ */
5
11
  class Item extends HomeyAPIV3Item {
6
12
 
7
13
  }
@@ -2,6 +2,12 @@
2
2
 
3
3
  const HomeyAPIV3Item = require('../HomeyAPIV3/Item');
4
4
 
5
+ /**
6
+ * @class
7
+ * @hideconstructor
8
+ * @memberof HomeyAPIV3Local
9
+ * @extends HomeyAPIV3.Item
10
+ */
5
11
  class Item extends HomeyAPIV3Item {
6
12
 
7
13
  }
@@ -6,8 +6,18 @@ const Manager = require('./Manager');
6
6
 
7
7
  class ManagerDevkit extends Manager {
8
8
 
9
+ /**
10
+ * Upload & run an app on Homey Pro.
11
+ * @param {Object} opts
12
+ * @param {ReadableStream} opts.app - A .tar.gz filestream.
13
+ * @param {Object} opts.env - Environment variables.
14
+ * @param {Boolean} opts.debug - Enable debug mode.
15
+ * @param {Boolean} opts.clean - Purge all app settings before running the app.
16
+ * @returns {Promise<any>}
17
+ * @function HomeyAPIV3Local.ManagerDevkit#runApp
18
+ */
9
19
  async runApp({
10
- app, // Readable
20
+ app,
11
21
  env = {},
12
22
  debug = false,
13
23
  clean = false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "files": [