homebridge-tuya-plus 4.1.0-dev.69 → 4.1.0-pr.100.74
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
|
@@ -505,9 +505,10 @@
|
|
|
505
505
|
},
|
|
506
506
|
"dpCurrentTemperature": {
|
|
507
507
|
"type": "integer",
|
|
508
|
+
"title": "Current Temperature DP",
|
|
508
509
|
"placeholder": "3",
|
|
509
510
|
"condition": {
|
|
510
|
-
"functionBody": "return model.devices && model.devices[arrayIndices] && ['Convector', 'SimpleHeater'].includes(model.devices[arrayIndices].type);"
|
|
511
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['Convector', 'SimpleHeater', 'Fan', 'FanLight'].includes(model.devices[arrayIndices].type);"
|
|
511
512
|
}
|
|
512
513
|
},
|
|
513
514
|
"dpLightOn": {
|
|
@@ -555,6 +556,14 @@
|
|
|
555
556
|
"functionBody": "return model.devices && model.devices[arrayIndices] && ['Fan'].includes(model.devices[arrayIndices].type);"
|
|
556
557
|
}
|
|
557
558
|
},
|
|
559
|
+
"directionUseBool": {
|
|
560
|
+
"title": "Use Boolean for Direction",
|
|
561
|
+
"type": "boolean",
|
|
562
|
+
"description": "Sends true/false instead of forward/reverse strings for oscillation/direction.",
|
|
563
|
+
"condition": {
|
|
564
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['Fan', 'FanLight'].includes(model.devices[arrayIndices].type);"
|
|
565
|
+
}
|
|
566
|
+
},
|
|
558
567
|
"maxSpeed": {
|
|
559
568
|
"type": "integer",
|
|
560
569
|
"placeholder": "3",
|
|
@@ -576,6 +585,22 @@
|
|
|
576
585
|
"functionBody": "return model.devices && model.devices[arrayIndices] && ['Fan', 'FanLight'].includes(model.devices[arrayIndices].type);"
|
|
577
586
|
}
|
|
578
587
|
},
|
|
588
|
+
"useStringsFan": {
|
|
589
|
+
"title": "Send fan speed as text",
|
|
590
|
+
"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.",
|
|
591
|
+
"type": "boolean",
|
|
592
|
+
"condition": {
|
|
593
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['FanLight'].includes(model.devices[arrayIndices].type);"
|
|
594
|
+
}
|
|
595
|
+
},
|
|
596
|
+
"useStringsLight": {
|
|
597
|
+
"title": "Send brightness and colour temperature as text",
|
|
598
|
+
"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.",
|
|
599
|
+
"type": "boolean",
|
|
600
|
+
"condition": {
|
|
601
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['FanLight'].includes(model.devices[arrayIndices].type);"
|
|
602
|
+
}
|
|
603
|
+
},
|
|
579
604
|
"singleDpWrites": {
|
|
580
605
|
"title": "Send fan commands one DP at a time",
|
|
581
606
|
"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.",
|
|
@@ -12,23 +12,37 @@ class SimpleFanAccessory extends BaseAccessory {
|
|
|
12
12
|
_registerPlatformAccessory() {
|
|
13
13
|
const {Service} = this.hap;
|
|
14
14
|
this.accessory.addService(Service.Fan, this.device.context.name);
|
|
15
|
+
|
|
16
|
+
if (this.device.context.dpCurrentTemperature) {
|
|
17
|
+
this.accessory.addService(Service.TemperatureSensor, this.device.context.name + ' Temperature');
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
super._registerPlatformAccessory();
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
_registerCharacteristics(dps) {
|
|
19
24
|
const {Service, Characteristic} = this.hap;
|
|
25
|
+
|
|
20
26
|
const serviceFan = this.accessory.getService(Service.Fan);
|
|
21
27
|
this._checkServiceName(serviceFan, this.device.context.name);
|
|
28
|
+
|
|
29
|
+
let serviceTemp;
|
|
30
|
+
if (this.device.context.dpCurrentTemperature) {
|
|
31
|
+
serviceTemp = this.accessory.getService(Service.TemperatureSensor);
|
|
32
|
+
if (serviceTemp) {
|
|
33
|
+
this._checkServiceName(serviceTemp, this.device.context.name + ' Temperature');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
22
37
|
this.dpFanOn = this._getCustomDP(this.device.context.dpFanOn) || '1';
|
|
23
38
|
this.dpRotationSpeed = this._getCustomDP(this.device.context.dpRotationSpeed) || '3';
|
|
24
39
|
this.dpFanDirection = this._getCustomDP(this.device.context.dpFanDirection) || '2';
|
|
25
|
-
// Oscillation is opt-in: SwingMode is only exposed when the fan's boolean
|
|
26
|
-
// swing DP is configured, so existing setups are unchanged (issue #96).
|
|
27
40
|
this.dpSwing = this._getCustomDP(this.device.context.dpSwing);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
|
|
42
|
+
this.dpCurrentTemperature = this._getCustomDP(this.device.context.dpCurrentTemperature);
|
|
43
|
+
|
|
31
44
|
this.noDirection = this._coerceBoolean(this.device.context.noDirection, false);
|
|
45
|
+
this.directionUseBool = this._coerceBoolean(this.device.context.directionUseBool, false);
|
|
32
46
|
|
|
33
47
|
this.maxSpeed = parseInt(this.device.context.maxSpeed) || 3;
|
|
34
48
|
this.fanDefaultSpeed = parseInt(this.device.context.fanDefaultSpeed) || 1;
|
|
@@ -67,6 +81,13 @@ class SimpleFanAccessory extends BaseAccessory {
|
|
|
67
81
|
.onSet(value => this.setSwingMode(value));
|
|
68
82
|
} else this._removeCharacteristic(serviceFan, Characteristic.SwingMode);
|
|
69
83
|
|
|
84
|
+
let characteristicTemperature;
|
|
85
|
+
if (this.dpCurrentTemperature && serviceTemp) {
|
|
86
|
+
characteristicTemperature = serviceTemp.getCharacteristic(Characteristic.CurrentTemperature)
|
|
87
|
+
.updateValue(this._getCurrentTemperature(dps[this.dpCurrentTemperature]))
|
|
88
|
+
.onGet(() => this.getCurrentTemperature());
|
|
89
|
+
}
|
|
90
|
+
|
|
70
91
|
this.device.on('change', (changes, state) => {
|
|
71
92
|
if (changes.hasOwnProperty(this.dpFanOn) && characteristicFanOn.value !== changes[this.dpFanOn])
|
|
72
93
|
characteristicFanOn.updateValue(changes[this.dpFanOn]);
|
|
@@ -84,6 +105,11 @@ class SimpleFanAccessory extends BaseAccessory {
|
|
|
84
105
|
if (characteristicSwingMode.value !== swing) characteristicSwingMode.updateValue(swing);
|
|
85
106
|
}
|
|
86
107
|
|
|
108
|
+
if (characteristicTemperature && changes.hasOwnProperty(this.dpCurrentTemperature)) {
|
|
109
|
+
const temp = this._getCurrentTemperature(changes[this.dpCurrentTemperature]);
|
|
110
|
+
if (characteristicTemperature.value !== temp) characteristicTemperature.updateValue(temp);
|
|
111
|
+
}
|
|
112
|
+
|
|
87
113
|
this.log.debug('SimpleFan changed: ' + JSON.stringify(state));
|
|
88
114
|
});
|
|
89
115
|
}
|
|
@@ -148,11 +174,17 @@ class SimpleFanAccessory extends BaseAccessory {
|
|
|
148
174
|
|
|
149
175
|
_getFanDirection(dp) {
|
|
150
176
|
const {Characteristic} = this.hap;
|
|
177
|
+
if (this.directionUseBool) {
|
|
178
|
+
return dp ? Characteristic.RotationDirection.CLOCKWISE : Characteristic.RotationDirection.COUNTER_CLOCKWISE;
|
|
179
|
+
}
|
|
151
180
|
return (dp === 'reverse') ? Characteristic.RotationDirection.COUNTER_CLOCKWISE : Characteristic.RotationDirection.CLOCKWISE;
|
|
152
181
|
}
|
|
153
182
|
|
|
154
183
|
setFanDirection(value) {
|
|
155
184
|
const {Characteristic} = this.hap;
|
|
185
|
+
if (this.directionUseBool) {
|
|
186
|
+
return this.setStateAsync(this.dpFanDirection, value !== Characteristic.RotationDirection.COUNTER_CLOCKWISE);
|
|
187
|
+
}
|
|
156
188
|
const tuyaVal = (value === Characteristic.RotationDirection.COUNTER_CLOCKWISE) ? 'reverse' : 'forward';
|
|
157
189
|
return this.setStateAsync(this.dpFanDirection, tuyaVal);
|
|
158
190
|
}
|
|
@@ -171,6 +203,15 @@ class SimpleFanAccessory extends BaseAccessory {
|
|
|
171
203
|
return this.setStateAsync(this.dpSwing, value === Characteristic.SwingMode.SWING_ENABLED);
|
|
172
204
|
}
|
|
173
205
|
|
|
206
|
+
getCurrentTemperature() {
|
|
207
|
+
return this._getCurrentTemperature(this.getStateAsync(this.dpCurrentTemperature));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
_getCurrentTemperature(dp) {
|
|
211
|
+
const v = parseFloat(dp);
|
|
212
|
+
return isNaN(v) ? 0 : v;
|
|
213
|
+
}
|
|
214
|
+
|
|
174
215
|
convertRotationSpeedFromTuyaToHomeKit(value) {
|
|
175
216
|
const v = parseInt(value) || 0;
|
|
176
217
|
if (v <= 0) return 0;
|
|
@@ -185,4 +226,4 @@ class SimpleFanAccessory extends BaseAccessory {
|
|
|
185
226
|
}
|
|
186
227
|
}
|
|
187
228
|
|
|
188
|
-
module.exports = SimpleFanAccessory;
|
|
229
|
+
module.exports = SimpleFanAccessory;
|
|
@@ -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-
|
|
3
|
+
"version": "4.1.0-pr.100.74",
|
|
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": {
|
|
@@ -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
|
|