homey-api 3.0.4 → 3.0.6

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/lib/API.js CHANGED
@@ -1,8 +1,3 @@
1
- /* eslint-disable new-cap */
2
- /* eslint-disable max-classes-per-file */
3
- /* eslint-disable global-require */
4
- /* eslint-disable import/no-dynamic-require */
5
-
6
1
  'use strict';
7
2
 
8
3
  // const path = require('path');
@@ -274,6 +269,7 @@ class API {
274
269
  });
275
270
  }
276
271
 
272
+ // eslint-disable-next-line no-unused-vars
277
273
  async onCallRequestHeaders({ request }) {
278
274
  return {};
279
275
  }
@@ -294,15 +290,19 @@ class API {
294
290
  }
295
291
 
296
292
  async onCallResponseOK({
293
+ // eslint-disable-next-line no-unused-vars
297
294
  context,
298
295
  body,
296
+ // eslint-disable-next-line no-unused-vars
299
297
  statusCode,
298
+ // eslint-disable-next-line no-unused-vars
300
299
  statusText,
301
300
  }) {
302
301
  return body;
303
302
  }
304
303
 
305
304
  async onCallResponseNotOK({
305
+ // eslint-disable-next-line no-unused-vars
306
306
  context,
307
307
  body,
308
308
  statusCode,
@@ -9,7 +9,7 @@ class APIDefinition {
9
9
  /**
10
10
  *
11
11
  * @param {object} opts
12
- * @param {API} opts.api
12
+ * @param {import('./API.js')} opts.api
13
13
  * @param {object} opts.properties
14
14
  */
15
15
  constructor({
@@ -25,8 +25,8 @@ class Homey extends APIDefinition {
25
25
  /**
26
26
  * This method returns a {@link HomeyAPI} instance matching the Homey's API level and platform.
27
27
  * Additionally, it ensures a session on the Homey during initialization.
28
- * @param {object} opts
29
- * @param {string|array} opts.strategy - One string, or an array of {@link HomeyAPI#DISCOVERY_STRATEGIES} strings, to connect to the Homey.
28
+ * @param {object} [opts]
29
+ * @param {string|array} [opts.strategy] - One string, or an array of {@link HomeyAPI#DISCOVERY_STRATEGIES} strings, to connect to the Homey.
30
30
  * @returns {Promise<HomeyAPI>}
31
31
  */
32
32
  async authenticate({ strategy } = {}) {
@@ -19,6 +19,7 @@ class StorageAdapter {
19
19
  * @param {object} value
20
20
  * @returns {Promise<void>}
21
21
  */
22
+ // eslint-disable-next-line no-unused-vars
22
23
  async set(value) {
23
24
  throw new Error('Not Implemented: StorageAdapter.set()');
24
25
  }
@@ -240,7 +240,8 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
240
240
  /*
241
241
  * API overloads
242
242
  */
243
-
243
+
244
+ // eslint-disable-next-line no-unused-vars
244
245
  async onCallRequestHeaders({ request }) {
245
246
  // Try to set the Token from the StorageAdapter
246
247
  if (!this.__token) {
@@ -9,23 +9,34 @@ const EventEmitter = require('../../EventEmitter');
9
9
  * @memberof HomeyAPIV3
10
10
  */
11
11
  class Item extends EventEmitter {
12
-
13
12
  static ID = null; // Set by Manager.js
14
13
 
15
- constructor({
16
- id,
17
- homey,
18
- manager,
19
- properties,
20
- }) {
14
+ /**
15
+ * The ID of the Item.
16
+ * @type {string}
17
+ */
18
+ id;
19
+ /**
20
+ * The URI of the Item, e.g. `homey:foo:bar`.
21
+ * @type {string}
22
+ */
23
+ uri;
24
+
25
+ constructor({ id, homey, manager, properties }) {
21
26
  super();
22
27
 
23
- Object.defineProperty(this, '__id', {
28
+ Object.defineProperty(this, 'id', {
24
29
  value: id,
25
30
  enumerable: true,
26
31
  writable: false,
27
32
  });
28
33
 
34
+ Object.defineProperty(this, 'uri', {
35
+ value: `homey:${this.constructor.ID}:${this.id}`,
36
+ enumerable: true,
37
+ writable: false,
38
+ });
39
+
29
40
  // Set Homey
30
41
  Object.defineProperty(this, '__homey', {
31
42
  value: homey,
@@ -59,22 +70,6 @@ class Item extends EventEmitter {
59
70
  }
60
71
  }
61
72
 
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
- */
74
- get uri() {
75
- return `homey:${this.constructor.ID}:${this.id}`;
76
- }
77
-
78
73
  /**
79
74
  * The Manager of the Item.
80
75
  * @type {HomeyAPIV3.Manager}
@@ -123,7 +118,8 @@ class Item extends EventEmitter {
123
118
  // promise before we try to connect again.
124
119
  await Promise.resolve();
125
120
  await this.__disconnectPromise;
126
- } catch (err) { }
121
+ // eslint-disable-next-line no-empty
122
+ } catch (err) {}
127
123
 
128
124
  this.__connectPromise = Promise.resolve().then(async () => {
129
125
  if (!this.io) {
@@ -158,7 +154,7 @@ class Item extends EventEmitter {
158
154
 
159
155
  // Delete the connecting Promise
160
156
  this.__connectPromise
161
- .catch(() => { })
157
+ .catch(() => {})
162
158
  .finally(() => {
163
159
  delete this.__connectPromise;
164
160
  });
@@ -175,21 +171,20 @@ class Item extends EventEmitter {
175
171
  // If connecting, await that first
176
172
  try {
177
173
  await this.__connectPromise;
178
- } catch (err) { }
174
+ // eslint-disable-next-line no-empty
175
+ } catch (err) {}
179
176
 
180
177
  this.__disconnectPromise = Promise.resolve().then(async () => {
181
178
  this.__connected = false;
182
179
 
183
180
  if (this.io) {
184
- this.io
185
- .then(io => io.unsubscribe())
186
- .catch(err => this.__debug('Error Disconnecting:', err));
181
+ this.io.then(io => io.unsubscribe()).catch(err => this.__debug('Error Disconnecting:', err));
187
182
  }
188
183
  });
189
184
 
190
185
  // Delete the disconnecting Promise
191
186
  this.__disconnectPromise
192
- .catch(() => { })
187
+ .catch(() => {})
193
188
  .finally(() => {
194
189
  delete this.__disconnectPromise;
195
190
  // Delete this.io so connect can start new connections.
@@ -216,7 +211,7 @@ class Item extends EventEmitter {
216
211
  this.removeAllListeners();
217
212
 
218
213
  // Disconnect from Socket.io
219
- this.disconnect().catch(() => { });
214
+ this.disconnect().catch(() => {});
220
215
  }
221
216
 
222
217
  static transformGet(item) {
@@ -226,7 +221,6 @@ class Item extends EventEmitter {
226
221
  static transformSet(item) {
227
222
  return item;
228
223
  }
229
-
230
224
  }
231
225
 
232
226
  module.exports = Item;
@@ -396,7 +396,10 @@ class Manager extends EventEmitter {
396
396
  // If disconnecting, await that first
397
397
  try {
398
398
  await this.__disconnectPromise;
399
- } catch (err) { }
399
+ // eslint-disable-next-line no-empty
400
+ } catch (err) {
401
+
402
+ }
400
403
 
401
404
  this.__connectPromise = Promise.resolve().then(async () => {
402
405
  if (!this.io) {
@@ -498,7 +501,10 @@ class Manager extends EventEmitter {
498
501
  // If connecting, await that first
499
502
  try {
500
503
  await this.__connectPromise;
501
- } catch (err) { }
504
+ // eslint-disable-next-line no-empty
505
+ } catch (err) {
506
+
507
+ }
502
508
 
503
509
  this.__disconnectPromise = Promise.resolve().then(async () => {
504
510
  this.__connected = false;
@@ -162,10 +162,11 @@ class Device extends Item {
162
162
 
163
163
  /**
164
164
  * Get the device's logs.
165
- * @returns {Promise<{String, HomeyAPIV3.ManagerInsights.Log}>}
165
+ * @returns {Promise.<Object.<string, HomeyAPIV3.ManagerInsights.Log>>}
166
166
  */
167
167
  async getLogs() {
168
168
  const logs = await this.homey.insights.getLogs();
169
+
169
170
  return Object.values(logs)
170
171
  .filter(log => log.ownerUri === this.uri)
171
172
  .reduce((result, log) => ({
@@ -176,7 +177,7 @@ class Device extends Item {
176
177
 
177
178
  /**
178
179
  * Get the device's flows.
179
- * @returns {Promise<{String, HomeyAPIV3.ManagerFlow.Flow}>}
180
+ * @returns {Promise.<Object.<string, HomeyAPIV3.ManagerFlow.Flow>>}
180
181
  */
181
182
  async getFlows() {
182
183
  const flows = await this.homey.flow.getFlows();
@@ -198,8 +199,7 @@ class Device extends Item {
198
199
  }
199
200
 
200
201
  /**
201
- * @returns {Promise<{String, HomeyAPIV3.ManagerFlow.AdvancedFlow}>}
202
- * @returns {Promise<Object>}
202
+ * @returns {Promise.<Object.<string, HomeyAPIV3.ManagerFlow.AdvancedFlow>>}
203
203
  */
204
204
  async getAdvancedFlows() {
205
205
  const advancedFlows = await this.homey.flow.getAdvancedFlows();
@@ -421,7 +421,10 @@ class HomeyAPIV3 extends HomeyAPI {
421
421
  if (resHeadersContentType && resHeadersContentType.startsWith('application/json')) {
422
422
  try {
423
423
  resBodyJson = JSON.parse(resBodyText);
424
- } catch (err) { }
424
+ // eslint-disable-next-line no-empty
425
+ } catch (err) {
426
+
427
+ }
425
428
  }
426
429
 
427
430
  if (!res.ok) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "3.0.4",
3
+ "version": "3.0.6",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "homepage": "https://github.com/athombv/node-homey-api#readme",
44
44
  "engines": {
45
- "node": ">12"
45
+ "node": ">=16"
46
46
  },
47
47
  "dependencies": {
48
48
  "core-js": "^3.19.1",
@@ -56,6 +56,8 @@
56
56
  "@babel/core": "^7.16.0",
57
57
  "@babel/plugin-proposal-class-properties": "^7.16.0",
58
58
  "@babel/preset-env": "^7.16.0",
59
+ "@typescript-eslint/eslint-plugin": "^6.1.0",
60
+ "@typescript-eslint/parser": "^6.1.0",
59
61
  "babel-loader": "^8.2.3",
60
62
  "concurrently": "^5.1.0",
61
63
  "ejs": "^3.1.6",
@@ -66,8 +68,11 @@
66
68
  "jsdoc": "^3.6.7",
67
69
  "jsdoc-to-markdown": "^7.1.0",
68
70
  "jsdoc-ts-utils": "^2.0.1",
71
+ "jsdoc-tsimport-plugin": "^1.0.5",
69
72
  "keypather": "^3.1.0",
73
+ "prettier": "^3.0.0",
70
74
  "serve": "^14.0.1",
75
+ "typescript": "^5.1.6",
71
76
  "watch": "^1.0.2",
72
77
  "webpack": "^5.64.0",
73
78
  "webpack-cli": "^4.9.1",