homebridge-tuya-plus 4.1.0-dev.77 → 4.1.0-dev.79

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/AGENTS.md CHANGED
@@ -149,6 +149,11 @@ optional, off-by-default flags read through `_debugConfig()` and coerced with
149
149
  (token, signature, password, access key/id, uid) redacted. Verbose and
150
150
  per-request — keep it off in normal operation, and remember Homebridge
151
151
  debug logging must be on to see it.
152
+ - `debug.logDebugAsInfo` — promote every `this.log.debug` line to `info` by
153
+ wrapping the platform logger (threaded down to every device/accessory/cloud
154
+ component). Lets a user capture the plugin's verbose protocol/state logging
155
+ without enabling Homebridge's global debug mode. Chatty by design — a
156
+ troubleshooting switch, not for normal operation.
152
157
 
153
158
  ## Git & PR workflow
154
159
 
@@ -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",
package/index.js CHANGED
@@ -93,6 +93,23 @@ function coerceBoolean(value, defaultValue) {
93
93
  : df;
94
94
  }
95
95
 
96
+ // Return a drop-in replacement for the Homebridge logger whose .debug() emits
97
+ // at info level instead, leaving every other method (and the callable form)
98
+ // untouched. Wrapping the platform's logger once and threading it down to every
99
+ // device/accessory/cloud component promotes the plugin's whole debug stream to
100
+ // info, so users can capture its verbose protocol/state logging without turning
101
+ // on Homebridge's global debug mode (debug.logDebugAsInfo).
102
+ function promoteDebugToInfo(log) {
103
+ const wrapped = (...args) => log(...args);
104
+ for (const key of ['info', 'warn', 'error', 'log']) {
105
+ if (typeof log[key] === 'function')
106
+ wrapped[key] = (...args) => log[key](...args);
107
+ }
108
+ wrapped.debug = (...args) => log.info(...args);
109
+ if ('prefix' in log) wrapped.prefix = log.prefix;
110
+ return wrapped;
111
+ }
112
+
96
113
  module.exports = function (homebridge) {
97
114
  ({
98
115
  platformAccessory: PlatformAccessory,
@@ -114,6 +131,14 @@ class TuyaLan {
114
131
  constructor(...props) {
115
132
  [this.log, this.config, this.api] = [...props];
116
133
 
134
+ // Apply before anything logs so the very first lines already honour it.
135
+ if (this.config && coerceBoolean(this._debugConfig().logDebugAsInfo)) {
136
+ this.log = promoteDebugToInfo(this.log);
137
+ this.log.info(
138
+ 'debug.logDebugAsInfo is set: routing all debug logging to info.',
139
+ );
140
+ }
141
+
117
142
  this.cachedAccessories = new Map();
118
143
  // One TuyaDevice per configured device, keyed by Tuya id, so discovery can
119
144
  // hand each its LAN target once it's found on the network.
@@ -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
- // Some fans use DP 2 for a mode enum (nature/sleep/…) rather than a
29
- // rotation direction; RotationDirection would then write forward/reverse
30
- // into that enum. noDirection drops the characteristic for those fans.
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-tuya-plus",
3
- "version": "4.1.0-dev.77",
3
+ "version": "4.1.0-dev.79",
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": {
@@ -166,6 +166,49 @@ describe('TuyaLan — debug.forceCloudFallback', () => {
166
166
  });
167
167
  });
168
168
 
169
+ describe('TuyaLan — debug.logDebugAsInfo', () => {
170
+ // The platform wraps its logger and threads it down to every
171
+ // device/accessory/cloud component, so promoting it once routes the
172
+ // plugin's whole debug stream to info. Build the platform directly here to
173
+ // keep a handle on the underlying logger mock the wrapper delegates to.
174
+ function platformWith(config) {
175
+ const Platform = getPlatformClass();
176
+ const rawLog = makeLog();
177
+ return [new Platform(rawLog, config, makeApi()), rawLog];
178
+ }
179
+
180
+ test('routes a debug line to info', () => {
181
+ const [platform, rawLog] = platformWith({debug: {logDebugAsInfo: true}, devices: [SW()]});
182
+ platform.log.debug('hello', 1);
183
+ expect(rawLog.info).toHaveBeenCalledWith('hello', 1);
184
+ expect(rawLog.debug).not.toHaveBeenCalledWith('hello', 1);
185
+ });
186
+
187
+ test('the wrapped logger passes the callable form and info/warn/error straight through', () => {
188
+ const [platform, rawLog] = platformWith({debug: {logDebugAsInfo: true}, devices: [SW()]});
189
+ platform.log('plain');
190
+ platform.log.warn('careful');
191
+ platform.log.error('broke');
192
+ expect(rawLog).toHaveBeenCalledWith('plain');
193
+ expect(rawLog.warn).toHaveBeenCalledWith('careful');
194
+ expect(rawLog.error).toHaveBeenCalledWith('broke');
195
+ });
196
+
197
+ test('off (or absent) leaves the logger untouched and debug going to debug', () => {
198
+ const [platform, rawLog] = platformWith({devices: [SW()]});
199
+ expect(platform.log).toBe(rawLog);
200
+ platform.log.debug('quiet');
201
+ expect(rawLog.debug).toHaveBeenCalledWith('quiet');
202
+ expect(rawLog.info).not.toHaveBeenCalledWith('quiet');
203
+ });
204
+
205
+ test('lenient boolean spellings are accepted', () => {
206
+ const [platform, rawLog] = platformWith({debug: {logDebugAsInfo: 'true'}, devices: [SW()]});
207
+ platform.log.debug('promote me');
208
+ expect(rawLog.info).toHaveBeenCalledWith('promote me');
209
+ });
210
+ });
211
+
169
212
  describe('TuyaLan — unconfigured device discovery', () => {
170
213
  const UNKNOWN = {id: 'bf99999999999999', ip: '10.0.0.9'};
171
214
  const BARE = 'Discovered a device that has not been configured yet (%s@%s).';