homey-api 3.0.0-rc.5 → 3.0.0-rc.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.
@@ -68,6 +68,13 @@ class Item extends EventEmitter {
68
68
 
69
69
  this[key] = value;
70
70
  }
71
+
72
+ this.emit('update', properties);
73
+ }
74
+
75
+ __delete() {
76
+ this.destroy();
77
+ this.emit('delete');
71
78
  }
72
79
 
73
80
  async connect() {
@@ -412,53 +412,38 @@ class Manager extends EventEmitter {
412
412
 
413
413
  switch (operation) {
414
414
  case 'create': {
415
- let item = { ...data };
416
- item = Item.transform(item);
417
- item = new Item({
418
- id: item.id,
415
+ data = Item.transform(data);
416
+
417
+ const item = new Item({
418
+ id: data.id,
419
419
  homey: this.homey,
420
420
  manager: this,
421
- properties: { ...item },
421
+ properties: { ...data },
422
422
  });
423
+ this.__cache[itemId][data.id] = item;
423
424
 
424
- this.__cache[itemId][item.id] = item;
425
- this.__cache[itemId][item.id].emit('create');
426
-
427
- return this.emit(`${itemId}.create`, item);
425
+ break;
428
426
  }
429
427
  case 'update': {
430
- let item = { ...data };
431
- item = Item.transform(item);
428
+ data = Item.transform(data);
432
429
 
433
- if (this.__cache[itemId][item.id]) {
434
- item = this.__cache[itemId][item.id];
435
- item.__update(item);
436
- item.emit('update');
437
- } else {
438
- item = new Item({
439
- id: item.id,
440
- homey: this.homey,
441
- manager: this,
442
- properties: { ...item },
443
- });
444
- this.__cache[itemId][item.id] = item;
430
+ if (this.__cache[itemId][data.id]) {
431
+ const item = this.__cache[itemId][data.id];
432
+ item.__update(data);
445
433
  }
446
434
 
447
- return this.emit(`${itemId}.update`, item);
435
+ break;
448
436
  }
449
437
  case 'delete': {
450
- let item = Item.transform({ ...data });
451
- item = Item.transform(item);
438
+ data = Item.transform(data);
452
439
 
453
- if (this.__cache[itemId][item.id]) {
454
- this.__cache[itemId][item.id].emit('delete');
455
- this.__cache[itemId][item.id].destroy();
440
+ if (this.__cache[itemId][data.id]) {
441
+ const item = this.__cache[itemId][data.id];
442
+ item.__delete();
456
443
  delete this.__cache[itemId][item.id];
457
444
  }
458
445
 
459
- return this.emit(`${itemId}.delete`, {
460
- id: item.id,
461
- });
446
+ break;
462
447
  }
463
448
  default:
464
449
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "3.0.0-rc.5",
3
+ "version": "3.0.0-rc.6",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "files": [