homebridge-tuya-plus 3.14.0-dev.43 → 3.14.0-dev.44
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/lib/TuyaCloudDevice.js +16 -1
- package/package.json +1 -1
- package/test/TuyaCloudDevice.test.js +13 -0
package/lib/TuyaCloudDevice.js
CHANGED
|
@@ -215,7 +215,22 @@ class TuyaCloudDevice extends EventEmitter {
|
|
|
215
215
|
// first 'online' is caught. On any (re)connect we re-read the full state
|
|
216
216
|
// to recover anything missed while the stream was down.
|
|
217
217
|
this.messaging.on('online', () => this._refreshState());
|
|
218
|
-
this.messaging.subscribeDevice(this.context.id, status => this.
|
|
218
|
+
this.messaging.subscribeDevice(this.context.id, status => this._onRealtime(status));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// A realtime (MQTT) update arrived for this device, so it reports its changes
|
|
222
|
+
// over the stream and the post-write catch-up read is redundant — drop any
|
|
223
|
+
// pending one. A device whose reports never arrive over MQTT (some custom
|
|
224
|
+
// controllers — the stream carries nothing for them) gets none of these, so its
|
|
225
|
+
// catch-up stays armed and remains the only way its state reaches HomeKit. This
|
|
226
|
+
// makes the catch-up self-cancelling: it costs an HTTP read only on devices that
|
|
227
|
+
// actually need it.
|
|
228
|
+
_onRealtime(status) {
|
|
229
|
+
if (this._catchupTimers) {
|
|
230
|
+
this._catchupTimers.forEach(t => clearTimeout(t));
|
|
231
|
+
this._catchupTimers = null;
|
|
232
|
+
}
|
|
233
|
+
this._applyStatus(status);
|
|
219
234
|
}
|
|
220
235
|
|
|
221
236
|
async _refreshState() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-tuya-plus",
|
|
3
|
-
"version": "3.14.0-dev.
|
|
3
|
+
"version": "3.14.0-dev.44",
|
|
4
4
|
"description": "A community-maintained Homebridge plugin for controlling Tuya devices in HomeKit. LAN-first, with an optional Tuya Cloud fallback for any device the LAN can't reach.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -342,6 +342,19 @@ describe('TuyaCloudDevice', () => {
|
|
|
342
342
|
dev.stop();
|
|
343
343
|
});
|
|
344
344
|
|
|
345
|
+
test('a realtime update cancels the pending catch-up (no redundant read on MQTT-covered devices)', async () => {
|
|
346
|
+
const api = makeApi();
|
|
347
|
+
api.getShadowProperties = jest.fn().mockResolvedValue([{code: 'switch_1', dp_id: 1, value: false}]);
|
|
348
|
+
const dev = makeDevice(api, null, {key: 'abc'});
|
|
349
|
+
await dev._connect();
|
|
350
|
+
await dev.update({'1': true});
|
|
351
|
+
expect(Array.isArray(dev._catchupTimers)).toBe(true);
|
|
352
|
+
|
|
353
|
+
dev._onRealtime([{code: 'switch_1', value: true}]); // MQTT delivers → catch-up not needed
|
|
354
|
+
expect(dev._catchupTimers).toBeNull();
|
|
355
|
+
dev.stop();
|
|
356
|
+
});
|
|
357
|
+
|
|
345
358
|
test('a refresh reads via the shadow, so a thing-model device whose /status is empty still updates', async () => {
|
|
346
359
|
const api = makeApi();
|
|
347
360
|
let rs = 13;
|