### @tuyapi/link

`0.1.0`
Need help reading this?

### TuyaLinkWizard

A wrapper that combines `@tuyapi/cloud` and `(@tuyapi/link).manual` (included in this package) to make registration Just Work™️. Exported as `(@tuyapi/link).wizard`.

new TuyaLinkWizard(options: Object)
Parameters
options `(Object)` construction options

Name | Description
--- | ---
options.apiKey `String` | API key
options.apiSecret `String` | API secret
options.email `String` | user email
options.password `String` | user password
options.region `String` (default `'AZ'`) | region (AZ=Americas, AY=Asia, EU=Europe)
options.timezone `String` (default `'-05:00'`) | timezone of device

Example

    // Note: user account does not need to already exist
    const register = new TuyaLink.wizard({key: 'your-api-key',
                                              secret: 'your-api-secret',
                                              email: 'example@example.com',
                                              password: 'example-password'});

Instance Members
▸ init()

Logins to Tuya cloud using credentials provided to constructor

init(): Promise<String>
Returns
`Promise<String>`: A Promise that contains the session ID
Example

    register.init()

▸ linkDevice(options)

Links device to WiFi and cloud

linkDevice(options: Object): Promise<Object>
Parameters
options `(Object)` options

Name | Description
--- | ---
options.ssid `String` | the SSID to send to the device
options.wifiPassword `String` | password for the SSID
options.devices `Number` (default `1`) | if linking more than 1 device at a time, set to number of devices being linked

Returns
`Promise<Object>`: A Promise that contains data on device(s)
Example

    register.linkDevice({ssid: 'HOME-C168',
    wifiPassword: '795F48E494285B6A'}).then(device => {
      console.log(device);
    });

### TuyaLink

A lower level option for linking devices. Use only if you're not generating a token through `@tuyapi/cloud`. Exported as `(@tuyapi/link).manual`. Currently has no options, but some may be added in the future.

new TuyaLink(options: Object)
Parameters
options `(Object)` construction options
Example

    const register = new TuyaLink.manual({});

Instance Members
▸ registerSmartLink(options)

Thin wrapper for this.sendSmartLinkStart() and this.sendSmartLinkData(). Unless you have a special use case, prefer this method over calling this.sendSmartLinkStart() and this.sendSmartLinkData() directly.

registerSmartLink(options: Object): Promise<Undefined>
Parameters
options `(Object)` options

Name | Description
--- | ---
options.region `String` | region (see smartLinkEncode() for options)
options.token `String` | generated token to send
options.secret `String` | generated secret to send
options.ssid `String` | SSID to connect to
options.wifiPassword `String` | password of WiFi

Returns
`Promise<Undefined>`: A Promise that resolves when all data has been transmitted
Example

    device.registerSmartLink({region: 'AZ',
                              token: '00000000',
                              secret: '0101',
                              ssid: 'Example SSID',
                              wifiPassword: 'example-password'}).then(() => {
     console.log('Done!');
    });

▸ sendSmartLinkStart()

Transmits start pattern of packets (1, 3, 6, 10) 144 times with a delay between transmits.

sendSmartLinkStart(): Promise<Undefined>
Returns
`Promise<Undefined>`: A Promise that resolves when data has been transmitted
▸ sendSmartLinkData(data)

Transmits provided data as UDP packet lengths 30 times with a delay between transmits.

sendSmartLinkData(data: Array): Promise<Undefined>
Parameters
data `(Array)` of packet lengths to send
Returns
`Promise<Undefined>`: A Promise that resolves when data has been transmitted
▸ smartLinkEncode(options)

Encodes data as UDP packet lengths.

smartLinkEncode(options: Object): Array
Parameters
options `(Object)` options

Name | Description
--- | ---
options.region `String` | two-letter region (AZ=Americas, AY=Asia, EU=Europe)
options.token `String` | token
options.secret `String` | secret
options.ssid `String` | SSID
options.wifiPassword `String` | password of WiFi

Returns
`Array`: array of packet lengths
▸ cleanup()

Un-references UDP instance so that a script can cleanly exit.

cleanup()