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.
|
@@ -412,53 +412,38 @@ class Manager extends EventEmitter {
|
|
|
412
412
|
|
|
413
413
|
switch (operation) {
|
|
414
414
|
case 'create': {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
item = new Item({
|
|
418
|
-
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: { ...
|
|
421
|
+
properties: { ...data },
|
|
422
422
|
});
|
|
423
|
+
this.__cache[itemId][data.id] = item;
|
|
423
424
|
|
|
424
|
-
|
|
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
|
-
|
|
431
|
-
item = Item.transform(item);
|
|
428
|
+
data = Item.transform(data);
|
|
432
429
|
|
|
433
|
-
if (this.__cache[itemId][
|
|
434
|
-
item = this.__cache[itemId][
|
|
435
|
-
item.__update(
|
|
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
|
-
|
|
435
|
+
break;
|
|
448
436
|
}
|
|
449
437
|
case 'delete': {
|
|
450
|
-
|
|
451
|
-
item = Item.transform(item);
|
|
438
|
+
data = Item.transform(data);
|
|
452
439
|
|
|
453
|
-
if (this.__cache[itemId][
|
|
454
|
-
this.__cache[itemId][
|
|
455
|
-
|
|
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
|
-
|
|
460
|
-
id: item.id,
|
|
461
|
-
});
|
|
446
|
+
break;
|
|
462
447
|
}
|
|
463
448
|
default:
|
|
464
449
|
break;
|