homey-api 3.16.0 → 3.17.0

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.
@@ -5782,12 +5782,6 @@ export class Util {
5782
5782
 
5783
5783
  static encodeUrlSearchParams(params: object): string;
5784
5784
 
5785
- static deepEqual(
5786
- a: any,
5787
-
5788
- b: any,
5789
- ): boolean;
5790
-
5791
5785
  static fetch(
5792
5786
  args: string,
5793
5787
 
@@ -5829,12 +5823,6 @@ export class Util {
5829
5823
  static serializeQueryObject(queryObject: object): string;
5830
5824
 
5831
5825
  static encodeUrlSearchParams(params: object): string;
5832
-
5833
- static deepEqual(
5834
- a: any,
5835
-
5836
- b: any,
5837
- ): boolean;
5838
5826
  }
5839
5827
 
5840
5828
  export class APIDefinition {}
@@ -9212,12 +9200,6 @@ export class Util {
9212
9200
 
9213
9201
  static encodeUrlSearchParams(params: object): string;
9214
9202
 
9215
- static deepEqual(
9216
- a: any,
9217
-
9218
- b: any,
9219
- ): boolean;
9220
-
9221
9203
  static fetch(
9222
9204
  args: string,
9223
9205
 
@@ -9259,12 +9241,6 @@ export class Util {
9259
9241
  static serializeQueryObject(queryObject: object): string;
9260
9242
 
9261
9243
  static encodeUrlSearchParams(params: object): string;
9262
-
9263
- static deepEqual(
9264
- a: any,
9265
-
9266
- b: any,
9267
- ): boolean;
9268
9244
  }
9269
9245
 
9270
9246
  export namespace HomeyAPIV3Cloud {
@@ -90,6 +90,7 @@ class HomeyAPI extends EventEmitter {
90
90
  value: properties.softwareVersion ?? null,
91
91
  enumerable: true,
92
92
  writable: true,
93
+ configurable: true,
93
94
  });
94
95
 
95
96
  // Set Name
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const EventEmitter = require('../../EventEmitter');
4
- const Util = require('../../Util');
5
4
 
6
5
  /**
7
6
  * A superclass for all CRUD Items.
@@ -95,43 +94,14 @@ class Item extends EventEmitter {
95
94
  }
96
95
 
97
96
  __update(properties) {
98
- const oldValues = {};
99
- const newValues = {};
100
- const changedKeys = [];
101
-
102
97
  for (const [key, value] of Object.entries(properties)) {
103
98
  if (key === 'id') continue;
104
-
105
- if (!Util.deepEqual(this[key], value)) {
106
- oldValues[key] = Util.deepClone(this[key]);
107
- newValues[key] = Util.deepClone(value);
108
- changedKeys.push(key);
109
-
110
- this[key] = value;
111
- }
99
+ this[key] = value;
112
100
  }
113
101
 
114
102
  this.__lastUpdated = new Date();
115
103
 
116
- if (changedKeys.length === 0) {
117
- return {
118
- oldValues,
119
- newValues,
120
- changedKeys,
121
- };
122
- }
123
-
124
- this.emit('update', properties, {
125
- oldValues,
126
- newValues,
127
- changedKeys,
128
- });
129
-
130
- return {
131
- oldValues,
132
- newValues,
133
- changedKeys,
134
- };
104
+ this.emit('update', properties);
135
105
  }
136
106
 
137
107
  __delete() {
@@ -531,19 +531,8 @@ class Manager extends EventEmitter {
531
531
 
532
532
  if (this.__cache[ItemClass.ID][props.id]) {
533
533
  const item = this.__cache[ItemClass.ID][props.id];
534
- const {
535
- oldValues,
536
- newValues,
537
- changedKeys,
538
- } = item.__update(props);
539
-
540
- if (changedKeys.length === 0) return;
541
-
542
- return this.emit(event, item, {
543
- oldValues,
544
- newValues,
545
- changedKeys,
546
- });
534
+ item.__update(props);
535
+ return this.emit(event, item);
547
536
  }
548
537
 
549
538
  break;
@@ -228,20 +228,6 @@ class HomeyAPIV3 extends HomeyAPI {
228
228
  throw new Error('No Discovery Strategies Available');
229
229
  }
230
230
 
231
- // TODO
232
- // maybe we should always ping
233
-
234
- // Don't discover, just set the only strategy
235
- if (Object.keys(urls).length === 1) {
236
- this.__baseUrl = Object.values(urls)[0];
237
- this.__strategyId = Object.keys(urls)[0];
238
-
239
- return {
240
- baseUrl: this.__baseUrl,
241
- strategyId: this.__strategyId,
242
- };
243
- }
244
-
245
231
  this.__debug(`Discovery Strategies: ${Object.keys(urls).join(',')}`);
246
232
 
247
233
  // Create the returned Promise
@@ -448,7 +434,7 @@ class HomeyAPIV3 extends HomeyAPI {
448
434
  } else if (pings[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL]) {
449
435
  pings[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL]
450
436
  .then((result) => resolve(result))
451
- .catch(() => {
437
+ .catch((err) => {
452
438
  if (pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]) {
453
439
  pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]
454
440
  .then((result) => resolve(result))
@@ -463,12 +449,14 @@ class HomeyAPIV3 extends HomeyAPI {
463
449
 
464
450
  reject(new APIErrorHomeyOffline(err));
465
451
  });
452
+ } else {
453
+ reject(new APIErrorHomeyOffline(err));
466
454
  }
467
455
  });
468
456
  } else if (pings[HomeyAPI.DISCOVERY_STRATEGIES.MDNS]) {
469
457
  pings[HomeyAPI.DISCOVERY_STRATEGIES.MDNS]
470
458
  .then((result) => resolve(result))
471
- .catch(() => {
459
+ .catch((err) => {
472
460
  if (pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]) {
473
461
  pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]
474
462
  .then((result) => resolve(result))
@@ -483,12 +471,14 @@ class HomeyAPIV3 extends HomeyAPI {
483
471
 
484
472
  reject(new APIErrorHomeyOffline(err));
485
473
  });
474
+ } else {
475
+ reject(new APIErrorHomeyOffline(err));
486
476
  }
487
477
  });
488
478
  } else if (pings[HomeyAPI.DISCOVERY_STRATEGIES.REMOTE_FORWARDED]) {
489
479
  pings[HomeyAPI.DISCOVERY_STRATEGIES.REMOTE_FORWARDED]
490
480
  .then((result) => resolve(result))
491
- .catch(() => {
481
+ .catch((err) => {
492
482
  if (pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]) {
493
483
  pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]
494
484
  .then((result) => resolve(result))
@@ -503,6 +493,8 @@ class HomeyAPIV3 extends HomeyAPI {
503
493
 
504
494
  reject(new APIErrorHomeyOffline(err));
505
495
  });
496
+ } else {
497
+ reject(new APIErrorHomeyOffline(err));
506
498
  }
507
499
  });
508
500
  } else if (pings[HomeyAPI.DISCOVERY_STRATEGIES.CLOUD]) {
@@ -660,6 +652,7 @@ class HomeyAPIV3 extends HomeyAPI {
660
652
  this.__token = store.token;
661
653
  this.__session = store.session;
662
654
 
655
+ await this.baseUrl; // Ensure discovery has completed
663
656
  return;
664
657
  }
665
658
 
@@ -32,6 +32,11 @@ class HomeyAPIV3Cloud extends HomeyAPIV3 {
32
32
  strategy,
33
33
  ...props,
34
34
  });
35
+
36
+ // Seed the version cache with the initial value from the Cloud API,
37
+ // then remove the own data property so the prototype getter is used.
38
+ this.__versionCache[this.id] ??= this.version;
39
+ delete this.version;
35
40
  }
36
41
 
37
42
  get tier() {
@@ -42,6 +47,10 @@ class HomeyAPIV3Cloud extends HomeyAPIV3 {
42
47
  return this.__versionCache[this.id];
43
48
  }
44
49
 
50
+ set version(value) {
51
+ this.__versionCache[this.id] = value;
52
+ }
53
+
45
54
  get platform() {
46
55
  return 'cloud';
47
56
  }
package/lib/Util.js CHANGED
@@ -338,92 +338,6 @@ class Util {
338
338
  return encodedPairs.join('&');
339
339
  }
340
340
 
341
- /**
342
- * Deep equality check between two values.
343
- * @param {any} a
344
- * @param {any} b
345
- * @returns {boolean}
346
- */
347
- static deepEqual(a, b) {
348
- if (a === b) return true;
349
-
350
- if (
351
- typeof a !== 'object' ||
352
- typeof b !== 'object' ||
353
- a === null ||
354
- b === null
355
- ) {
356
- return false;
357
- }
358
-
359
- const keysA = Object.keys(a);
360
- const keysB = Object.keys(b);
361
-
362
- if (keysA.length !== keysB.length) return false;
363
-
364
- for (const key of keysA) {
365
- if (!keysB.includes(key) || !this.deepEqual(a[key], b[key])) {
366
- return false;
367
- }
368
- }
369
-
370
- return true;
371
- }
372
-
373
- static deepClone(value) {
374
- // Use native structuredClone when available
375
- if (typeof structuredClone === 'function') {
376
- return structuredClone(value);
377
- }
378
-
379
- const seen = new WeakMap();
380
-
381
- function clone(val) {
382
- if (val === null || typeof val !== 'object') {
383
- return val;
384
- }
385
-
386
- if (seen.has(val)) {
387
- return seen.get(val);
388
- }
389
-
390
- if (val instanceof Date) {
391
- return new Date(val);
392
- }
393
-
394
- if (val instanceof Map) {
395
- const map = new Map();
396
- seen.set(val, map);
397
- val.forEach((v, k) => map.set(clone(k), clone(v)));
398
- return map;
399
- }
400
-
401
- if (val instanceof Set) {
402
- const set = new Set();
403
- seen.set(val, set);
404
- val.forEach(v => set.add(clone(v)));
405
- return set;
406
- }
407
-
408
- if (Array.isArray(val)) {
409
- const arr = [];
410
- seen.set(val, arr);
411
- val.forEach((v, i) => arr[i] = clone(v));
412
- return arr;
413
- }
414
-
415
- const obj = {};
416
- seen.set(val, obj);
417
- Object.keys(val).forEach(key => {
418
- obj[key] = clone(val[key]);
419
- });
420
-
421
- return obj;
422
- }
423
-
424
- return clone(value);
425
- }
426
-
427
341
  }
428
342
 
429
343
  module.exports = Util;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "3.16.0",
3
+ "version": "3.17.0",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "license": "SEE LICENSE",
@@ -73,7 +73,7 @@
73
73
  "homey-api": "^3.0.8",
74
74
  "http-server": "^0.12.3",
75
75
  "jest": "^30.0.0-alpha.2",
76
- "jsdoc": "^4.0.2",
76
+ "jsdoc": "4.0.5",
77
77
  "jsdoc-to-markdown": "^8.0.0",
78
78
  "jsdoc-ts-utils": "^4.0.0",
79
79
  "jsdoc-tsimport-plugin": "^1.0.5",