homebridge-tuya-plus 3.14.0-dev.13 → 3.14.0-dev.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/Changelog.md CHANGED
@@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. This projec
13
13
  * [*] **Fix cloud irrigation valves that could be turned on but not off** — the per-zone write coalescer was dropping any command that matched the last-known `device.state`. Cloud devices never optimistically advance `state` (it only moves once the realtime stream confirms the device), so an "off" issued before the "on" was echoed matched the stale "off" and was discarded — HomeKit showed the zone closed while it kept running. Queued commands are now sent as-is (callers already queue only genuine changes).
14
14
  * [*] **IrrigationSystem: remove the rain sensor.** It never reported reliably on these devices, and bundling a sensor (a different HomeKit category) in the same accessory forced the Home app to fragment the sprinkler into "sub-accessories" — blocking control from the main tile and hiding the system master on/off. The accessory is now a single, clean sprinkler tile (IrrigationSystem + valves + optional battery); any leftover Contact/Leak sensor service from a previous build is removed automatically on restart. The `noRainSensor`, `rainSensorType`, `rainInverted`, `dpRain` and `rainOnValue` options are gone.
15
15
  * [*] **IrrigationSystem: add the HAP Service Label service for multi-valve controllers** — an accessory that exposes a collection of same-type services (more than one `Valve`) must include a `ServiceLabel` service to anchor each valve's `ServiceLabelIndex`. It was missing, so stricter Home app clients (notably iOS) scattered the zones as separate tiles instead of nesting them under the single irrigation tile. The service is added automatically (with the Arabic-numerals namespace) whenever there is more than one valve; user-set zone names still take precedence.
16
+ * [*] **IrrigationSystem: stop the valve toggle flickering after a press** — tapping a zone briefly snapped back to the old state before settling on the new one. The `Active` getters returned the raw `device.state`, which (for cloud devices) only advances once the realtime stream echoes the write back, so a read in that window reported the pre-press value. The getters now report the value HomeKit already shows (optimistic on press, then confirmed/corrected by device-side change events); they still surface "No Response" while disconnected.
16
17
 
17
18
  ## 2.0.1 (2021-03-25)
18
19
  This update includes the following changes:
@@ -238,7 +238,7 @@ class IrrigationSystemAccessory extends BaseAccessory {
238
238
 
239
239
  this._systemActiveChar = irrigation.getCharacteristic(Characteristic.Active)
240
240
  .updateValue(this._anyValveOn() ? Characteristic.Active.ACTIVE : Characteristic.Active.INACTIVE)
241
- .onGet(() => this._anyValveOn() ? Characteristic.Active.ACTIVE : Characteristic.Active.INACTIVE)
241
+ .onGet(() => this._reportCached(this._systemActiveChar))
242
242
  .onSet(value => this._setSystemActive(value));
243
243
 
244
244
  this._systemInUseChar = irrigation.getCharacteristic(Characteristic.InUse)
@@ -281,10 +281,10 @@ class IrrigationSystemAccessory extends BaseAccessory {
281
281
  .updateValue(0)
282
282
  .onGet(() => this._valveRemaining(cfg));
283
283
 
284
- valve.getCharacteristic(Characteristic.Active)
284
+ const activeChar = valve.getCharacteristic(Characteristic.Active)
285
285
  .updateValue(on ? Characteristic.Active.ACTIVE : Characteristic.Active.INACTIVE)
286
- .onGet(() => (this.getStateAsync(cfg.dp) ? 1 : 0))
287
286
  .onSet(value => this._setValveActive(cfg, value));
287
+ activeChar.onGet(() => this._reportCached(activeChar));
288
288
 
289
289
  valve.getCharacteristic(Characteristic.InUse)
290
290
  .updateValue(on ? Characteristic.InUse.IN_USE : Characteristic.InUse.NOT_IN_USE);
@@ -364,6 +364,19 @@ class IrrigationSystemAccessory extends BaseAccessory {
364
364
  if (valveChanged) this._syncAggregate();
365
365
  }
366
366
 
367
+ // onGet handler for the system / valve Active characteristics. Returns the
368
+ // value HomeKit already shows — the optimistic value written on press and
369
+ // then confirmed (or corrected) by device-side change events — rather than
370
+ // the raw `device.state`. Cloud devices don't advance `device.state` until
371
+ // the realtime stream echoes the write back, so reading it here returned the
372
+ // pre-press value for a moment and made the Home app toggle visibly flicker
373
+ // back to the old state before settling. Throwing while disconnected keeps
374
+ // the HomeKit "No Response" behaviour.
375
+ _reportCached(char) {
376
+ if (!this.device.connected) throw new Error('Not connected');
377
+ return char.value;
378
+ }
379
+
367
380
  /* ------------------------------------------------------------------ *
368
381
  * Valve activation + timer logic
369
382
  * ------------------------------------------------------------------ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-tuya-plus",
3
- "version": "3.14.0-dev.13",
3
+ "version": "3.14.0-dev.14",
4
4
  "description": "A community-maintained Homebridge plugin for controlling Tuya devices locally over LAN. Includes new features, fixes, and updated device support.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -298,6 +298,38 @@ describe('IrrigationSystemAccessory — valve activation & timer', () => {
298
298
  jest.advanceTimersByTime(600 * 1000);
299
299
  expect(device.update.mock.calls.length).toBe(calls);
300
300
  });
301
+
302
+ test('valve Active onGet reports the optimistic value, not the lagging device state (no flicker)', () => {
303
+ // Cloud devices don't advance device.state until the realtime stream
304
+ // echoes the write back. Emulate that (update is a no-op on state) and
305
+ // confirm a freshly-pressed valve keeps reading ON instead of briefly
306
+ // reverting to the pre-press value.
307
+ const { accessory, device } = makeHarness({ '1': false }, { defaultDuration: 0 });
308
+ device.update.mockImplementation(() => true);
309
+ const v = valve(accessory, 1);
310
+
311
+ v.getCharacteristic(Characteristic.Active).triggerSet(1);
312
+ jest.advanceTimersByTime(500);
313
+
314
+ expect(device.state['1']).toBe(false); // not echoed yet
315
+ expect(v.getCharacteristic(Characteristic.Active).triggerGet()).toBe(Characteristic.Active.ACTIVE);
316
+ });
317
+
318
+ test('system Active onGet reports the cached aggregate, not the lagging device state', () => {
319
+ const { accessory, device } = makeHarness({ '1': false, '2': false }, { defaultDuration: 0 });
320
+ device.update.mockImplementation(() => true);
321
+ valve(accessory, 1).getCharacteristic(Characteristic.Active).triggerSet(1);
322
+ jest.advanceTimersByTime(500);
323
+
324
+ expect(irrigation(accessory).getCharacteristic(Characteristic.Active).triggerGet())
325
+ .toBe(Characteristic.Active.ACTIVE);
326
+ });
327
+
328
+ test('Active onGet still throws while disconnected (HomeKit shows "No Response")', () => {
329
+ const { accessory, device } = makeHarness({ '1': false });
330
+ device.connected = false;
331
+ expect(() => valve(accessory, 1).getCharacteristic(Characteristic.Active).triggerGet()).toThrow();
332
+ });
301
333
  });
302
334
 
303
335
  describe('IrrigationSystemAccessory — write batching (one Tuya command)', () => {