homey-api 3.0.0-rc.1 → 3.0.0-rc.3

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.
@@ -1063,62 +1063,6 @@
1063
1063
 
1064
1064
 
1065
1065
 
1066
- makeCapabilityInstance(
1067
-
1068
-
1069
-
1070
-
1071
- capabilityId: string,
1072
-
1073
-
1074
-
1075
- listener: {
1076
-
1077
-
1078
- value: number | boolean | string,
1079
-
1080
-
1081
- },
1082
-
1083
-
1084
-
1085
-
1086
- ):
1087
- HomeyAPIV2.ManagerDevices.Device.DeviceCapability;
1088
-
1089
- setCapabilityValue(
1090
-
1091
-
1092
-
1093
-
1094
- opts: {
1095
-
1096
-
1097
- capabilityId: string,
1098
-
1099
-
1100
-
1101
- value: number | boolean | string,
1102
-
1103
-
1104
-
1105
- opts: {
1106
-
1107
-
1108
- duration: number,
1109
-
1110
-
1111
- },
1112
-
1113
-
1114
- },
1115
-
1116
-
1117
-
1118
-
1119
- ):
1120
- Promise<void>;
1121
-
1122
1066
  }
1123
1067
 
1124
1068
  }
@@ -14573,6 +14517,10 @@
14573
14517
 
14574
14518
 
14575
14519
 
14520
+
14521
+
14522
+
14523
+
14576
14524
 
14577
14525
 
14578
14526
 
@@ -6411,62 +6411,6 @@
6411
6411
 
6412
6412
 
6413
6413
 
6414
- makeCapabilityInstance(
6415
-
6416
-
6417
-
6418
-
6419
- capabilityId: string,
6420
-
6421
-
6422
-
6423
- listener: {
6424
-
6425
-
6426
- value: number | boolean | string,
6427
-
6428
-
6429
- },
6430
-
6431
-
6432
-
6433
-
6434
- ):
6435
- HomeyAPIV2.ManagerDevices.Device.DeviceCapability;
6436
-
6437
- setCapabilityValue(
6438
-
6439
-
6440
-
6441
-
6442
- opts: {
6443
-
6444
-
6445
- capabilityId: string,
6446
-
6447
-
6448
-
6449
- value: number | boolean | string,
6450
-
6451
-
6452
-
6453
- opts: {
6454
-
6455
-
6456
- duration: number,
6457
-
6458
-
6459
- },
6460
-
6461
-
6462
- },
6463
-
6464
-
6465
-
6466
-
6467
- ):
6468
- Promise<void>;
6469
-
6470
6414
  }
6471
6415
 
6472
6416
  }
@@ -20621,6 +20565,10 @@
20621
20565
 
20622
20566
 
20623
20567
 
20568
+
20569
+
20570
+
20571
+
20624
20572
 
20625
20573
 
20626
20574
 
@@ -139,10 +139,6 @@ class HomeyAPI {
139
139
  throw new Error('Invalid Homey');
140
140
  }
141
141
 
142
- if (homey.platform !== 'local') {
143
- throw new Error(`Invalid Homey Platform: ${homey.platform}`);
144
- }
145
-
146
142
  const props = {
147
143
  debug,
148
144
  token: await homey.api.getOwnerApiToken(),
@@ -154,16 +150,21 @@ class HomeyAPI {
154
150
  },
155
151
  };
156
152
 
157
- if (homey.platformVersion === 1) {
153
+ if (homey.platform === 'local' && homey.platformVersion === 1) {
158
154
  const HomeyAPIV2 = require('./HomeyAPIV2');
159
155
  return new HomeyAPIV2(props);
160
156
  }
161
157
 
162
- if (homey.platformVersion === 2) {
158
+ if (homey.platform === 'local' && homey.platformVersion === 2) {
163
159
  const HomeyAPIV3Local = require('./HomeyAPIV3Local');
164
160
  return new HomeyAPIV3Local(props);
165
161
  }
166
162
 
163
+ if (homey.platform === 'cloud' && homey.platformVersion === 2) {
164
+ const HomeyAPIV3Cloud = require('./HomeyAPIV3Cloud');
165
+ return new HomeyAPIV3Cloud(props);
166
+ }
167
+
167
168
  throw new Error(`Invalid Homey Platform Version: ${homey.platformVersion}`);
168
169
  }
169
170
 
@@ -12,20 +12,6 @@ class ManagerDevices extends Manager {
12
12
  Device,
13
13
  }
14
14
 
15
- async getCapability({
16
- $cache = true,
17
- id,
18
- }) {
19
- if ($cache === true && this.__cache['capability'][id]) {
20
- return this.__cache['capability'][id];
21
- }
22
-
23
- return this.__super__getCapability({
24
- id: id.split(':').reverse()[0],
25
- uri: id.split(':', 3).join(':'),
26
- });
27
- }
28
-
29
15
  }
