homebridge-tuya-plus 4.3.0 → 4.4.0-dev.118
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/.github/workflows/test.yml +5 -1
- package/AGENTS.md +7 -1
- package/Changelog.md +2 -0
- package/index.js +1 -0
- package/lib/TuyaDevice.js +20 -0
- package/package.json +2 -2
- package/test/TuyaDevice.test.js +50 -0
- package/test/index.test.js +17 -0
|
@@ -9,13 +9,17 @@ on:
|
|
|
9
9
|
jobs:
|
|
10
10
|
test:
|
|
11
11
|
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
node-version: ["20", "22", "24", "26"]
|
|
12
16
|
steps:
|
|
13
17
|
- uses: actions/checkout@v4
|
|
14
18
|
|
|
15
19
|
- name: Use Node.js
|
|
16
20
|
uses: actions/setup-node@v4
|
|
17
21
|
with:
|
|
18
|
-
node-version:
|
|
22
|
+
node-version: ${{ matrix.node-version }}
|
|
19
23
|
|
|
20
24
|
- run: npm ci
|
|
21
25
|
|
package/AGENTS.md
CHANGED
|
@@ -20,7 +20,7 @@ software with a large existing install base.**
|
|
|
20
20
|
|
|
21
21
|
- **Node.js, CommonJS** (`require`/`module.exports`). No TypeScript, no build
|
|
22
22
|
step — the source that ships is the source in the repo.
|
|
23
|
-
- Target runtimes: Node `^20.18 || ^22.10 || ^24`, Homebridge `^1.8 || ^2.0`
|
|
23
|
+
- Target runtimes: Node `^20.18 || ^22.10 || ^24 || ^26`, Homebridge `^1.8 || ^2.0`
|
|
24
24
|
(see `engines` in `package.json`). Keep changes compatible with both
|
|
25
25
|
Homebridge 1.x and 2.x.
|
|
26
26
|
|
|
@@ -155,6 +155,12 @@ optional, off-by-default flags read through `_debugConfig()` and coerced with
|
|
|
155
155
|
without enabling Homebridge's global debug mode. Chatty by design — a
|
|
156
156
|
troubleshooting switch, not for normal operation.
|
|
157
157
|
|
|
158
|
+
- `debug.logStateChanges` — log every device's data-point changes (from the LAN
|
|
159
|
+
or the cloud) at `info`, e.g. `Kitchen Light: state changed (lan) → {"1":false}`,
|
|
160
|
+
plus one `initial state` line per device at startup. Without it the same lines
|
|
161
|
+
still go to `debug`. A quiet way to keep an on/off history without
|
|
162
|
+
`logDebugAsInfo`'s protocol noise.
|
|
163
|
+
|
|
158
164
|
## Git & PR workflow
|
|
159
165
|
|
|
160
166
|
- Develop on the branch you've been assigned; never push to `main` directly.
|
package/Changelog.md
CHANGED
|
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. This projec
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
* [+] **Log device state changes.** Every data-point change, whether it came in over the LAN or the cloud, is now logged per device (`Kitchen Light: state changed (lan) → {"1":false}`), plus the initial state at startup. These lines go to `debug` by default; set `"debug": { "logStateChanges": true }` on the platform to see them at `info` without turning on the rest of the debug logging. Off by default, so existing logs are unchanged.
|
|
8
|
+
* [*] **Declare Node.js 26 support.** The `engines.node` range now includes `^26.0.0`, so Homebridge no longer flags the plugin as incompatible on Node 26. The test workflow now runs on Node 20, 22, 24 and 26.
|
|
7
9
|
* [+] **PercentBlinds: animate Opening/Closing mid-travel via an optional work-state data-point.** Many Tuya curtain/roller motors report their position (`dpPercentState`) only once travel finishes, so the Home app jumped straight to the target instead of showing "Opening…"/"Closing…". Set `"dpWorkState"` (Tuya `work_state`/`control`, usually `7`) and the accessory drives HomeKit's `PositionState` from the live direction the motor reports (`opening`/`closing`, with `open`/`up` and `close`/`down` also recognised, overridable via `opening`/`closing`), then settles to STOPPED when the position report arrives. `flipState` inverts the direction to match a flipped position range. Purely opt-in: with no `dpWorkState` the behaviour is unchanged. Also adds `PercentBlinds`, its `dpPercentControl`/`dpPercentState`/`flipState`/`dpWorkState` options, and the new work-state values to `config.schema.json` (the type existed in code but was missing from the Config UI form).
|
|
8
10
|
* [+] **Garage door: support DASPI "Passage" openers.** Set `"manufacturer": "Daspi"` on a `GarageDoor` device to select its data-points (`dpAction` `1`, `dpStatus` `7`, still overridable). DASPI reports state as strings on DP `7` (`full_opened`/`opening`/`open_softstop`/`full_closed`/`closing`/`close_softstop`) and takes capitalized `Open`/`Close` commands on DP `1`; the soft-stop phases map to HomeKit's Opening/Closing so the tile animates correctly mid-travel.
|
|
9
11
|
* [+] **Tuya Cloud is now a transparent, global fallback for every device.** What started as an experiment to reach battery-powered "sleepy" irrigation timers (which never appear on the LAN) is now a general, optional fallback: add a top-level `cloud` credentials block once and the plugin keeps a single Tuya Cloud/MQTT session alive in the background, falling back to it whenever a device can't be reached on the LAN — a flaky moment, or hardware that's never local. The plugin stays **LAN-first** (local is always tried first and preferred) and cloud remains **strictly opt-in** (nothing runs unless credentials are present).
|
package/index.js
CHANGED
|
@@ -464,6 +464,7 @@ class TuyaLan {
|
|
|
464
464
|
cloudApi: usesCloud ? this.cloudApi : undefined,
|
|
465
465
|
messaging: usesCloud ? this.cloudMessaging : undefined,
|
|
466
466
|
cloudStartDelay: usesCloud ? this._nextCloudStartDelay() : 0,
|
|
467
|
+
logStateChanges: coerceBoolean(this._debugConfig().logStateChanges),
|
|
467
468
|
log: this.log,
|
|
468
469
|
UUID: UUID.generate(UUID_SEED + ':' + device.id),
|
|
469
470
|
connect: false,
|
package/lib/TuyaDevice.js
CHANGED
|
@@ -51,6 +51,7 @@ class TuyaDevice extends EventEmitter {
|
|
|
51
51
|
this.setMaxListeners(0);
|
|
52
52
|
|
|
53
53
|
this.log = props.log || console;
|
|
54
|
+
this._logStateChanges = !!props.logStateChanges;
|
|
54
55
|
|
|
55
56
|
// A plain config object on `context`, mirroring the transport classes but
|
|
56
57
|
// without the live helper objects we were handed.
|
|
@@ -58,6 +59,7 @@ class TuyaDevice extends EventEmitter {
|
|
|
58
59
|
delete this.context.log;
|
|
59
60
|
delete this.context.cloudApi;
|
|
60
61
|
delete this.context.messaging;
|
|
62
|
+
delete this.context.logStateChanges;
|
|
61
63
|
|
|
62
64
|
this.state = {};
|
|
63
65
|
this._stopped = false;
|
|
@@ -197,12 +199,30 @@ class TuyaDevice extends EventEmitter {
|
|
|
197
199
|
if (first || Object.keys(changes).length) {
|
|
198
200
|
this.state = {...this.state, ...merged};
|
|
199
201
|
this._registered = true;
|
|
202
|
+
this._logStateChange(first ? 'initial state' : 'state changed', which, first ? this.state : changes);
|
|
200
203
|
// The first emit drives BaseAccessory's one-time characteristic
|
|
201
204
|
// registration; later emits carry only what actually changed.
|
|
202
205
|
this.emit('change', changes, this.state);
|
|
203
206
|
}
|
|
204
207
|
}
|
|
205
208
|
|
|
209
|
+
// Every change from either transport funnels through here, already diffed, so
|
|
210
|
+
// this is the one place that can log a clean per-device on/off history. It's
|
|
211
|
+
// debug by default (per-state-change is chatty); debug.logStateChanges lifts
|
|
212
|
+
// just these lines to info without promoting the rest of the debug stream.
|
|
213
|
+
_logStateChange(label, which, dps) {
|
|
214
|
+
let detail;
|
|
215
|
+
try {
|
|
216
|
+
detail = JSON.stringify(dps);
|
|
217
|
+
} catch (ex) {
|
|
218
|
+
detail = Object.keys(dps).join(', ');
|
|
219
|
+
}
|
|
220
|
+
const source = which ? ` (${which})` : '';
|
|
221
|
+
const line = `${this.context.name}: ${label}${source} → ${detail}`;
|
|
222
|
+
if (this._logStateChanges) this.log.info(line);
|
|
223
|
+
else this.log.debug(line);
|
|
224
|
+
}
|
|
225
|
+
|
|
206
226
|
// Decide whether `which` backend may drive the one-time characteristic
|
|
207
227
|
// registration. LAN is always safe (numeric signature). The cloud is safe when
|
|
208
228
|
// the device is cloud-only (no local key), or once it has the numeric map (state
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-tuya-plus",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0-dev.118",
|
|
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": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
],
|
|
44
44
|
"engines": {
|
|
45
45
|
"homebridge": "^1.8.0 || ^2.0.0-beta.0",
|
|
46
|
-
"node": "^20.18.0 || ^22.10.0 || ^24.0.0"
|
|
46
|
+
"node": "^20.18.0 || ^22.10.0 || ^24.0.0 || ^26.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@eslint/js": "^9.30.1",
|
package/test/TuyaDevice.test.js
CHANGED
|
@@ -142,6 +142,56 @@ describe('TuyaDevice — state merge & registration', () => {
|
|
|
142
142
|
});
|
|
143
143
|
});
|
|
144
144
|
|
|
145
|
+
describe('TuyaDevice — state-change logging', () => {
|
|
146
|
+
const spyLog = () => ({info: jest.fn(), warn: jest.fn(), error: jest.fn(), debug: jest.fn()});
|
|
147
|
+
|
|
148
|
+
test('logs the initial state, then only what changed, at debug by default', () => {
|
|
149
|
+
const spy = spyLog();
|
|
150
|
+
const dev = makeDevice({log: spy});
|
|
151
|
+
const lan = fakeBackend({connected: true, state: {'1': true, '2': 50}});
|
|
152
|
+
withBackends(dev, {lan});
|
|
153
|
+
|
|
154
|
+
lan.emit('change');
|
|
155
|
+
lan.state = {'1': false, '2': 50};
|
|
156
|
+
lan.emit('change');
|
|
157
|
+
|
|
158
|
+
expect(spy.debug).toHaveBeenCalledWith('Lamp: initial state (lan) → {"1":true,"2":50}');
|
|
159
|
+
expect(spy.debug).toHaveBeenCalledWith('Lamp: state changed (lan) → {"1":false}');
|
|
160
|
+
expect(spy.info).not.toHaveBeenCalled();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('logStateChanges lifts the lines to info and names the transport', () => {
|
|
164
|
+
const spy = spyLog();
|
|
165
|
+
const dev = makeDevice({key: undefined, log: spy, logStateChanges: true}); // cloud-only
|
|
166
|
+
const cloud = fakeBackend({connected: true, state: {'switch_led': true}});
|
|
167
|
+
withBackends(dev, {cloud});
|
|
168
|
+
|
|
169
|
+
cloud.emit('change');
|
|
170
|
+
cloud.state = {'switch_led': false};
|
|
171
|
+
cloud.emit('change');
|
|
172
|
+
|
|
173
|
+
expect(spy.info).toHaveBeenCalledWith('Lamp: state changed (cloud) → {"switch_led":false}');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('a report with nothing new logs nothing', () => {
|
|
177
|
+
const spy = spyLog();
|
|
178
|
+
const dev = makeDevice({log: spy, logStateChanges: true});
|
|
179
|
+
const lan = fakeBackend({connected: true, state: {'1': true}});
|
|
180
|
+
withBackends(dev, {lan});
|
|
181
|
+
|
|
182
|
+
lan.emit('change');
|
|
183
|
+
spy.info.mockClear();
|
|
184
|
+
lan.emit('change');
|
|
185
|
+
|
|
186
|
+
expect(spy.info).not.toHaveBeenCalled();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('the flag stays out of the device context', () => {
|
|
190
|
+
const dev = makeDevice({logStateChanges: true});
|
|
191
|
+
expect(dev.context.logStateChanges).toBeUndefined();
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
145
195
|
describe('TuyaDevice — writes with fallback', () => {
|
|
146
196
|
test('LAN is used first when both backends are up', async () => {
|
|
147
197
|
const dev = makeDevice();
|
package/test/index.test.js
CHANGED
|
@@ -220,6 +220,23 @@ describe('TuyaLan — debug.logDebugAsInfo', () => {
|
|
|
220
220
|
});
|
|
221
221
|
});
|
|
222
222
|
|
|
223
|
+
describe('TuyaLan — debug.logStateChanges', () => {
|
|
224
|
+
test('is handed to every device when set', () => {
|
|
225
|
+
run({debug: {logStateChanges: true}, devices: [SW()]});
|
|
226
|
+
expect(propsFor('bf11111111111111').logStateChanges).toBe(true);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('lenient boolean spellings are accepted', () => {
|
|
230
|
+
run({debug: {logStateChanges: 'true'}, devices: [SW()]});
|
|
231
|
+
expect(propsFor('bf11111111111111').logStateChanges).toBe(true);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('off (or absent) by default', () => {
|
|
235
|
+
run({devices: [SW()]});
|
|
236
|
+
expect(propsFor('bf11111111111111').logStateChanges).toBe(false);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
223
240
|
describe('TuyaLan — unconfigured device discovery', () => {
|
|
224
241
|
const UNKNOWN = {id: 'bf99999999999999', ip: '10.0.0.9'};
|
|
225
242
|
const BARE = 'Discovered a device that has not been configured yet (%s@%s).';
|