Comparing version 5.3.2 to 6.0.0
43
index.js
@@ -30,2 +30,4 @@ // Import packages | ||
* @param {Number} [options.version=3.1] protocol version | ||
* @param {Boolean} [options.nullPayloadOnJSONError=false] if true, emits a data event | ||
* containing a payload of null values for on-device JSON parsing errors | ||
* @example | ||
@@ -36,3 +38,12 @@ * const tuya = new TuyaDevice({id: 'xxxxxxxxxxxxxxxxxxxx', | ||
class TuyaDevice extends EventEmitter { | ||
constructor({ip, port = 6668, id, gwID = id, key, productKey, version = 3.1} = {}) { | ||
constructor({ | ||
ip, | ||
port = 6668, | ||
id, | ||
gwID = id, | ||
key, | ||
productKey, | ||
version = 3.1, | ||
nullPayloadOnJSONError = false | ||
} = {}) { | ||
super(); | ||
@@ -42,2 +53,4 @@ // Set device to user-passed options | ||
this.nullPayloadOnJSONError = nullPayloadOnJSONError; | ||
// Check arguments | ||
@@ -320,16 +333,18 @@ if (!(isValidString(id) || | ||
for (const packet of packets) { | ||
if (packet.payload && packet.payload === 'json obj data unvalid') { | ||
this.emit('error', packet.payload); | ||
if (this.nullPayloadOnJSONError) { | ||
for (const packet of packets) { | ||
if (packet.payload && packet.payload === 'json obj data unvalid') { | ||
this.emit('error', packet.payload); | ||
packet.payload = { | ||
dps: { | ||
1: null, | ||
2: null, | ||
3: null, | ||
101: null, | ||
102: null, | ||
103: null | ||
} | ||
}; | ||
packet.payload = { | ||
dps: { | ||
1: null, | ||
2: null, | ||
3: null, | ||
101: null, | ||
102: null, | ||
103: null | ||
} | ||
}; | ||
} | ||
} | ||
@@ -336,0 +351,0 @@ } |
{ | ||
"name": "tuyapi", | ||
"version": "5.3.2", | ||
"version": "6.0.0", | ||
"description": "An easy-to-use API for devices that use Tuya's cloud services", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
43839
1010