30
16
 
31
17
  module.exports = ManagerDevices;
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ const PairSessionV3 = require('../../HomeyAPIV3/ManagerDrivers/PairSession');
4
+
5
+ class PairSession extends PairSessionV3 {
6
+
7
+ static transform(item) {
8
+ item = super.transform(item);
9
+
10
+ item.driverId = `${item.driverUri}:${item.driverId}`;
11
+ item.ownerUri = item.driverUri;
12
+
13
+ delete item.driverUri;
14
+
15
+ return item;
16
+ }
17
+
18
+ }
19
+
20
+ module.exports = PairSession;
@@ -2,12 +2,14 @@
2
2
 
3
3
  const ManagerDriversV3 = require('../HomeyAPIV3/ManagerDrivers');
4
4
  const Driver = require('./ManagerDrivers/Driver');
5
+ const PairSession = require('./ManagerDrivers/PairSession');
5
6
 
6
7
  class ManagerDrivers extends ManagerDriversV3 {
7
8
 
8
9
  static CRUD = {
9
10
  ...super.CRUD,
10
11
  Driver,
12
+ PairSession,
11
13
  }
12
14
 
13
15
  async getDriver({
@@ -24,6 +26,21 @@ class ManagerDrivers extends ManagerDriversV3 {
24
26
  });
25
27
  }
26
28
 
29
+ async createPairSession({
30
+ pairsession,
31
+ ...props
32
+ }) {
33
+ if (pairsession.driverId) {
34
+ pairsession.driverUri = pairsession.driverId.split(':', 3).join(':');
35
+ pairsession.driverId = pairsession.driverId.split(':').reverse()[0];
36
+ }
37
+
38
+ return this.__super__createPairSession({
39
+ pairsession,
40
+ ...props,
41
+ });
42
+ }
43
+
27
44
  }
28
45
 
29
46
  module.exports = ManagerDrivers;
@@ -18,22 +18,45 @@ class ManagerFlow extends Manager {
18
18
  FlowCardAction,
19
19
  }
20
20
 
21
- // TODO: Transform card IDs
22
- // async createFlow() {
23
-
24
- // }
25
-
26
- // async updateFlow() {
27
-
28
- // }
29
-
30
- // async createAdvancedFlow() {
21
+ async createFlow({
22
+ flow,
23
+ ...props
24
+ }) {
25
+ return this.__super__.createFlow({
26
+ flow: Flow.transform(flow),
27
+ ...props,
28
+ });
29
+ }
31
30
 
32
- // }
31
+ async updateFlow({
32
+ flow,
33
+ ...props
34
+ }) {
35
+ return this.__super__.updateFlow({
36
+ flow: Flow.transform(flow),
37
+ ...props,
38
+ });
39
+ }
33
40
 
34
- // async updateAdvancedFlow() {
41
+ async createAdvancedFlow({
42
+ advancedflow,
43
+ ...props
44
+ }) {
45
+ return this.__super__.createAdvancedFlow({
46
+ advancedflow: AdvancedFlow.transform(advancedflow),
47
+ ...props,
48
+ });
49
+ }
35
50
 
36
- // }
51
+ async updateAdvancedFlow({
52
+ advancedflow,
53
+ ...props
54
+ }) {
55
+ return this.__super__.updateAdvancedFlow({
56
+ advancedflow: AdvancedFlow.transform(advancedflow),
57
+ ...props,
58
+ });
59
+ }
37
60
 
38
61
  async getFlowCardTrigger({
39
62
  $cache = true,
@@ -24,6 +24,23 @@ class ManagerInsights extends ManagerInsightsV3 {
24
24
  });
25
25
  }
26
26
 
27
+ async getLogEntries({ id }) {
28
+ return this.__super__getLogEntries({
29
+ id: id.split(':').reverse()[0],
30
+ uri: id.split(':', 3).join(':'),
31
+ });
32
+ }
33
+
34
+ async deleteLogEntries({ id }) {
35
+ return this.__super__deleteLogEntries({
36
+ id: id.split(':').reverse()[0],
37
+ uri: id.split(':', 3).join(':'),
38
+ });
39
+ }
40
+
41
+ // deleteLog
42
+ // updateLog
43
+
27
44
  }
28
45
 
29
46
  module.exports = ManagerInsights;
