Skip to content

Latest commit

 

History

History
99 lines (70 loc) · 4.66 KB

API.md

File metadata and controls

99 lines (70 loc) · 4.66 KB

Docs

Table of Contents

TuyaDevice

Represents a Tuya device.

Parameters

  • options Object options for constructing a TuyaDevice
    • options.type String type of device (optional, default 'outlet')
    • options.ip String? IP of device
    • options.port Number port of device (optional, default 6668)
    • options.id String ID of device
    • options.uid String UID of device (optional, default '')
    • options.key String encryption key of device
    • options.version Number protocol version (optional, default 3.1)

Examples

const tuya = new TuyaDevice({id: 'xxxxxxxxxxxxxxxxxxxx', key: 'xxxxxxxxxxxxxxxx'})
const tuya = new TuyaDevice([
{id: 'xxxxxxxxxxxxxxxxxxxx', key: 'xxxxxxxxxxxxxxxx'},
{id: 'xxxxxxxxxxxxxxxxxxxx', key: 'xxxxxxxxxxxxxxxx'}])

resolveIds

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

get

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

  • options Object? optional options for getting data
    • options.id String? ID of device
    • options.schema Boolean? true to return entire schema, not just the first result

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

set

Sets a property on a device.

Parameters

  • options Object options for setting properties
    • options.id String? ID of device
    • options.set Boolean true for on, false for off
    • options.dps Number? dps index to change

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