homebridge-tuya-plus 4.1.0-dev.78 → 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 +5 -0
- package/index.js +25 -0
- package/package.json +1 -1
- package/test/index.test.js +43 -0
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
|
|
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.
|
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.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": {
|
package/test/index.test.js
CHANGED
|
@@ -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).';
|