@@ -64,6 +64,8 @@ class Item extends EventEmitter {
64
64
 
65
65
  __update(properties) {
66
66
  for (const [key, value] of Object.entries(properties)) {
67
+ if (key === 'id') continue;
68
+
67
69
  this[key] = value;
68
70
  }
69
71
  }
@@ -260,7 +260,6 @@ class Manager extends EventEmitter {
260
260
  let item = { ...result };
261
261
  item = Item.transform(item);
262
262
  item = new Item({
263
- itemId,
264
263
  id: item.id,
265
264
  homey: this.homey,
266
265
  manager: this,
@@ -280,11 +279,10 @@ class Manager extends EventEmitter {
280
279
  for (let item of Object.values(result)) {
281
280
  item = Item.transform(item);
282
281
  if (this.__cache[itemId][item.id]) {
283
- this.__cache[itemId][item.id].__update(item);
284
282
  items[item.id] = this.__cache[itemId][item.id];
283
+ items[item.id].__update(item);
285
284
  } else {
286
285
  items[item.id] = new Item({
287
- itemId,
288
286
  id: item.id,
289
287
  homey: this.homey,
290
288
  manager: this,
@@ -317,12 +315,13 @@ class Manager extends EventEmitter {
317
315
  case 'updateOne': {
318
316
  let item = { ...result };
319
317
  item = Item.transform(item);
318
+
320
319
  if (this.__cache[itemId][item.id]) {
321
- item = this.__cache[itemId][item.id].__update(item);
320
+ item = this.__cache[itemId][item.id];
321
+ item.__update(item);
322
322
  } else {
323
323
  item = Item.transform(item);
324
324
  item = new Item({
325
- itemId,
326
325
  id: item.id,
327
326
  homey: this.homey,
328
327
  manager: this,
@@ -416,7 +415,6 @@ class Manager extends EventEmitter {
416
415
  let item = { ...data };
417
416
  item = Item.transform(item);
418
417
  item = new Item({
419
- itemId,
420
418
  id: item.id,
421
419
  homey: this.homey,
422
420
  manager: this,
@@ -438,7 +436,6 @@ class Manager extends EventEmitter {
438
436
  item.emit('update');
439
437
  } else {
440
438
  item = new Item({
441
- itemId,
442
439
  id: item.id,
443
440
  homey: this.homey,
444
441
  manager: this,
@@ -17,17 +17,13 @@ class Device extends Item {
17
17
  });
18
18
  }
19
19
 
20
- get uri() {
21
- return `homey:device:${this.id}`;
22
- }
23
-
24
20
  /**
25
- * Creates an {@link HomeyAPIV2.DeviceCapability} for realtime capability updates.
21
+ * Creates an {@link HomeyAPIV3.DeviceCapability} for realtime capability updates.
26
22
  * @param {string} capabilityId
27
23
  * @param {Function} listener
28
24
  * @param {number|boolean|string} listener.value
29
- * @returns {HomeyAPIV2.ManagerDevices.Device.DeviceCapability}
30
- * @function HomeyAPIV2.ManagerDevices.Device#makeCapabilityInstance
25
+ * @returns {HomeyAPIV3.ManagerDevices.Device.DeviceCapability}
26
+ * @function HomeyAPIV3.ManagerDevices.Device#makeCapabilityInstance
31
27
  * @example
32
28
  *
33
29
  * const onOffInstance = device.makeCapabilityInstance('onoff', value => {
@@ -76,7 +72,7 @@ class Device extends Item {
76
72
  * @param {object} [opts.opts]
77
73
  * @param {number} [opts.opts.duration]
78
74
  * @returns {Promise<void>}
79
- * @function HomeyAPIV2.ManagerDevices.Device#setCapabilityValue
75
+ * @function HomeyAPIV3.ManagerDevices.Device#setCapabilityValue
80
76
  */
81
77
  async setCapabilityValue(options, ...args) {
82
78
  // Legacy compatibility from node-athom-api
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const Item = require('../Item');
4
+
5
+ class PairSession extends Item {
6
+
7
+ }
8
+
9
+ module.exports = PairSession;
@@ -2,12 +2,14 @@
2
2
 
3
3
  const Manager = require('./Manager');
4
4
  const Driver = require('./ManagerDrivers/Driver');
5
+ const PairSession = require('./ManagerDrivers/PairSession');
5
6
 
6
7
  class ManagerDrivers extends Manager {
7
8
 
8
9
  static CRUD = {
9
10
  ...super.CRUD,
10
11
  Driver,
12
+ PairSession,
11
13
  }
12
14
 
13
15
  }
@@ -4,6 +4,14 @@ const Item = require('../Item');
4
4
 
5
5
  class Flow extends Item {
6
6
 
7
+ /**
8
+ * Check whether this Flow misses one or more {@link FlowCard} or {@link FlowToken}.
9
+ * @returns Promise<Boolean>
10
+ */
11
+ async isBroken() {
12
+ throw new Error('Not Implemented');
13
+ }
14
+
7
15
  }
8
16
 
9
17
  module.exports = Flow;
@@ -4,6 +4,12 @@ const Item = require('../Item');
4
4
 
5
5
  class Log extends Item {
6
6
 
7
+ async getEntries() {
8
+ return this.manager.getLogEntries({
9
+ id: this.id,
10
+ });
11
+ }
12
+
7
13
  }
8
14
 
9
15
  module.exports = Log;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "3.0.0-rc.1",
3
+ "version": "3.0.0-rc.3",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "files": [