homebridge-tuya-plus 4.1.0-dev.69 → 4.1.0-dev.76
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/config.schema.json
CHANGED
|
@@ -576,6 +576,22 @@
|
|
|
576
576
|
"functionBody": "return model.devices && model.devices[arrayIndices] && ['Fan', 'FanLight'].includes(model.devices[arrayIndices].type);"
|
|
577
577
|
}
|
|
578
578
|
},
|
|
579
|
+
"useStringsFan": {
|
|
580
|
+
"title": "Send fan speed as text",
|
|
581
|
+
"description": "Overrides \"useStrings\" for the fan only. Set this when the fan's speed data point wants a different value type than the light's brightness and colour temperature. Defaults to whatever \"useStrings\" is.",
|
|
582
|
+
"type": "boolean",
|
|
583
|
+
"condition": {
|
|
584
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['FanLight'].includes(model.devices[arrayIndices].type);"
|
|
585
|
+
}
|
|
586
|
+
},
|
|
587
|
+
"useStringsLight": {
|
|
588
|
+
"title": "Send brightness and colour temperature as text",
|
|
589
|
+
"description": "Overrides \"useStrings\" for the light only. Set this when the light's data points want a different value type than the fan's speed. Defaults to whatever \"useStrings\" is.",
|
|
590
|
+
"type": "boolean",
|
|
591
|
+
"condition": {
|
|
592
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['FanLight'].includes(model.devices[arrayIndices].type);"
|
|
593
|
+
}
|
|
594
|
+
},
|
|
579
595
|
"singleDpWrites": {
|
|
580
596
|
"title": "Send fan commands one DP at a time",
|
|
581
597
|
"description": "Enable if turning the fan on or changing its speed is silently ignored. Some fan firmwares reject LAN packets that carry more than one data point, so the fan on/off and speed are sent as separate packets instead of combined.",
|
|
@@ -76,6 +76,8 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
76
76
|
this.fanCurrentSpeed = 0;
|
|
77
77
|
this.useStrings = this._coerceBoolean(this.device.context.useStrings, true);
|
|
78
78
|
this.singleDpWrites = this._coerceBoolean(this.device.context.singleDpWrites, false);
|
|
79
|
+
this.useStringsFan = this._coerceBoolean(this.device.context.useStringsFan, this.useStrings);
|
|
80
|
+
this.useStringsLight = this._coerceBoolean(this.device.context.useStringsLight, this.useStrings);
|
|
79
81
|
|
|
80
82
|
const characteristicFanOn = serviceFan.getCharacteristic(Characteristic.On)
|
|
81
83
|
.updateValue(this._getFanOn(dps[this.dpFanOn]))
|
|
@@ -184,7 +186,7 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
184
186
|
const target = this.fanCurrentSpeed === 0 ? this.fanDefaultSpeed : this.fanCurrentSpeed;
|
|
185
187
|
const payload = {
|
|
186
188
|
[this.dpFanOn]: true,
|
|
187
|
-
[this.dpRotationSpeed]: this.
|
|
189
|
+
[this.dpRotationSpeed]: this.useStringsFan ? target.toString() : target
|
|
188
190
|
};
|
|
189
191
|
return this._writeFanState(payload);
|
|
190
192
|
}
|
|
@@ -198,7 +200,7 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
198
200
|
if (value === 0) {
|
|
199
201
|
const payload = {
|
|
200
202
|
[this.dpFanOn]: false,
|
|
201
|
-
[this.dpRotationSpeed]: this.
|
|
203
|
+
[this.dpRotationSpeed]: this.useStringsFan ? this.fanDefaultSpeed.toString() : this.fanDefaultSpeed
|
|
202
204
|
};
|
|
203
205
|
return this._writeFanState(payload);
|
|
204
206
|
} else {
|
|
@@ -206,7 +208,7 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
206
208
|
this.fanCurrentSpeed = tuya;
|
|
207
209
|
const payload = {
|
|
208
210
|
[this.dpFanOn]: true,
|
|
209
|
-
[this.dpRotationSpeed]: this.
|
|
211
|
+
[this.dpRotationSpeed]: this.useStringsFan ? tuya.toString() : tuya
|
|
210
212
|
};
|
|
211
213
|
return this._writeFanState(payload);
|
|
212
214
|
}
|
|
@@ -250,7 +252,7 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
250
252
|
|
|
251
253
|
setBrightness(value) {
|
|
252
254
|
const tuya = this.convertBrightnessFromHomeKitToTuya(value);
|
|
253
|
-
return this.setStateAsync(this.dpBrightness, this.
|
|
255
|
+
return this.setStateAsync(this.dpBrightness, this.useStringsLight ? tuya.toString() : tuya);
|
|
254
256
|
}
|
|
255
257
|
|
|
256
258
|
getColorTemp() {
|
|
@@ -259,7 +261,7 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
259
261
|
|
|
260
262
|
setColorTemp(value) {
|
|
261
263
|
const tuya = this.convertColorTempFromHomeKitToTuya(value);
|
|
262
|
-
return this.setStateAsync(this.dpColorTemp, this.
|
|
264
|
+
return this.setStateAsync(this.dpColorTemp, this.useStringsLight ? tuya.toString() : tuya);
|
|
263
265
|
}
|
|
264
266
|
|
|
265
267
|
convertRotationSpeedFromTuyaToHomeKit(value) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-tuya-plus",
|
|
3
|
-
"version": "4.1.0-dev.
|
|
3
|
+
"version": "4.1.0-dev.76",
|
|
4
4
|
"description": "A community-maintained Homebridge plugin for controlling Tuya devices locally over LAN, with an optional Tuya Cloud fallback for whatever the LAN can't reach. Includes new features, fixes, and updated device support. PRs welcome: if it runs, it ships (almost).",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
37
37
|
"homebridge-plugin",
|
|
38
|
+
"supports-hap",
|
|
38
39
|
"homebridge",
|
|
39
40
|
"homebridge-tuya",
|
|
40
41
|
"tuya"
|
|
@@ -16,11 +16,14 @@ function makeFanLight(state = {}, context = {}) {
|
|
|
16
16
|
instance.dpRotationSpeed = '62';
|
|
17
17
|
instance.dpFanDirection = device.context.dpFanDirection || '63';
|
|
18
18
|
instance.dpLightOn = device.context.dpLightOn || '20';
|
|
19
|
+
instance.dpBrightness = '22';
|
|
19
20
|
instance.dpColorTemp = '23';
|
|
20
21
|
instance.maxSpeed = parseInt(device.context.maxSpeed) || 6;
|
|
21
22
|
instance.fanDefaultSpeed = parseInt(device.context.fanDefaultSpeed) || 1;
|
|
22
23
|
instance.fanCurrentSpeed = 0;
|
|
23
24
|
instance.useStrings = instance._coerceBoolean(device.context.useStrings, true);
|
|
25
|
+
instance.useStringsFan = instance._coerceBoolean(device.context.useStringsFan, instance.useStrings);
|
|
26
|
+
instance.useStringsLight = instance._coerceBoolean(device.context.useStringsLight, instance.useStrings);
|
|
24
27
|
instance.singleDpWrites = instance._coerceBoolean(device.context.singleDpWrites, false);
|
|
25
28
|
instance.lightUseEnum = instance._coerceBoolean(device.context.lightUseEnum, false);
|
|
26
29
|
instance.lightOnCommand = device.context.lightOnCommand || 'On';
|
|
@@ -415,4 +418,72 @@ describe('SimpleFanLightAccessory.getColorTemp / setColorTemp', () => {
|
|
|
415
418
|
await expect(instance.setColorTemp(370)).rejects.toBeInstanceOf(HAP.HapStatusError);
|
|
416
419
|
expect(device.update).not.toHaveBeenCalled();
|
|
417
420
|
});
|
|
421
|
+
|
|
418
422
|
});
|
|
423
|
+
|
|
424
|
+
// ---------------------------------------------------------------------------
|
|
425
|
+
// useStringsFan / useStringsLight override useStrings per side, and inherit it
|
|
426
|
+
// when unset so configs written before the split keep their old behaviour.
|
|
427
|
+
// ---------------------------------------------------------------------------
|
|
428
|
+
describe('SimpleFanLightAccessory — useStringsFan / useStringsLight', () => {
|
|
429
|
+
test('both sides inherit useStrings: false when neither override is set', () => {
|
|
430
|
+
const fan = makeFanLight({ '60': false, '62': 1 }, { useStrings: false });
|
|
431
|
+
fan.instance.setSpeed(100);
|
|
432
|
+
expect(fan.device.update).toHaveBeenCalledWith({ '60': true, '62': 6 });
|
|
433
|
+
|
|
434
|
+
const light = makeFanLight({ '22': 500, '23': 500 }, { useStrings: false });
|
|
435
|
+
light.instance.setBrightness(100);
|
|
436
|
+
light.instance.setColorTemp(154);
|
|
437
|
+
expect(payloads(light.device)).toEqual([{ '22': 1000 }, { '23': 1000 }]);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test('both sides inherit the useStrings default (strings) when nothing is set', () => {
|
|
441
|
+
const fan = makeFanLight({ '60': false, '62': 1 });
|
|
442
|
+
fan.instance.setSpeed(100);
|
|
443
|
+
expect(fan.device.update).toHaveBeenCalledWith({ '60': true, '62': '6' });
|
|
444
|
+
|
|
445
|
+
const light = makeFanLight({ '22': 500, '23': 500 });
|
|
446
|
+
light.instance.setBrightness(100);
|
|
447
|
+
light.instance.setColorTemp(154);
|
|
448
|
+
expect(payloads(light.device)).toEqual([{ '22': '1000' }, { '23': '1000' }]);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
test('useStringsFan overrides the fan only, leaving the light on useStrings', () => {
|
|
452
|
+
const { instance, device } = makeFanLight(
|
|
453
|
+
{ '60': false, '62': 1, '22': 500, '23': 500 },
|
|
454
|
+
{ useStrings: true, useStringsFan: false }
|
|
455
|
+
);
|
|
456
|
+
instance.setSpeed(100);
|
|
457
|
+
instance.setBrightness(100);
|
|
458
|
+
instance.setColorTemp(154);
|
|
459
|
+
expect(payloads(device)).toEqual([{ '60': true, '62': 6 }, { '22': '1000' }, { '23': '1000' }]);
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
test('useStringsLight overrides the light only, leaving the fan on useStrings', () => {
|
|
463
|
+
const { instance, device } = makeFanLight(
|
|
464
|
+
{ '60': false, '62': 1, '22': 500, '23': 500 },
|
|
465
|
+
{ useStrings: false, useStringsLight: true }
|
|
466
|
+
);
|
|
467
|
+
instance.setSpeed(100);
|
|
468
|
+
instance.setBrightness(100);
|
|
469
|
+
instance.setColorTemp(154);
|
|
470
|
+
expect(payloads(device)).toEqual([{ '60': true, '62': 6 }, { '22': '1000' }, { '23': '1000' }]);
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
test('accepts the string form of the overrides, as hand-written configs produce', () => {
|
|
474
|
+
const { instance, device } = makeFanLight(
|
|
475
|
+
{ '60': false, '62': 1, '23': 500 },
|
|
476
|
+
{ useStrings: 'true', useStringsFan: 'false', useStringsLight: 'true' }
|
|
477
|
+
);
|
|
478
|
+
instance.setSpeed(100);
|
|
479
|
+
instance.setColorTemp(154);
|
|
480
|
+
expect(payloads(device)).toEqual([{ '60': true, '62': 6 }, { '23': '1000' }]);
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
test('setFanOn from off applies useStringsFan to the default speed', () => {
|
|
484
|
+
const { instance, device } = makeFanLight({ '60': false, '62': 1 }, { useStrings: true, useStringsFan: false });
|
|
485
|
+
instance.setFanOn(true);
|
|
486
|
+
expect(device.update).toHaveBeenCalledWith({ '60': true, '62': 1 });
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
|
|
@@ -877,9 +877,14 @@ These are accessories that combine fan and lighting control in one device. Suppo
|
|
|
877
877
|
/* Speed used when the fan is switched on from off. Default: 1 */
|
|
878
878
|
"fanDefaultSpeed": 1,
|
|
879
879
|
|
|
880
|
-
/* Send
|
|
880
|
+
/* Send values as strings rather than numbers, for both the fan speed and
|
|
881
|
+
the light's brightness / colour temperature. Default: true */
|
|
881
882
|
"useStrings": true,
|
|
882
883
|
|
|
884
|
+
/* Override "useStrings" for the fan speed alone. Defaults to "useStrings"
|
|
885
|
+
(see the note below on fans that want a different type per side) */
|
|
886
|
+
"useStringsFan": true,
|
|
887
|
+
|
|
883
888
|
/* Send each data point in its own packet instead of combining fan
|
|
884
889
|
power + speed into one. Default: false (see note below) */
|
|
885
890
|
"singleDpWrites": false,
|
|
@@ -908,7 +913,27 @@ These are accessories that combine fan and lighting control in one device. Suppo
|
|
|
908
913
|
"minWhiteColor": 154,
|
|
909
914
|
|
|
910
915
|
/* Warmest colour temperature, in mireds (~2700 K). Default: 370 */
|
|
911
|
-
"maxWhiteColor": 370
|
|
916
|
+
"maxWhiteColor": 370,
|
|
917
|
+
|
|
918
|
+
/* Override "useStrings" for the light alone. Defaults to "useStrings" */
|
|
919
|
+
"useStringsLight": true
|
|
920
|
+
}
|
|
921
|
+
```
|
|
922
|
+
|
|
923
|
+
#### When the fan and the light want different value types
|
|
924
|
+
|
|
925
|
+
On most fans a single `useStrings` covers the whole device. Some (e.g. the **Treatlife DS03**) disagree between the two halves — the speed data point takes one type and the light's brightness / colour-temperature data points take the other — which shows up as one half of the accessory working while the other silently ignores commands. Set `useStringsFan` and/or `useStringsLight` to override `useStrings` for just that side; whichever you leave out keeps following `useStrings`, so existing configs are unaffected.
|
|
926
|
+
|
|
927
|
+
```json5
|
|
928
|
+
{
|
|
929
|
+
"type": "FanLight",
|
|
930
|
+
"name": "My Fan with Light",
|
|
931
|
+
"id": "032000123456789abcde",
|
|
932
|
+
"key": "0123456789abcdef",
|
|
933
|
+
|
|
934
|
+
/* Speed wants a plain number, brightness and colour temperature want strings */
|
|
935
|
+
"useStringsFan": false,
|
|
936
|
+
"useStringsLight": true
|
|
912
937
|
}
|
|
913
938
|
```
|
|
914
939
|
|