Represents a Tuya device.
Parameters
optionsObject options for constructing a TuyaDeviceoptions.typeString type of device (optional, default'outlet')options.ipString? IP of deviceoptions.portNumber port of device (optional, default6668)options.idString ID of deviceoptions.uidString UID of device (optional, default'')options.keyString encryption key of deviceoptions.versionNumber protocol version (optional, default3.1)
Examples
const tuya = new TuyaDevice({id: 'xxxxxxxxxxxxxxxxxxxx', key: 'xxxxxxxxxxxxxxxx'})const tuya = new TuyaDevice([
{id: 'xxxxxxxxxxxxxxxxxxxx', key: 'xxxxxxxxxxxxxxxx'},
{id: 'xxxxxxxxxxxxxxxxxxxx', key: 'xxxxxxxxxxxxxxxx'}])Resolves IDs stored in class to IPs. If you didn't pass IPs to the constructor, you must call this before doing anything else.
Returns Promise<Boolean> true if IPs were found and devices are ready to be used
Gets a device's current status. Defaults to returning only the value of the first result, but by setting {schema: true} you can get everything.
Parameters
optionsObject? optional options for getting data
Examples
// get status for device with one property
tuya.get().then(status => console.log(status))// get status for specific device with one property
tuya.get({id: 'xxxxxxxxxxxxxxxxxxxx'}).then(status => console.log(status))// get all available data from device
tuya.get({schema: true}).then(data => console.log(data))Returns Promise<Object> returns boolean if no options are provided, otherwise returns object of results
Sets a property on a device.
Parameters
optionsObject options for setting properties
Examples
// set default property on default device
tuya.set({set: true}).then(() => console.log('device was changed'))// set custom property on non-default device
tuya.set({id: 'xxxxxxxxxxxxxxxxxxxx', 'dps': 2, set: true}).then(() => console.log('device was changed'))Returns Promise<Boolean> returns true if the command succeeded