+
+
+
+
+
+
+
+
+ TuyaDevice
+
+
+
+
+
+
+ Represents a Tuya device.
+
+
+ new TuyaDevice(options:
Object)
+
+
+
+
+
+
+
+
+
+
+
+ Parameters
+
+
+
+
+
+
+
+
+
+
+
+
+ Name |
+ Description |
+
+
+
+
+
+ options.ip String?
+ |
+ IP of device
+ |
+
+
+
+
+
+ options.port Number
+
+ (default 6668 )
+ |
+ port of device
+ |
+
+
+
+
+
+ options.id String
+ |
+ ID of device
+ |
+
+
+
+
+
+ options.key String
+ |
+ encryption key of device
+ |
+
+
+
+
+
+ options.version Number
+
+ (default 3.1 )
+ |
+ protocol version
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Example
+
+
+ const tuya = new TuyaDevice({id: 'xxxxxxxxxxxxxxxxxxxx', key: 'xxxxxxxxxxxxxxxx'})
+
+
+
+
+
+
+ Instance Members
+
+
+
+
+
+
▸
+
resolveIds(options?)
+
+
+
+
+
+
+
+ Resolves IDs stored in class to IPs. If you didn't pass IPs to the constructor,
+you must call this before doing anything else.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters
+
+
+
+
+
+
+
+
+
+
+
+
+ Name |
+ Description |
+
+
+
+
+
+ options.timeout Number
+
+ (default 10 )
+ |
+ how long, in seconds, to wait for device
+to be resolved before timeout error is thrown
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns
+ Promise<Boolean>
:
+ true if IP was found and device is ready to be used
+
+
+
+
+
+
+
+
+ Example
+
+
+ tuya.resolveIds().then(() => console.log('ready!'))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Gets a device's current status.
+Defaults to returning only the value of the first DPS index.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters
+
+
+
+
+
+
+
+
+
+
+
+
+ Name |
+ Description |
+
+
+
+
+
+ options.schema Boolean?
+ |
+ true to return entire schema of device
+ |
+
+
+
+
+
+ options.dps Number
+
+ (default 1 )
+ |
+ DPS index to return
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns
+ Promise<Object>
:
+ returns boolean if no options are provided, otherwise returns object of results
+
+
+
+
+
+
+
+
+ Example
+
+
+
+tuya.get().then(status => console.log(status))
+
+
+
+tuya.get({dps: 2}).then(status => console.log(status))
+
+
+
+tuya.get({schema: true}).then(data => console.log(data))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Sets a property on a device.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters
+
+
+
+
+
+
+
+
+
+
+
+
+ Name |
+ Description |
+
+
+
+
+
+ options.dps Number
+
+ (default 1 )
+ |
+ DPS index to set
+ |
+
+
+
+
+
+ options.set any
+ |
+ value to set
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns
+ Promise<Boolean>
:
+ returns
+true
+ if the command succeeded
+
+
+
+
+
+
+
+
+ Example
+
+
+
+tuya.set({set: true}).then(() => console.log('device was changed'))
+
+
+
+tuya.set({dps: 2, set: true}).then(() => console.log('device was changed'))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ TuyaCipher
+
+
+
+
+
+
+ Class for encrypting and decrypting payloads.
+
+
+ new TuyaCipher(options:
Object)
+
+
+
+
+
+
+
+
+
+
+
+ Parameters
+
+
+
+
+
+
+
+
+
+
+
+
+ Name |
+ Description |
+
+
+
+
+
+ options.key String
+ |
+ localKey of cipher
+ |
+
+
+
+
+
+ options.version Number
+ |
+ protocol version
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Example
+
+
+ const cipher = new TuyaCipher({key: 'xxxxxxxxxxxxxxxx', version: 3.1})
+
+
+
+
+
+
+ Instance Members
+
+
+
+
+
+
+
+
+
+ Encrypts data.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters
+
+
+
+
+
+
+
+
+
+
+
+
+ Name |
+ Description |
+
+
+
+
+
+ options.data String
+ |
+ data to encrypt
+ |
+
+
+
+
+
+ options.base64 Boolean
+
+ (default true )
+ |
+ true
+ to return result in Base64
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns
+ (Buffer | String)
:
+ returns Buffer unless options.base64 is true
+
+
+
+
+
+
+
+
+ Example
+
+
+ TuyaCipher.encrypt({data: 'hello world'})
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Decrypts data.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters
+
+
+
+
+
data (String)
+ to decrypt
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns
+ (Object | String)
:
+ returns object if data is JSON, else returns string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Calculates a MD5 hash.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters
+
+
+
+
+
+
+
+ Returns
+ String
:
+ last 8 characters of hash of data
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ MessageParser
+
+
+
+
+
+
+ Class for decoding and encoding payloads.
+
+
+ new MessageParser()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Static Members
+
+
+
+
+
+
+
+
+
+ Static wrapper for lower-level MessageParser
+functions to easily parse packets.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters
+
+
+
+
+
data (Buffer)
+ packet to parse
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns
+ (Undefined | Object | String)
:
+ An object or string, depending on whether
+data contains an object. Undefined if
+there is no data in packet.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Static wrapper for lower-level MessageParser
+functions to easily encode packets
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters
+
+
+
+
+
+
+
+
+
+
+
+
+ Name |
+ Description |
+
+
+
+
+
+ options.data (String | Buffer | Object)
+ |
+ data to encode
+ |
+
+
+
+
+
+ options.commandByte String
+ |
+ command byte
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns
+ Buffer
:
+ binary payload
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+