homebridge-tuya-plus 3.14.0-dev.17 → 3.14.0-dev.19
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 +5 -0
- package/config.schema.json +1 -1
- package/index.js +2 -1
- package/lib/BaseAccessory.js +40 -13
- package/lib/ConvectorAccessory.js +1 -1
- package/lib/CustomMultiOutletAccessory.js +2 -1
- package/lib/MultiOutletAccessory.js +2 -1
- package/lib/OilDiffuserAccessory.js +10 -8
- package/lib/RGBTWLightAccessory.js +13 -11
- package/lib/RGBTWOutletAccessory.js +11 -9
- package/lib/SimpleBlindsAccessory.js +5 -5
- package/lib/SimpleDimmer2Accessory.js +1 -1
- package/lib/SimpleDimmerAccessory.js +10 -6
- package/lib/SimpleGarageDoorAccessory.js +31 -18
- package/lib/SimpleHeaterAccessory.js +2 -2
- package/lib/SwitchAccessory.js +2 -1
- package/lib/TWLightAccessory.js +2 -2
- package/lib/TuyaCloudDevice.js +15 -5
- package/lib/ValveAccessory.js +16 -12
- package/lib/VerticalBlindsWithTilt.js +5 -3
- package/lib/WledDimmerAccessory.js +46 -81
- package/package.json +1 -1
- package/test/BaseAccessory.test.js +83 -10
- package/test/MultiOutletAccessory.test.js +12 -0
- package/test/RGBTWLightAccessory.test.js +3 -3
- package/test/SimpleFanLightAccessory.test.js +3 -3
- package/test/SimpleGarageDoorAccessory.test.js +4 -2
- package/test/TuyaCloudDevice.test.js +22 -1
- package/test/getCategory.test.js +1 -0
- package/wiki/Supported-Device-Types.md +8 -6
package/lib/TWLightAccessory.js
CHANGED
|
@@ -72,7 +72,7 @@ class TWLightAccessory extends BaseAccessory {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
getBrightness() {
|
|
75
|
-
return this.convertBrightnessFromTuyaToHomeKit(this.
|
|
75
|
+
return this.convertBrightnessFromTuyaToHomeKit(this.getStateAsync(this.dpBrightness));
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
setBrightness(value) {
|
|
@@ -80,7 +80,7 @@ class TWLightAccessory extends BaseAccessory {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
getColorTemperature() {
|
|
83
|
-
return this.convertColorTemperatureFromTuyaToHomeKit(this.
|
|
83
|
+
return this.convertColorTemperatureFromTuyaToHomeKit(this.getStateAsync(this.dpColorTemperature));
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
setColorTemperature(value) {
|
package/lib/TuyaCloudDevice.js
CHANGED
|
@@ -173,7 +173,15 @@ class TuyaCloudDevice extends EventEmitter {
|
|
|
173
173
|
// `this.state`: the accessory already reflects the user's intent in HomeKit
|
|
174
174
|
// immediately, and leaving `state` untouched lets the realtime stream
|
|
175
175
|
// confirm the real device state without a spurious "revert" while a sleepy
|
|
176
|
-
// device catches up.
|
|
176
|
+
// device catches up.
|
|
177
|
+
//
|
|
178
|
+
// Return contract mirrors TuyaAccessory.update() as far as a synchronous
|
|
179
|
+
// caller is concerned (truthy on a no-op, `false` when not connected) but,
|
|
180
|
+
// unlike the LAN class, the actual command travels over HTTP and only its
|
|
181
|
+
// outcome reveals a failure. So when a command IS dispatched we return the
|
|
182
|
+
// promise that resolves to the boolean result (and never rejects), letting
|
|
183
|
+
// `BaseAccessory.setMultiStateAsync` await it and surface a rejected cloud
|
|
184
|
+
// command to HomeKit instead of silently dropping it.
|
|
177
185
|
update(dps) {
|
|
178
186
|
if (!dps || typeof dps !== 'object') return true;
|
|
179
187
|
|
|
@@ -185,13 +193,15 @@ class TuyaCloudDevice extends EventEmitter {
|
|
|
185
193
|
return false;
|
|
186
194
|
}
|
|
187
195
|
|
|
188
|
-
this.api.sendCommands(this.context.id, commands)
|
|
196
|
+
return this.api.sendCommands(this.context.id, commands)
|
|
189
197
|
.then(ok => {
|
|
190
198
|
if (!ok) this.log.warn(`${this.context.name}: Tuya Cloud rejected command ${JSON.stringify(commands)}`);
|
|
199
|
+
return ok;
|
|
191
200
|
})
|
|
192
|
-
.catch(ex =>
|
|
193
|
-
|
|
194
|
-
|
|
201
|
+
.catch(ex => {
|
|
202
|
+
this.log.error(`${this.context.name}: cloud command failed: ${ex.message}`);
|
|
203
|
+
return false;
|
|
204
|
+
});
|
|
195
205
|
}
|
|
196
206
|
|
|
197
207
|
/* ------------------------------------------------------------------ *
|
package/lib/ValveAccessory.js
CHANGED
|
@@ -49,13 +49,13 @@ class ValveAccessory extends BaseAccessory {
|
|
|
49
49
|
.onSet(value => this.setStateAsync(this.dpPower, value));
|
|
50
50
|
|
|
51
51
|
const characteristicInUse = service.getCharacteristic(Characteristic.InUse)
|
|
52
|
-
.onGet(() => characteristicActive.value);
|
|
52
|
+
.onGet(() => { if (!this.device.connected) throw this._commError(); return characteristicActive.value; });
|
|
53
53
|
|
|
54
54
|
if (!this.noTimer) {
|
|
55
55
|
service.getCharacteristic(Characteristic.SetDuration)
|
|
56
|
-
.onGet(() => this.setDuration)
|
|
56
|
+
.onGet(() => { if (!this.device.connected) throw this._commError(); return this.setDuration; })
|
|
57
57
|
.on('change', (data) => {
|
|
58
|
-
this.log.
|
|
58
|
+
this.log.debug('Water Valve Time Duration Set to: ' + data.newValue / 60 + ' Minutes');
|
|
59
59
|
this.setDuration = data.newValue;
|
|
60
60
|
|
|
61
61
|
if (service.getCharacteristic(Characteristic.InUse).value) {
|
|
@@ -65,8 +65,9 @@ class ValveAccessory extends BaseAccessory {
|
|
|
65
65
|
|
|
66
66
|
clearTimeout(this.timer);
|
|
67
67
|
this.timer = setTimeout(() => {
|
|
68
|
-
this.log.
|
|
69
|
-
|
|
68
|
+
this.log.debug('Water Valve Timer Expired. Shutting OFF Valve');
|
|
69
|
+
this.setStateInBackground(this.dpPower, 0);
|
|
70
|
+
service.getCharacteristic(Characteristic.Active).updateValue(0);
|
|
70
71
|
service.getCharacteristic(Characteristic.InUse).updateValue(0);
|
|
71
72
|
this.lastActivationTime = null;
|
|
72
73
|
}, (data.newValue * 1000));
|
|
@@ -75,6 +76,7 @@ class ValveAccessory extends BaseAccessory {
|
|
|
75
76
|
|
|
76
77
|
service.getCharacteristic(Characteristic.RemainingDuration)
|
|
77
78
|
.onGet(() => {
|
|
79
|
+
if (!this.device.connected) throw this._commError();
|
|
78
80
|
let remainingTime = this.setDuration - Math.floor(((new Date()).getTime() - this.lastActivationTime) / 1000);
|
|
79
81
|
return (remainingTime && remainingTime > 0) ? remainingTime : 0;
|
|
80
82
|
});
|
|
@@ -87,17 +89,18 @@ class ValveAccessory extends BaseAccessory {
|
|
|
87
89
|
service.getCharacteristic(Characteristic.RemainingDuration).updateValue(0);
|
|
88
90
|
service.getCharacteristic(Characteristic.Active).updateValue(0);
|
|
89
91
|
clearTimeout(this.timer);
|
|
90
|
-
this.log.
|
|
92
|
+
this.log.debug('Water Valve is OFF!');
|
|
91
93
|
break;
|
|
92
94
|
case 1:
|
|
93
95
|
this.lastActivationTime = (new Date()).getTime();
|
|
94
96
|
service.getCharacteristic(Characteristic.RemainingDuration).updateValue(this.setDuration);
|
|
95
97
|
service.getCharacteristic(Characteristic.Active).updateValue(1);
|
|
96
|
-
this.log.
|
|
98
|
+
this.log.debug('Water Valve Turning ON with Timer Set to: ' + this.setDuration / 60 + ' Minutes');
|
|
97
99
|
clearTimeout(this.timer);
|
|
98
100
|
this.timer = setTimeout(() => {
|
|
99
|
-
this.log.
|
|
100
|
-
|
|
101
|
+
this.log.debug('Water Valve Timer Expired. Shutting OFF Valve');
|
|
102
|
+
this.setStateInBackground(this.dpPower, 0);
|
|
103
|
+
service.getCharacteristic(Characteristic.Active).updateValue(0);
|
|
101
104
|
service.getCharacteristic(Characteristic.InUse).updateValue(0);
|
|
102
105
|
this.lastActivationTime = null;
|
|
103
106
|
}, (this.setDuration * 1000));
|
|
@@ -110,11 +113,12 @@ class ValveAccessory extends BaseAccessory {
|
|
|
110
113
|
service.getCharacteristic(Characteristic.RemainingDuration).updateValue(this.setDuration);
|
|
111
114
|
service.getCharacteristic(Characteristic.Active).updateValue(1);
|
|
112
115
|
service.getCharacteristic(Characteristic.InUse).updateValue(1);
|
|
113
|
-
this.log.
|
|
116
|
+
this.log.debug('Water Valve is ON After Restart. Setting Timer to: ' + this.setDuration / 60 + ' Minutes');
|
|
114
117
|
clearTimeout(this.timer);
|
|
115
118
|
this.timer = setTimeout(() => {
|
|
116
|
-
this.log.
|
|
117
|
-
|
|
119
|
+
this.log.debug('Water Valve Timer Expired. Shutting OFF Valve');
|
|
120
|
+
this.setStateInBackground(this.dpPower, 0);
|
|
121
|
+
service.getCharacteristic(Characteristic.Active).updateValue(0);
|
|
118
122
|
this.lastActivationTime = null;
|
|
119
123
|
}, (this.setDuration * 1000));
|
|
120
124
|
}
|
|
@@ -38,16 +38,16 @@ class VerticalBlindsWithTilt extends BaseAccessory {
|
|
|
38
38
|
|
|
39
39
|
const characteristicCurrentPosition = service.getCharacteristic(Characteristic.CurrentPosition)
|
|
40
40
|
.updateValue(this.currentPosition)
|
|
41
|
-
.onGet(() => this.currentPosition);
|
|
41
|
+
.onGet(() => { if (!this.device.connected) throw this._commError(); return this.currentPosition; });
|
|
42
42
|
|
|
43
43
|
const characteristicTargetPosition = service.getCharacteristic(Characteristic.TargetPosition)
|
|
44
44
|
.updateValue(this.currentPosition)
|
|
45
|
-
.onGet(() => this.currentPosition)
|
|
45
|
+
.onGet(() => { if (!this.device.connected) throw this._commError(); return this.currentPosition; })
|
|
46
46
|
.onSet(value => this.setPosition(value));
|
|
47
47
|
|
|
48
48
|
const characteristicPositionState = service.getCharacteristic(Characteristic.PositionState)
|
|
49
49
|
.updateValue(Characteristic.PositionState.STOPPED)
|
|
50
|
-
.onGet(() => Characteristic.PositionState.STOPPED);
|
|
50
|
+
.onGet(() => { if (!this.device.connected) throw this._commError(); return Characteristic.PositionState.STOPPED; });
|
|
51
51
|
|
|
52
52
|
const characteristicCurrentHorizontalTilt = service.getCharacteristic(Characteristic.CurrentHorizontalTiltAngle)
|
|
53
53
|
.updateValue(this._getTiltAngle(dps[this.dpTiltState] || dps[this.dpTilt]))
|
|
@@ -76,6 +76,7 @@ class VerticalBlindsWithTilt extends BaseAccessory {
|
|
|
76
76
|
|
|
77
77
|
setPosition(value) {
|
|
78
78
|
const {Characteristic} = this.hap;
|
|
79
|
+
if (!this.device.connected) throw this._commError();
|
|
79
80
|
|
|
80
81
|
if (value === 0) {
|
|
81
82
|
if (this.currentPosition === 0) {
|
|
@@ -205,6 +206,7 @@ class VerticalBlindsWithTilt extends BaseAccessory {
|
|
|
205
206
|
}
|
|
206
207
|
|
|
207
208
|
setTiltAngle(value) {
|
|
209
|
+
if (!this.device.connected) throw this._commError();
|
|
208
210
|
const tuyaValue = Math.round((value / 1.8) + 50);
|
|
209
211
|
const clampedValue = Math.max(0, Math.min(100, tuyaValue));
|
|
210
212
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const SimpleDimmerAccessory = require('./SimpleDimmerAccessory');
|
|
2
2
|
const http = require('http');
|
|
3
3
|
const maxWledBrightness = 255;
|
|
4
4
|
|
|
@@ -6,30 +6,14 @@ const maxWledBrightness = 255;
|
|
|
6
6
|
const wledDebounceMs = 50;
|
|
7
7
|
const wledWarmupMs = 8000;
|
|
8
8
|
|
|
9
|
-
class WledDimmerAccessory extends
|
|
10
|
-
static getCategory(Categories) {
|
|
11
|
-
return Categories.LIGHTBULB;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
constructor(...props) {
|
|
15
|
-
super(...props);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
_registerPlatformAccessory() {
|
|
19
|
-
const {Service} = this.hap;
|
|
20
|
-
|
|
21
|
-
this.accessory.addService(Service.Lightbulb, this.device.context.name);
|
|
22
|
-
|
|
23
|
-
super._registerPlatformAccessory();
|
|
24
|
-
}
|
|
25
|
-
|
|
9
|
+
class WledDimmerAccessory extends SimpleDimmerAccessory {
|
|
26
10
|
_registerCharacteristics(dps) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
// The Lightbulb service, On/Brightness characteristics, default DPs and
|
|
12
|
+
// the device 'change' listener are all set up by SimpleDimmerAccessory.
|
|
13
|
+
// WLED only layers optional brightness sync and preset-effect switches
|
|
14
|
+
// on top, so without syncBrightnessToWled configured this behaves
|
|
15
|
+
// exactly like a plain SimpleDimmer.
|
|
16
|
+
super._registerCharacteristics(dps);
|
|
33
17
|
|
|
34
18
|
// State for debounced / delayed WLED updates
|
|
35
19
|
this._wledPendingBri = null;
|
|
@@ -47,32 +31,20 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
47
31
|
null;
|
|
48
32
|
this.syncBrightnessToWled = (syncCfg && ('' + syncCfg).trim()) || null;
|
|
49
33
|
|
|
50
|
-
this.log.
|
|
34
|
+
this.log.debug(
|
|
51
35
|
'[WLED Sync] %s: syncBrightnessToWled=%s',
|
|
52
36
|
this.device.context.name,
|
|
53
37
|
this.syncBrightnessToWled || 'disabled'
|
|
54
38
|
);
|
|
55
39
|
|
|
56
|
-
const characteristicOn = service.getCharacteristic(Characteristic.On)
|
|
57
|
-
.updateValue(dps[this.dpPower])
|
|
58
|
-
.onGet(() => this.getStateAsync(this.dpPower))
|
|
59
|
-
.onSet(value => this.setStateAsync(this.dpPower, value));
|
|
60
|
-
|
|
61
|
-
const characteristicBrightness = service.getCharacteristic(Characteristic.Brightness);
|
|
62
|
-
// Keep a reference so we can update brightness from background WLED calls
|
|
63
|
-
this._characteristicBrightness = characteristicBrightness;
|
|
64
|
-
|
|
65
40
|
if (this.syncBrightnessToWled) {
|
|
66
41
|
// Start with 100% locally while we fetch the actual WLED brightness
|
|
67
|
-
|
|
68
|
-
.updateValue(100)
|
|
69
|
-
.onGet(() => this.getBrightness())
|
|
70
|
-
.onSet(value => this.setBrightness(value));
|
|
42
|
+
this._characteristicBrightness.updateValue(100);
|
|
71
43
|
|
|
72
44
|
// Force Tuya dimmer brightness to 100% on startup
|
|
73
45
|
const maxTuyaBrightness = this.convertBrightnessFromHomeKitToTuya(100);
|
|
74
46
|
if (dps[this.dpBrightness] !== maxTuyaBrightness) {
|
|
75
|
-
this.log.
|
|
47
|
+
this.log.debug(
|
|
76
48
|
'[WLED Sync] %s: setting Tuya brightness DP%s to max (%s)',
|
|
77
49
|
this.device.context.name,
|
|
78
50
|
this.dpBrightness,
|
|
@@ -80,19 +52,6 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
80
52
|
);
|
|
81
53
|
this.setState(this.dpBrightness, maxTuyaBrightness, () => {});
|
|
82
54
|
}
|
|
83
|
-
} else {
|
|
84
|
-
const initial = this.convertBrightnessFromTuyaToHomeKit(dps[this.dpBrightness]);
|
|
85
|
-
this.log.debug(
|
|
86
|
-
'%s: initial Tuya brightness DP%s=%s -> HomeKit %s%%',
|
|
87
|
-
this.device.context.name,
|
|
88
|
-
this.dpBrightness,
|
|
89
|
-
dps[this.dpBrightness],
|
|
90
|
-
initial
|
|
91
|
-
);
|
|
92
|
-
characteristicBrightness
|
|
93
|
-
.updateValue(initial)
|
|
94
|
-
.onGet(() => this.getBrightness())
|
|
95
|
-
.onSet(value => this.setBrightness(value));
|
|
96
55
|
}
|
|
97
56
|
|
|
98
57
|
// Optional: create one HomeKit Switch per configured WLED preset effect.
|
|
@@ -148,7 +107,7 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
148
107
|
return callback();
|
|
149
108
|
}
|
|
150
109
|
|
|
151
|
-
this.log.
|
|
110
|
+
this.log.debug(
|
|
152
111
|
'[WLED Sync] %s: setting preset effect "%s" (id=%s, index=%s)',
|
|
153
112
|
this.device.context.name,
|
|
154
113
|
effectName,
|
|
@@ -196,6 +155,7 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
196
155
|
});
|
|
197
156
|
})
|
|
198
157
|
.on('get', cb => {
|
|
158
|
+
if (!this.device.connected) return cb(this._commError());
|
|
199
159
|
cb(null, this.device.state[this.dpPower] && this._wledCurrentEffectIndex === (index + 1));
|
|
200
160
|
});
|
|
201
161
|
|
|
@@ -211,15 +171,17 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
211
171
|
.filter(service => service.UUID === HapService.Switch.UUID && service.subtype && service.subtype.startsWith('wledEffect '))
|
|
212
172
|
.forEach(service => {
|
|
213
173
|
if (!validEffectServices.includes(service)) {
|
|
214
|
-
this.log.
|
|
174
|
+
this.log.debug('Removing', service.displayName);
|
|
215
175
|
this.accessory.removeService(service);
|
|
216
176
|
}
|
|
217
177
|
});
|
|
218
178
|
}
|
|
179
|
+
}
|
|
219
180
|
|
|
181
|
+
_registerChangeListener() {
|
|
220
182
|
this.device.on('change', changes => {
|
|
221
183
|
// Log full DPS changes so we can see exactly what Tuya reported
|
|
222
|
-
this.log.
|
|
184
|
+
this.log.debug(
|
|
223
185
|
'%s DPS changes: %s %s was:',
|
|
224
186
|
this.device.context.name,
|
|
225
187
|
JSON.stringify(changes),
|
|
@@ -228,10 +190,10 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
228
190
|
);
|
|
229
191
|
|
|
230
192
|
if (changes.hasOwnProperty(this.dpPower)) {
|
|
231
|
-
const oldPower = !!
|
|
193
|
+
const oldPower = !!this._characteristicOn.value;
|
|
232
194
|
const newPower = !!changes[this.dpPower];
|
|
233
195
|
|
|
234
|
-
this.log.
|
|
196
|
+
this.log.debug(
|
|
235
197
|
'%s power change detected on DP%s: %s -> %s',
|
|
236
198
|
this.device.context.name,
|
|
237
199
|
this.dpPower,
|
|
@@ -240,13 +202,13 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
240
202
|
);
|
|
241
203
|
|
|
242
204
|
if (oldPower !== newPower) {
|
|
243
|
-
|
|
205
|
+
this._characteristicOn.updateValue(newPower);
|
|
244
206
|
}
|
|
245
207
|
|
|
246
208
|
// Track warmup window for WLED after power ON
|
|
247
209
|
if (this.syncBrightnessToWled && newPower) {
|
|
248
210
|
this._wledReadyAt = Date.now() + wledWarmupMs;
|
|
249
|
-
this.log.
|
|
211
|
+
this.log.debug(
|
|
250
212
|
'[WLED Sync] %s: power ON -> delaying WLED API calls for %sms',
|
|
251
213
|
this.device.context.name,
|
|
252
214
|
wledWarmupMs
|
|
@@ -270,7 +232,7 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
270
232
|
|
|
271
233
|
// Ignore the "forced back to 100%" update to avoid feedback loops
|
|
272
234
|
if (tuyaValue === maxTuyaBrightness) {
|
|
273
|
-
this.log.
|
|
235
|
+
this.log.debug(
|
|
274
236
|
'[WLED Sync] %s: Tuya DP%s reported max brightness (%s), ignoring',
|
|
275
237
|
this.device.context.name,
|
|
276
238
|
this.dpBrightness,
|
|
@@ -282,7 +244,7 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
282
244
|
const percent = this.convertBrightnessFromTuyaToHomeKit(tuyaValue);
|
|
283
245
|
const bri = Math.max(0, Math.min(maxWledBrightness, Math.round((percent / 100) * maxWledBrightness)));
|
|
284
246
|
|
|
285
|
-
this.log.
|
|
247
|
+
this.log.debug(
|
|
286
248
|
'[WLED Sync] %s: Tuya DP%s changed to %s -> %s%% -> WLED bri=%s (debounced)',
|
|
287
249
|
this.device.context.name,
|
|
288
250
|
this.dpBrightness,
|
|
@@ -303,14 +265,14 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
303
265
|
}
|
|
304
266
|
|
|
305
267
|
// Reflect that brightness back into HomeKit
|
|
306
|
-
|
|
268
|
+
this._characteristicBrightness.updateValue(percent);
|
|
307
269
|
|
|
308
270
|
// After a short delay, force Tuya brightness back to 100% so it stops dimming the strip
|
|
309
271
|
if (this._wledForceMaxTimeout) {
|
|
310
272
|
clearTimeout(this._wledForceMaxTimeout);
|
|
311
273
|
}
|
|
312
274
|
this._wledForceMaxTimeout = setTimeout(() => {
|
|
313
|
-
this.log.
|
|
275
|
+
this.log.debug(
|
|
314
276
|
'[WLED Sync] %s: forcing Tuya DP%s back to max (%s) after Tuya app change',
|
|
315
277
|
this.device.context.name,
|
|
316
278
|
this.dpBrightness,
|
|
@@ -319,17 +281,18 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
319
281
|
this.setState(this.dpBrightness, maxTuyaBrightness, () => {});
|
|
320
282
|
}, 5000);
|
|
321
283
|
});
|
|
322
|
-
} else if (!this.syncBrightnessToWled && changes.hasOwnProperty(this.dpBrightness) && this.convertBrightnessFromHomeKitToTuya(
|
|
323
|
-
|
|
284
|
+
} else if (!this.syncBrightnessToWled && changes.hasOwnProperty(this.dpBrightness) && this.convertBrightnessFromHomeKitToTuya(this._characteristicBrightness.value) !== changes[this.dpBrightness]) {
|
|
285
|
+
this._characteristicBrightness.updateValue(this.convertBrightnessFromTuyaToHomeKit(changes[this.dpBrightness]));
|
|
324
286
|
}
|
|
325
287
|
});
|
|
326
288
|
}
|
|
327
289
|
|
|
328
290
|
getBrightness() {
|
|
291
|
+
if (!this.device.connected) throw this._commError();
|
|
329
292
|
if (this.syncBrightnessToWled) {
|
|
330
293
|
// If we already have a cached WLED brightness, return it immediately.
|
|
331
294
|
if (this._lastWledPercent != null) {
|
|
332
|
-
this.log.
|
|
295
|
+
this.log.debug(
|
|
333
296
|
'[WLED Sync] %s: getBrightness() -> using cached %s%%',
|
|
334
297
|
this.device.context.name,
|
|
335
298
|
this._lastWledPercent
|
|
@@ -338,13 +301,14 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
338
301
|
}
|
|
339
302
|
return 50;
|
|
340
303
|
} else {
|
|
341
|
-
|
|
304
|
+
// No WLED sync: behave as a plain SimpleDimmer.
|
|
305
|
+
return super.getBrightness();
|
|
342
306
|
}
|
|
343
307
|
}
|
|
344
308
|
|
|
345
309
|
setBrightness(value) {
|
|
346
310
|
if (this.syncBrightnessToWled) {
|
|
347
|
-
this.log.
|
|
311
|
+
this.log.debug(
|
|
348
312
|
'[WLED Sync] %s: setBrightness(%s%%)',
|
|
349
313
|
this.device.context.name,
|
|
350
314
|
value
|
|
@@ -356,19 +320,19 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
356
320
|
// Ensure Tuya stays at 100% so it doesn't interfere with WLED.
|
|
357
321
|
const maxTuyaBrightness = this.convertBrightnessFromHomeKitToTuya(100);
|
|
358
322
|
if (this.device.state[this.dpBrightness] !== maxTuyaBrightness) {
|
|
359
|
-
this.log.
|
|
323
|
+
this.log.debug(
|
|
360
324
|
'[WLED Sync] %s: ensuring Tuya DP%s=%s (max)',
|
|
361
325
|
this.device.context.name,
|
|
362
326
|
this.dpBrightness,
|
|
363
327
|
maxTuyaBrightness
|
|
364
328
|
);
|
|
365
329
|
// Fire-and-forget; don't tie HomeKit callback to Tuya I/O.
|
|
366
|
-
this.
|
|
330
|
+
this.setStateInBackground(this.dpBrightness, maxTuyaBrightness);
|
|
367
331
|
}
|
|
368
332
|
|
|
369
333
|
// Compute desired WLED brightness once.
|
|
370
334
|
const bri = Math.max(0, Math.min(maxWledBrightness, Math.round((value / 100) * maxWledBrightness)));
|
|
371
|
-
this.log.
|
|
335
|
+
this.log.debug(
|
|
372
336
|
'[WLED Sync] %s: mapped HomeKit %s%% -> WLED bri=%s (debounced background)',
|
|
373
337
|
this.device.context.name,
|
|
374
338
|
value,
|
|
@@ -381,7 +345,8 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
381
345
|
// Return to HomeKit immediately; don't wait for network I/O.
|
|
382
346
|
return null;
|
|
383
347
|
} else {
|
|
384
|
-
|
|
348
|
+
// No WLED sync: behave as a plain SimpleDimmer.
|
|
349
|
+
return super.setBrightness(value);
|
|
385
350
|
}
|
|
386
351
|
}
|
|
387
352
|
|
|
@@ -390,7 +355,7 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
390
355
|
const parts = String(this.syncBrightnessToWled).split(':');
|
|
391
356
|
const host = parts[0];
|
|
392
357
|
const port = parts[1] ? parseInt(parts[1], 10) || 80 : 80;
|
|
393
|
-
this.log.
|
|
358
|
+
this.log.debug(
|
|
394
359
|
'[WLED Sync] %s: target host=%s port=%s',
|
|
395
360
|
this.device.context.name,
|
|
396
361
|
host,
|
|
@@ -424,7 +389,7 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
424
389
|
timeout: 1000
|
|
425
390
|
};
|
|
426
391
|
|
|
427
|
-
this.log.
|
|
392
|
+
this.log.debug(
|
|
428
393
|
'[WLED Sync] %s: GET http://%s:%s/json/state',
|
|
429
394
|
this.device.context.name,
|
|
430
395
|
target.host,
|
|
@@ -447,7 +412,7 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
447
412
|
);
|
|
448
413
|
return done(true);
|
|
449
414
|
}
|
|
450
|
-
this.log.
|
|
415
|
+
this.log.debug(
|
|
451
416
|
'[WLED Sync] %s: /json/state -> bri=%s',
|
|
452
417
|
this.device.context.name,
|
|
453
418
|
bri
|
|
@@ -506,7 +471,7 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
506
471
|
timeout: 1000
|
|
507
472
|
};
|
|
508
473
|
|
|
509
|
-
this.log.
|
|
474
|
+
this.log.debug(
|
|
510
475
|
'[WLED Sync] %s: POST http://%s:%s/json/state body=%s',
|
|
511
476
|
this.device.context.name,
|
|
512
477
|
target.host,
|
|
@@ -518,7 +483,7 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
518
483
|
// Consume response and ignore body
|
|
519
484
|
res.on('data', () => {});
|
|
520
485
|
res.on('end', () => {
|
|
521
|
-
this.log.
|
|
486
|
+
this.log.debug(
|
|
522
487
|
'[WLED Sync] %s: WLED brightness set, HTTP %s',
|
|
523
488
|
this.device.context.name,
|
|
524
489
|
res.statusCode
|
|
@@ -581,7 +546,7 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
581
546
|
timeout: 1000
|
|
582
547
|
};
|
|
583
548
|
|
|
584
|
-
this.log.
|
|
549
|
+
this.log.debug(
|
|
585
550
|
'[WLED Sync] %s: POST http://%s:%s/json/state body=%s (preset effect)',
|
|
586
551
|
this.device.context.name,
|
|
587
552
|
target.host,
|
|
@@ -593,7 +558,7 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
593
558
|
// Consume response and ignore body
|
|
594
559
|
res.on('data', () => {});
|
|
595
560
|
res.on('end', () => {
|
|
596
|
-
this.log.
|
|
561
|
+
this.log.debug(
|
|
597
562
|
'[WLED Sync] %s: WLED effect set to %s, HTTP %s',
|
|
598
563
|
this.device.context.name,
|
|
599
564
|
effectId,
|
|
@@ -657,7 +622,7 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
657
622
|
const warmupDelay = this._wledReadyAt && now < this._wledReadyAt ? (this._wledReadyAt - now) : 0;
|
|
658
623
|
const delay = warmupDelay + wledDebounceMs;
|
|
659
624
|
|
|
660
|
-
this.log.
|
|
625
|
+
this.log.debug(
|
|
661
626
|
'[WLED Sync] %s: scheduling WLED bri=%s in %sms (%s)',
|
|
662
627
|
this.device.context.name,
|
|
663
628
|
brightness,
|
|
@@ -670,7 +635,7 @@ class WledDimmerAccessory extends BaseAccessory {
|
|
|
670
635
|
|
|
671
636
|
// If the light is now off, skip the call.
|
|
672
637
|
if (!this.device.state[this.dpPower]) {
|
|
673
|
-
this.log.
|
|
638
|
+
this.log.debug(
|
|
674
639
|
'[WLED Sync] %s: skipping scheduled WLED bri=%s because power is OFF',
|
|
675
640
|
this.device.context.name,
|
|
676
641
|
this._wledPendingBri
|
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.19",
|
|
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": {
|