homey-api 1.5.13 → 1.5.14
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.
- package/assets/specifications/HomeyAPIV2.json +505 -425
- package/assets/types/homey-api.d.ts +545 -300
- package/assets/types/homey-api.private.d.ts +572 -276
- package/lib/HomeyAPI/HomeyAPIV2/Device.js +34 -2
- package/lib/HomeyAPI/HomeyAPIV2/DeviceCapability.js +1 -0
- package/lib/HomeyAPI/HomeyAPIV2/Manager.js +11 -2
- package/lib/HomeyAPI/HomeyAPIV2.js +6 -2
- package/package.json +1 -1
|
@@ -114,7 +114,7 @@ class Device extends Item {
|
|
|
114
114
|
this.__debug('connect');
|
|
115
115
|
|
|
116
116
|
if (!this.io) {
|
|
117
|
-
this.io =
|
|
117
|
+
this.io = this.homey.subscribe(this.uri, {
|
|
118
118
|
onConnect: () => {
|
|
119
119
|
this.__debug('onConnect');
|
|
120
120
|
this.__connected = true;
|
|
@@ -123,6 +123,34 @@ class Device extends Item {
|
|
|
123
123
|
this.__debug('onDisconnect');
|
|
124
124
|
this.__connected = false;
|
|
125
125
|
},
|
|
126
|
+
onReconnect: () => {
|
|
127
|
+
this.__debug('onDisconnect');
|
|
128
|
+
|
|
129
|
+
const capabilityInstances = this.__capabilityInstances;
|
|
130
|
+
if (Object.keys(capabilityInstances).length > 0) {
|
|
131
|
+
// Get the device's latest values
|
|
132
|
+
// TODO: Optimize this with `getDevices()` when >1 device has >0 capability instances.
|
|
133
|
+
this.manager.getDevice({
|
|
134
|
+
id: this.id,
|
|
135
|
+
}).then(async device => {
|
|
136
|
+
Object.entries(capabilityInstances).forEach(([capabilityId, capabilityInstance]) => {
|
|
137
|
+
const value = device.capabilitiesObj
|
|
138
|
+
? typeof device.capabilitiesObj[capabilityId] !== 'undefined'
|
|
139
|
+
? device.capabilitiesObj[capabilityId].value
|
|
140
|
+
: null
|
|
141
|
+
: null;
|
|
142
|
+
|
|
143
|
+
capabilityInstance.__onCapabilityValue({
|
|
144
|
+
capabilityId,
|
|
145
|
+
value,
|
|
146
|
+
transactionId: Util.uuid(),
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
})
|
|
150
|
+
// eslint-disable-next-line no-console
|
|
151
|
+
.catch(err => console.error(`Device[${this.id}].onReconnectError:`, err));
|
|
152
|
+
}
|
|
153
|
+
},
|
|
126
154
|
onEvent: (event, data) => {
|
|
127
155
|
// // Fire event listeners
|
|
128
156
|
if (Array.isArray(this.__listeners[event])) {
|
|
@@ -131,13 +159,17 @@ class Device extends Item {
|
|
|
131
159
|
},
|
|
132
160
|
});
|
|
133
161
|
}
|
|
162
|
+
|
|
163
|
+
await this.io;
|
|
134
164
|
}
|
|
135
165
|
|
|
136
166
|
async disconnect() {
|
|
137
167
|
this.__debug('disconnect');
|
|
138
168
|
|
|
139
169
|
if (this.io) {
|
|
140
|
-
this.io
|
|
170
|
+
this.io
|
|
171
|
+
.then(io => io.unsubscribe())
|
|
172
|
+
.catch(err => this.__debug('Error Disconnecting:', err));
|
|
141
173
|
}
|
|
142
174
|
}
|
|
143
175
|
|
|
@@ -384,7 +384,7 @@ class Manager extends EventEmitter {
|
|
|
384
384
|
this.__debug('connect');
|
|
385
385
|
|
|
386
386
|
if (!this.io) {
|
|
387
|
-
this.io =
|
|
387
|
+
this.io = this.homey.subscribe(this.uri, {
|
|
388
388
|
onConnect: () => {
|
|
389
389
|
this.__debug('onConnect');
|
|
390
390
|
this.__connected = true;
|
|
@@ -457,6 +457,8 @@ class Manager extends EventEmitter {
|
|
|
457
457
|
},
|
|
458
458
|
});
|
|
459
459
|
}
|
|
460
|
+
|
|
461
|
+
await this.io;
|
|
460
462
|
}
|
|
461
463
|
|
|
462
464
|
/**
|
|
@@ -467,11 +469,14 @@ class Manager extends EventEmitter {
|
|
|
467
469
|
this.__debug('disconnect');
|
|
468
470
|
|
|
469
471
|
if (this.io) {
|
|
470
|
-
this.io
|
|
472
|
+
this.io
|
|
473
|
+
.then(io => io.unsubscribe())
|
|
474
|
+
.catch(err => this.__debug('Error Disconnecting:', err));
|
|
471
475
|
}
|
|
472
476
|
}
|
|
473
477
|
|
|
474
478
|
destroy() {
|
|
479
|
+
// Clear cache
|
|
475
480
|
for (const id of Object.keys(this.__cache)) {
|
|
476
481
|
this.__cache[id] = {};
|
|
477
482
|
}
|
|
@@ -480,6 +485,10 @@ class Manager extends EventEmitter {
|
|
|
480
485
|
this.__cacheAllComplete[id] = false;
|
|
481
486
|
}
|
|
482
487
|
|
|
488
|
+
// Remove all event listeners
|
|
489
|
+
this.removeAllListeners();
|
|
490
|
+
|
|
491
|
+
// Disconnect from Socket.io
|
|
483
492
|
this.disconnect().catch(() => { });
|
|
484
493
|
}
|
|
485
494
|
|
|
@@ -184,9 +184,12 @@ class HomeyAPIV2 extends HomeyAPI {
|
|
|
184
184
|
|
|
185
185
|
// Don't discover, just set the only strategy
|
|
186
186
|
if (Object.keys(urls).length === 1) {
|
|
187
|
+
this.__baseUrl = Object.values(urls)[0];
|
|
188
|
+
this.__strategyId = Object.keys(urls)[0];
|
|
189
|
+
|
|
187
190
|
return {
|
|
188
|
-
|
|
189
|
-
|
|
191
|
+
baseUrl: this.__baseUrl,
|
|
192
|
+
strategyId: this.__strategyId,
|
|
190
193
|
};
|
|
191
194
|
}
|
|
192
195
|
|
|
@@ -526,6 +529,7 @@ class HomeyAPIV2 extends HomeyAPI {
|
|
|
526
529
|
|
|
527
530
|
return {
|
|
528
531
|
unsubscribe: () => {
|
|
532
|
+
this.__ioNamespace.emit('unsubscribe', uri);
|
|
529
533
|
this.__ioNamespace.removeListener(uri, __onEvent);
|
|
530
534
|
this.__io.removeListener('disconnect', __onDisconnect);
|
|
531
535
|
this.__io.removeListener('reconnect', __onReconnect);
|