cloud-switch-js
TypeScript icon, indicating that this package has built-in type declarations

0.9.0 • Public • Published

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()

/cloud-switch-js/

    Package Sidebar

    Install

    npm i cloud-switch-js

    Weekly Downloads

    0

    Version

    0.9.0

    License

    MIT

    Unpacked Size

    252 kB

    Total Files

    14

    Last publish

    Collaborators

    • jasompi