0.2.0 • Published 4 years ago

@redgrid/tuya-ac-api v0.2.0

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

TUYA-AC-API

An extension to @tuyapi/openapi that adds support for calling functins to control airconditioners via IR

Usage

const TuyaAcApi = require('./lib')

const apiConfig = {
  key: 'xxx',
  secret: 'xxx',
  schema: 'xxx'
}

async function main () {
  const api = new TuyaAcApi(apiConfig)
  await api.getToken() // must call this first

  // control a non-IR device (e.g. a smart plug)
  const deviceId = '55780007bcddc2af5cd6'
  // get its functions
  const functions = await api.functions(deviceId)
  console.log(functions)
  // call one to switch it on
  const response = await api.sendCommands(deviceId, [
    {
      code: 'switch',
      value: true
    }
  ])

  // control and IR device
  const brands = await api.getSupportedBrands('<device-id>')
  const remote_indices = await api.getSupportedRemotes('<device-id>', '<brand-id>')

  // need to add a remote to an IR device before it is possible to send keys
  await api.addRemote('<device-id>', '<remote-index>')

  const status = await api.status('<device-id>', '<remote-id>')
  console.log(status)

  const result = await api.sendKeys('<device-id>', '<remote-id>', '<remote-index', { power: 1, temp: 20 })

  const updatedStatus = await api.status('<device-id>', '<remote-id>')
  console.log(updatedStatus)
}

main()
  .catch(err => {
    console.error(err)
  })