@caseman72/tuya-api 1.0.0 → 1.1.0
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/index.js +23 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -66,7 +66,29 @@ class Tuya {
|
|
|
66
66
|
async setMode(idOrName, mode) {
|
|
67
67
|
const device = this.getDevice(idOrName);
|
|
68
68
|
if (!device) throw new Error(`Device not found: ${idOrName}`);
|
|
69
|
-
|
|
69
|
+
|
|
70
|
+
const result = await setMode(device, mode);
|
|
71
|
+
|
|
72
|
+
// Sync mode to all other devices in the same mode_group
|
|
73
|
+
if (device.mode_group) {
|
|
74
|
+
const grouped = this._devices.filter(d =>
|
|
75
|
+
d.mode_group === device.mode_group && d.id !== device.id
|
|
76
|
+
);
|
|
77
|
+
const synced = [];
|
|
78
|
+
for (const peer of grouped) {
|
|
79
|
+
try {
|
|
80
|
+
await setMode(peer, mode);
|
|
81
|
+
synced.push(peer.name);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
console.error(`[tuya-api] Failed to sync mode to ${peer.name}:`, err.message);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (synced.length > 0) {
|
|
87
|
+
result.synced = synced;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return result;
|
|
70
92
|
}
|
|
71
93
|
|
|
72
94
|
async setFanSpeed(idOrName, speed) {
|