0.9.0 • Published 2 years ago

cloud-switch-js v0.9.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Cloud Switch JS API

This nodejs module provide API to control Cloud Switch.

Install

npm i cloud-switch-js

Example usage

import { CloudSwitch } from 'cloud-switch-js'
import fs from 'fs'

export interface Settings {
  auth: string // access token
  deviceId: string // deviceID
}
function getTestSettings (): Settings {
  const settings = JSON.parse(
    fs.readFileSync('./settings.json', 'utf-8')
  ) as Settings
  return settings
}

async function run (): Promise<void> {
  const settings = getTestSettings()
  const cloudSwitch = await CloudSwitch.createCloudSwitchForId(settings.deviceId, settings.auth)
  console.log(`${cloudSwitch.name()} is ${cloudSwitch.isOnline() ? 'online' : 'offline'}`)

  if (cloudSwitch.isOnline()) {
    // Toggle Switch #4
    await cloudSwitch.toggleSwitch(4)
  }
}

void run().then().catch()