homebridge-tuya-plus 4.1.0-dev.68 → 4.1.0-dev.71
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
|
@@ -531,7 +531,7 @@
|
|
|
531
531
|
"functionBody": "return model.devices && model.devices[arrayIndices] && ['Convector', 'Fan', 'FanLight'].includes(model.devices[arrayIndices].type);"
|
|
532
532
|
}
|
|
533
533
|
},
|
|
534
|
-
"
|
|
534
|
+
"dpFanDirection": {
|
|
535
535
|
"type": "integer",
|
|
536
536
|
"placeholder": "63",
|
|
537
537
|
"condition": {
|
|
@@ -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.",
|
|
@@ -585,6 +601,51 @@
|
|
|
585
601
|
"functionBody": "return model.devices && model.devices[arrayIndices] && ['FanLight'].includes(model.devices[arrayIndices].type);"
|
|
586
602
|
}
|
|
587
603
|
},
|
|
604
|
+
"lightUseEnum": {
|
|
605
|
+
"title": "Light uses On/Off text values",
|
|
606
|
+
"description": "Enable if the light appears in HomeKit but toggling it does nothing. Some fans type the light data point as an enum of text values (e.g. \"On\"/\"Off\") rather than a boolean.",
|
|
607
|
+
"type": "boolean",
|
|
608
|
+
"placeholder": false,
|
|
609
|
+
"condition": {
|
|
610
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['FanLight'].includes(model.devices[arrayIndices].type);"
|
|
611
|
+
}
|
|
612
|
+
},
|
|
613
|
+
"lightOnCommand": {
|
|
614
|
+
"title": "Light \"on\" value",
|
|
615
|
+
"description": "The text value sent to turn the light on when \"Light uses On/Off text values\" is enabled.",
|
|
616
|
+
"type": "string",
|
|
617
|
+
"placeholder": "On",
|
|
618
|
+
"condition": {
|
|
619
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['FanLight'].includes(model.devices[arrayIndices].type) && model.devices[arrayIndices].lightUseEnum;"
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
"lightOffCommand": {
|
|
623
|
+
"title": "Light \"off\" value",
|
|
624
|
+
"description": "The text value sent to turn the light off when \"Light uses On/Off text values\" is enabled.",
|
|
625
|
+
"type": "string",
|
|
626
|
+
"placeholder": "Off",
|
|
627
|
+
"condition": {
|
|
628
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['FanLight'].includes(model.devices[arrayIndices].type) && model.devices[arrayIndices].lightUseEnum;"
|
|
629
|
+
}
|
|
630
|
+
},
|
|
631
|
+
"directionForwardCommand": {
|
|
632
|
+
"title": "Forward direction value",
|
|
633
|
+
"description": "The value sent for the normal/forward direction. Set this when direction lives on a shared \"mode\" data point (e.g. Windmode \"Normal\").",
|
|
634
|
+
"type": "string",
|
|
635
|
+
"placeholder": "forward",
|
|
636
|
+
"condition": {
|
|
637
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['FanLight'].includes(model.devices[arrayIndices].type);"
|
|
638
|
+
}
|
|
639
|
+
},
|
|
640
|
+
"directionReverseCommand": {
|
|
641
|
+
"title": "Reverse direction value",
|
|
642
|
+
"description": "The value sent for the reverse direction. Set this when direction lives on a shared \"mode\" data point (e.g. Windmode \"Reverse\").",
|
|
643
|
+
"type": "string",
|
|
644
|
+
"placeholder": "reverse",
|
|
645
|
+
"condition": {
|
|
646
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && ['FanLight'].includes(model.devices[arrayIndices].type);"
|
|
647
|
+
}
|
|
648
|
+
},
|
|
588
649
|
"dpChildLock": {
|
|
589
650
|
"type": "integer",
|
|
590
651
|
"placeholder": "6",
|
|
@@ -46,6 +46,19 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
46
46
|
this.useBrightness = this._coerceBoolean(this.device.context.useBrightness, true);
|
|
47
47
|
this.useColorTemp = this._coerceBoolean(this.device.context.useColorTemp, true);
|
|
48
48
|
|
|
49
|
+
// Some fans (e.g. the Orient AEON V.C.) type the light DP as an enum of
|
|
50
|
+
// 'On'/'Off' strings rather than a boolean. When lightUseEnum is set we
|
|
51
|
+
// read/write those command strings; otherwise the DP stays a plain bool.
|
|
52
|
+
this.lightUseEnum = this._coerceBoolean(this.device.context.lightUseEnum, false);
|
|
53
|
+
this.lightOnCommand = this.device.context.lightOnCommand || 'On';
|
|
54
|
+
this.lightOffCommand = this.device.context.lightOffCommand || 'Off';
|
|
55
|
+
|
|
56
|
+
// The direction DP's forward/reverse command strings are configurable so
|
|
57
|
+
// fans that carry direction on a shared "mode" DP (e.g. Windmode
|
|
58
|
+
// 'Normal'/'Reverse') can be mapped onto HomeKit's RotationDirection.
|
|
59
|
+
this.directionForwardCommand = this.device.context.directionForwardCommand || 'forward';
|
|
60
|
+
this.directionReverseCommand = this.device.context.directionReverseCommand || 'reverse';
|
|
61
|
+
|
|
49
62
|
let minWhiteColor = parseInt(this.device.context.minWhiteColor);
|
|
50
63
|
let maxWhiteColor = parseInt(this.device.context.maxWhiteColor);
|
|
51
64
|
if (isNaN(minWhiteColor)) minWhiteColor = DEFAULT_MIN_WHITE_COLOR;
|
|
@@ -63,6 +76,8 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
63
76
|
this.fanCurrentSpeed = 0;
|
|
64
77
|
this.useStrings = this._coerceBoolean(this.device.context.useStrings, true);
|
|
65
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);
|
|
66
81
|
|
|
67
82
|
const characteristicFanOn = serviceFan.getCharacteristic(Characteristic.On)
|
|
68
83
|
.updateValue(this._getFanOn(dps[this.dpFanOn]))
|
|
@@ -126,7 +141,8 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
126
141
|
}
|
|
127
142
|
|
|
128
143
|
if (changes.hasOwnProperty(this.dpLightOn) && characteristicLightOn) {
|
|
129
|
-
|
|
144
|
+
const lightOn = this._getLightOn(changes[this.dpLightOn]);
|
|
145
|
+
if (characteristicLightOn.value !== lightOn) characteristicLightOn.updateValue(lightOn);
|
|
130
146
|
}
|
|
131
147
|
|
|
132
148
|
if (changes.hasOwnProperty(this.dpBrightness) && characteristicBrightness) {
|
|
@@ -170,7 +186,7 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
170
186
|
const target = this.fanCurrentSpeed === 0 ? this.fanDefaultSpeed : this.fanCurrentSpeed;
|
|
171
187
|
const payload = {
|
|
172
188
|
[this.dpFanOn]: true,
|
|
173
|
-
[this.dpRotationSpeed]: this.
|
|
189
|
+
[this.dpRotationSpeed]: this.useStringsFan ? target.toString() : target
|
|
174
190
|
};
|
|
175
191
|
return this._writeFanState(payload);
|
|
176
192
|
}
|
|
@@ -184,7 +200,7 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
184
200
|
if (value === 0) {
|
|
185
201
|
const payload = {
|
|
186
202
|
[this.dpFanOn]: false,
|
|
187
|
-
[this.dpRotationSpeed]: this.
|
|
203
|
+
[this.dpRotationSpeed]: this.useStringsFan ? this.fanDefaultSpeed.toString() : this.fanDefaultSpeed
|
|
188
204
|
};
|
|
189
205
|
return this._writeFanState(payload);
|
|
190
206
|
} else {
|
|
@@ -192,7 +208,7 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
192
208
|
this.fanCurrentSpeed = tuya;
|
|
193
209
|
const payload = {
|
|
194
210
|
[this.dpFanOn]: true,
|
|
195
|
-
[this.dpRotationSpeed]: this.
|
|
211
|
+
[this.dpRotationSpeed]: this.useStringsFan ? tuya.toString() : tuya
|
|
196
212
|
};
|
|
197
213
|
return this._writeFanState(payload);
|
|
198
214
|
}
|
|
@@ -204,13 +220,13 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
204
220
|
|
|
205
221
|
_getFanDirection(dp) {
|
|
206
222
|
const {Characteristic} = this.hap;
|
|
207
|
-
return dp ===
|
|
223
|
+
return dp === this.directionReverseCommand
|
|
208
224
|
? Characteristic.RotationDirection.COUNTER_CLOCKWISE
|
|
209
225
|
: Characteristic.RotationDirection.CLOCKWISE;
|
|
210
226
|
}
|
|
211
227
|
|
|
212
228
|
setFanDirection(value) {
|
|
213
|
-
const tuyaVal = (value === 1) ?
|
|
229
|
+
const tuyaVal = (value === 1) ? this.directionReverseCommand : this.directionForwardCommand;
|
|
214
230
|
return this.setStateAsync(this.dpFanDirection, tuyaVal);
|
|
215
231
|
}
|
|
216
232
|
|
|
@@ -219,10 +235,14 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
219
235
|
}
|
|
220
236
|
|
|
221
237
|
_getLightOn(dp) {
|
|
238
|
+
if (this.lightUseEnum) return dp === this.lightOnCommand;
|
|
222
239
|
return !!dp;
|
|
223
240
|
}
|
|
224
241
|
|
|
225
242
|
setLightOn(value) {
|
|
243
|
+
if (this.lightUseEnum) {
|
|
244
|
+
return this.setStateAsync(this.dpLightOn, value ? this.lightOnCommand : this.lightOffCommand);
|
|
245
|
+
}
|
|
226
246
|
return this.setStateAsync(this.dpLightOn, value);
|
|
227
247
|
}
|
|
228
248
|
|
|
@@ -232,7 +252,7 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
232
252
|
|
|
233
253
|
setBrightness(value) {
|
|
234
254
|
const tuya = this.convertBrightnessFromHomeKitToTuya(value);
|
|
235
|
-
return this.setStateAsync(this.dpBrightness, this.
|
|
255
|
+
return this.setStateAsync(this.dpBrightness, this.useStringsLight ? tuya.toString() : tuya);
|
|
236
256
|
}
|
|
237
257
|
|
|
238
258
|
getColorTemp() {
|
|
@@ -241,7 +261,7 @@ class SimpleFanLightAccessory extends BaseAccessory {
|
|
|
241
261
|
|
|
242
262
|
setColorTemp(value) {
|
|
243
263
|
const tuya = this.convertColorTempFromHomeKitToTuya(value);
|
|
244
|
-
return this.setStateAsync(this.dpColorTemp, this.
|
|
264
|
+
return this.setStateAsync(this.dpColorTemp, this.useStringsLight ? tuya.toString() : tuya);
|
|
245
265
|
}
|
|
246
266
|
|
|
247
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.71",
|
|
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": {
|
|
@@ -14,13 +14,22 @@ function makeFanLight(state = {}, context = {}) {
|
|
|
14
14
|
|
|
15
15
|
instance.dpFanOn = '60';
|
|
16
16
|
instance.dpRotationSpeed = '62';
|
|
17
|
-
instance.dpFanDirection = '63';
|
|
17
|
+
instance.dpFanDirection = device.context.dpFanDirection || '63';
|
|
18
|
+
instance.dpLightOn = device.context.dpLightOn || '20';
|
|
19
|
+
instance.dpBrightness = '22';
|
|
18
20
|
instance.dpColorTemp = '23';
|
|
19
21
|
instance.maxSpeed = parseInt(device.context.maxSpeed) || 6;
|
|
20
22
|
instance.fanDefaultSpeed = parseInt(device.context.fanDefaultSpeed) || 1;
|
|
21
23
|
instance.fanCurrentSpeed = 0;
|
|
22
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);
|
|
23
27
|
instance.singleDpWrites = instance._coerceBoolean(device.context.singleDpWrites, false);
|
|
28
|
+
instance.lightUseEnum = instance._coerceBoolean(device.context.lightUseEnum, false);
|
|
29
|
+
instance.lightOnCommand = device.context.lightOnCommand || 'On';
|
|
30
|
+
instance.lightOffCommand = device.context.lightOffCommand || 'Off';
|
|
31
|
+
instance.directionForwardCommand = device.context.directionForwardCommand || 'forward';
|
|
32
|
+
instance.directionReverseCommand = device.context.directionReverseCommand || 'reverse';
|
|
24
33
|
if (device.context.minWhiteColor !== undefined) instance.minWhiteColor = parseInt(device.context.minWhiteColor);
|
|
25
34
|
if (device.context.maxWhiteColor !== undefined) instance.maxWhiteColor = parseInt(device.context.maxWhiteColor);
|
|
26
35
|
|
|
@@ -164,6 +173,119 @@ describe('SimpleFanLightAccessory — setFanOn(false)', () => {
|
|
|
164
173
|
});
|
|
165
174
|
});
|
|
166
175
|
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
// Enum light on/off: fans whose Light DP is an 'On'/'Off' enum rather than a
|
|
178
|
+
// boolean (e.g. Orient AEON V.C.). Default stays boolean for compatibility.
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
describe('SimpleFanLightAccessory — enum light (lightUseEnum)', () => {
|
|
181
|
+
test('reads the enum command strings, not truthiness', () => {
|
|
182
|
+
const { instance } = makeFanLight(
|
|
183
|
+
{ '20': 'Off' },
|
|
184
|
+
{ lightUseEnum: true }
|
|
185
|
+
);
|
|
186
|
+
// The boolean path would read the non-empty string 'Off' as ON (the bug).
|
|
187
|
+
expect(instance.getLightOn()).toBe(false);
|
|
188
|
+
instance.device.state['20'] = 'On';
|
|
189
|
+
expect(instance.getLightOn()).toBe(true);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('setLightOn writes the On/Off command strings', () => {
|
|
193
|
+
const { instance, device } = makeFanLight(
|
|
194
|
+
{ '20': 'Off' },
|
|
195
|
+
{ lightUseEnum: true }
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
instance.setLightOn(true);
|
|
199
|
+
expect(device.update).toHaveBeenCalledWith({ '20': 'On' });
|
|
200
|
+
|
|
201
|
+
device.state['20'] = 'On';
|
|
202
|
+
instance.setLightOn(false);
|
|
203
|
+
expect(device.update).toHaveBeenCalledWith({ '20': 'Off' });
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test('honours custom on/off command strings', () => {
|
|
207
|
+
const { instance, device } = makeFanLight(
|
|
208
|
+
{ '101': 'off' },
|
|
209
|
+
{ dpLightOn: '101', lightUseEnum: true, lightOnCommand: 'on', lightOffCommand: 'off' }
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
expect(instance.getLightOn()).toBe(false);
|
|
213
|
+
instance.setLightOn(true);
|
|
214
|
+
expect(device.update).toHaveBeenCalledWith({ '101': 'on' });
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('default (flag off) keeps the boolean behaviour', () => {
|
|
218
|
+
const { instance, device } = makeFanLight({ '20': false });
|
|
219
|
+
|
|
220
|
+
expect(instance._getLightOn(true)).toBe(true);
|
|
221
|
+
expect(instance._getLightOn(false)).toBe(false);
|
|
222
|
+
|
|
223
|
+
instance.setLightOn(true);
|
|
224
|
+
expect(device.update).toHaveBeenCalledWith({ '20': true });
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// ---------------------------------------------------------------------------
|
|
229
|
+
// Configurable direction commands: map a shared "mode" DP (Windmode
|
|
230
|
+
// Normal/Reverse) onto HomeKit's RotationDirection toggle.
|
|
231
|
+
// ---------------------------------------------------------------------------
|
|
232
|
+
describe('SimpleFanLightAccessory — configurable direction commands', () => {
|
|
233
|
+
const { RotationDirection } = HAP.Characteristic;
|
|
234
|
+
|
|
235
|
+
test('reads the reverse command as COUNTER_CLOCKWISE', () => {
|
|
236
|
+
const { instance } = makeFanLight(
|
|
237
|
+
{ '3': 'Reverse' },
|
|
238
|
+
{ dpFanDirection: '3', directionForwardCommand: 'Normal', directionReverseCommand: 'Reverse' }
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
expect(instance.getFanDirection()).toBe(RotationDirection.COUNTER_CLOCKWISE);
|
|
242
|
+
instance.device.state['3'] = 'Normal';
|
|
243
|
+
expect(instance.getFanDirection()).toBe(RotationDirection.CLOCKWISE);
|
|
244
|
+
// Unrelated Windmode values (e.g. Sleep set from the Tuya app) read as forward.
|
|
245
|
+
instance.device.state['3'] = 'Sleep';
|
|
246
|
+
expect(instance.getFanDirection()).toBe(RotationDirection.CLOCKWISE);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('setFanDirection writes the configured command strings', () => {
|
|
250
|
+
const { instance, device } = makeFanLight(
|
|
251
|
+
{ '3': 'Normal' },
|
|
252
|
+
{ dpFanDirection: '3', directionForwardCommand: 'Normal', directionReverseCommand: 'Reverse' }
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
instance.setFanDirection(RotationDirection.COUNTER_CLOCKWISE);
|
|
256
|
+
expect(device.update).toHaveBeenCalledWith({ '3': 'Reverse' });
|
|
257
|
+
|
|
258
|
+
device.state['3'] = 'Reverse';
|
|
259
|
+
instance.setFanDirection(RotationDirection.CLOCKWISE);
|
|
260
|
+
expect(device.update).toHaveBeenCalledWith({ '3': 'Normal' });
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('defaults remain forward/reverse when unconfigured', () => {
|
|
264
|
+
const { instance, device } = makeFanLight({ '63': 'forward' });
|
|
265
|
+
|
|
266
|
+
expect(instance._getFanDirection('reverse')).toBe(RotationDirection.COUNTER_CLOCKWISE);
|
|
267
|
+
instance.setFanDirection(RotationDirection.COUNTER_CLOCKWISE);
|
|
268
|
+
expect(device.update).toHaveBeenCalledWith({ '63': 'reverse' });
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// ---------------------------------------------------------------------------
|
|
273
|
+
// Direction DP resolution: dpFanDirection overrides the default DP.
|
|
274
|
+
// ---------------------------------------------------------------------------
|
|
275
|
+
describe('SimpleFanLightAccessory — direction DP resolution', () => {
|
|
276
|
+
test('honours the dpFanDirection config key', () => {
|
|
277
|
+
const { instance } = makeInstance(SimpleFanLightAccessory, {}, { type: 'FanLight', dpFanDirection: 3 });
|
|
278
|
+
instance._registerCharacteristics({});
|
|
279
|
+
expect(instance.dpFanDirection).toBe('3');
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test('defaults to DP 63 when unset', () => {
|
|
283
|
+
const { instance } = makeInstance(SimpleFanLightAccessory, {}, { type: 'FanLight' });
|
|
284
|
+
instance._registerCharacteristics({});
|
|
285
|
+
expect(instance.dpFanDirection).toBe('63');
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
167
289
|
// ---------------------------------------------------------------------------
|
|
168
290
|
// convertColorTempFromTuyaToHomeKit — default range, inverted (issue #44)
|
|
169
291
|
// ---------------------------------------------------------------------------
|
|
@@ -296,4 +418,72 @@ describe('SimpleFanLightAccessory.getColorTemp / setColorTemp', () => {
|
|
|
296
418
|
await expect(instance.setColorTemp(370)).rejects.toBeInstanceOf(HAP.HapStatusError);
|
|
297
419
|
expect(device.update).not.toHaveBeenCalled();
|
|
298
420
|
});
|
|
421
|
+
|
|
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
|
+
});
|
|
299
488
|
});
|
|
489
|
+
|
|
@@ -820,6 +820,9 @@ Every option below is optional — the defaults match a common 3-speed fan. The
|
|
|
820
820
|
Default: 3 */
|
|
821
821
|
"maxSpeed": 3,
|
|
822
822
|
|
|
823
|
+
/* Override the default datapoint identifier of direction control (forward/reverse) */
|
|
824
|
+
"dpFanDirection": 63,
|
|
825
|
+
|
|
823
826
|
/* Speed to use when the fan is switched on from off. Default: 1 */
|
|
824
827
|
"fanDefaultSpeed": 1,
|
|
825
828
|
|
|
@@ -874,9 +877,14 @@ These are accessories that combine fan and lighting control in one device. Suppo
|
|
|
874
877
|
/* Speed used when the fan is switched on from off. Default: 1 */
|
|
875
878
|
"fanDefaultSpeed": 1,
|
|
876
879
|
|
|
877
|
-
/* Send
|
|
880
|
+
/* Send values as strings rather than numbers, for both the fan speed and
|
|
881
|
+
the light's brightness / colour temperature. Default: true */
|
|
878
882
|
"useStrings": true,
|
|
879
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
|
+
|
|
880
888
|
/* Send each data point in its own packet instead of combining fan
|
|
881
889
|
power + speed into one. Default: false (see note below) */
|
|
882
890
|
"singleDpWrites": false,
|
|
@@ -905,7 +913,27 @@ These are accessories that combine fan and lighting control in one device. Suppo
|
|
|
905
913
|
"minWhiteColor": 154,
|
|
906
914
|
|
|
907
915
|
/* Warmest colour temperature, in mireds (~2700 K). Default: 370 */
|
|
908
|
-
"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
|
|
909
937
|
}
|
|
910
938
|
```
|
|
911
939
|
|
|
@@ -926,6 +954,48 @@ If the light, brightness and turning the fan **off** all work, but turning the f
|
|
|
926
954
|
}
|
|
927
955
|
```
|
|
928
956
|
|
|
957
|
+
#### Lights that use `On`/`Off` text values instead of a boolean
|
|
958
|
+
|
|
959
|
+
Some fans (e.g. the **Orient AEON V.C.**) type their light data point as an *enum of text values* — it sends `"On"` / `"Off"` strings rather than a boolean. With such a fan the light appears in HomeKit but toggling it does nothing, because the plugin's default light handling expects a boolean. Set `"lightUseEnum": true` to make the plugin read and write the text values instead. The command strings default to `"On"` / `"Off"` and can be overridden with `lightOnCommand` / `lightOffCommand`.
|
|
960
|
+
|
|
961
|
+
#### Direction carried on a shared "mode" data point
|
|
962
|
+
|
|
963
|
+
On some fans, forward/reverse is not its own data point — it is one of several values of a shared *mode* data point (e.g. a `Windmode` enum with values like `Normal`, `Reverse`, `Sleep`, `Breeze`). Point `dpFanDirection` at that data point and set `directionForwardCommand` / `directionReverseCommand` to the values it uses (they default to `"forward"` / `"reverse"`). HomeKit's clockwise/counter-clockwise direction toggle then maps onto `Normal` / `Reverse`. Any other mode value (`Sleep`, `Breeze`, …) set from the Tuya app simply reads back as the forward direction.
|
|
964
|
+
|
|
965
|
+
> Note: because direction shares the mode data point, selecting a normal speed writes `Normal` to it, so the fan can only be in one mode at a time — this mirrors how the physical fan works. Modes that HomeKit has no control for (Turbo, Sleep, Breeze) and the countdown timer are not exposed; set them from the Tuya / Smart Life app.
|
|
966
|
+
|
|
967
|
+
A full example for the Orient AEON V.C. (Power = DP 1, WindSpeed enum `"1"`–`"5"` = DP 2, Windmode = DP 3, Light enum `"On"`/`"Off"` = DP 101):
|
|
968
|
+
|
|
969
|
+
```json5
|
|
970
|
+
{
|
|
971
|
+
"type": "FanLight",
|
|
972
|
+
"name": "Orient AEON Fan",
|
|
973
|
+
"id": "032000123456789abcde",
|
|
974
|
+
"key": "0123456789abcdef",
|
|
975
|
+
|
|
976
|
+
/* Power (boolean) */
|
|
977
|
+
"dpFanOn": 1,
|
|
978
|
+
|
|
979
|
+
/* WindSpeed enum "1".."5" — parsed as levels 1..5 and sent as strings */
|
|
980
|
+
"dpRotationSpeed": 2,
|
|
981
|
+
"maxSpeed": 5,
|
|
982
|
+
"useStrings": true,
|
|
983
|
+
|
|
984
|
+
/* Light is an "On"/"Off" enum, not a boolean; no brightness/colour temp */
|
|
985
|
+
"dpLightOn": 101,
|
|
986
|
+
"lightUseEnum": true,
|
|
987
|
+
"useBrightness": false,
|
|
988
|
+
"useColorTemp": false,
|
|
989
|
+
|
|
990
|
+
/* Direction lives on the Windmode data point as Normal/Reverse */
|
|
991
|
+
"dpFanDirection": 3,
|
|
992
|
+
"directionForwardCommand": "Normal",
|
|
993
|
+
"directionReverseCommand": "Reverse"
|
|
994
|
+
}
|
|
995
|
+
```
|
|
996
|
+
|
|
997
|
+
> On this fan, reverse airflow only runs at the lower speeds — that limit is enforced by the fan's own firmware, not the plugin, so the HomeKit speed slider still shows the full range.
|
|
998
|
+
|
|
929
999
|
### Irrigation Systems / Sprinklers
|
|
930
1000
|
|
|
931
1001
|
Multi-valve Tuya irrigation/sprinkler controllers (the battery-powered Wi-Fi "faucet timers" that expose several `switch_*` valves and a `battery_percentage`) are exposed as a single, fully-fledged HomeKit **Irrigation System** accessory:
|