homey-api 1.5.17 → 1.5.20

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.
@@ -9,6 +9,18 @@ class App extends Item {
9
9
  path,
10
10
  body,
11
11
  }) {
12
+ if (typeof method !== 'string') {
13
+ throw new Error('Invalid Path');
14
+ }
15
+
16
+ if (typeof path !== 'string') {
17
+ throw new Error('Invalid Path');
18
+ }
19
+
20
+ if (!path.startsWith('/')) {
21
+ path = `/${path}`;
22
+ }
23
+
12
24
  this.__debug(method, path);
13
25
 
14
26
  return this.homey.call({
@@ -50,9 +50,20 @@ class DeviceCapability extends EventEmitter {
50
50
 
51
51
  // Set Value
52
52
  Object.defineProperty(this, '__value', {
53
- value: device.capabiltiesObj
54
- ? device.capabiltiesObj[this.id]
55
- ? device.capabiltiesObj[this.id].value
53
+ value: device.capabilitiesObj
54
+ ? device.capabilitiesObj[this.id]
55
+ ? device.capabilitiesObj[this.id].value
56
+ : null
57
+ : null,
58
+ enumerable: false,
59
+ writable: true,
60
+ });
61
+
62
+ // Set Last Changed
63
+ Object.defineProperty(this, '__lastChanged', {
64
+ value: device.capabilitiesObj
65
+ ? device.capabilitiesObj[this.id]
66
+ ? device.capabilitiesObj[this.id].lastUpdated
56
67
  : null
57
68
  : null,
58
69
  enumerable: false,
@@ -91,6 +102,7 @@ class DeviceCapability extends EventEmitter {
91
102
 
92
103
  if (value === this.__value) return;
93
104
  this.__value = value;
105
+ this.__lastChanged = new Date(transactionTime);
94
106
 
95
107
  this.__listener(value);
96
108
  }
@@ -103,7 +115,20 @@ class DeviceCapability extends EventEmitter {
103
115
  * @type {boolean|number|string|null}
104
116
  */
105
117
  get value() {
106
- return this.__value;
118
+ return typeof this.__value !== 'undefined'
119
+ ? this.__value
120
+ : null;
121
+ }
122
+
123
+ /**
124
+ * @type {Date|null}
125
+ */
126
+ get lastChanged() {
127
+ return (this.__lastChanged instanceof Date)
128
+ ? this.__lastChanged
129
+ : (typeof this.__lastChanged === 'string')
130
+ ? new Date(this.__lastChanged)
131
+ : null;
107
132
  }
108
133
 
109
134
  /**
@@ -126,6 +151,7 @@ class DeviceCapability extends EventEmitter {
126
151
  });
127
152
 
128
153
  this.__value = value;
154
+ this.__lastChanged = new Date();
129
155
  }
130
156
 
131
157
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "1.5.17",
3
+ "version": "1.5.20",
4
4
  "description": "Homey API",
5
- "main": "src/index.js",
5
+ "main": "index.js",
6
6
  "types": "assets/types/homey-api.d.ts",
7
7
  "scripts": {
8
8
  "test": "echo \"Error: no test specified\" && exit 1",