wattbox
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

wattbox

npm GitHub Workflow Status GitHub

Promise based node implementation of the WattBox control API

Installing

Using NPM:

npm install wattbox

Using Yarn:

yarn add wattbox

Example

Turn on an outlet on the WattBox

import { WattBoxPromise } from 'wattbox';

var wattbox = new WattBoxPromise('username', 'password', '192.168.1.25');

wattbox.powerOn(2).catch((err) => {
    console.log(err);
});

Reset an outlet with a custom period of time

import { WattBoxPromise } from 'wattbox';

var wattbox = new WattBoxPromise('username', 'password', '192.168.1.25');

// Turns the outlet off, waits for 5 seconds, then turns the outlet back on
wattbox.powerResetTimeout(2, 5000).catch((err) => {
    console.log(err);
});

Subscribe to status updates from the WattBox

import { WattBoxPromise } from 'wattbox';

var wattbox = new WattBoxPromise('username', 'password', '192.168.1.25');

wattbox.subscribeStatus(5000);

wattbox.on('status', (status) => {
    console.log(status);
});

wattbox.on('error', (error) => {
    console.log(error);
});

Methods

Power on the selected outlet:

wattbox.powerOn(<outlet>)

Power off the selected outlet:

wattbox.powerOff(<outlet>)

Power cycle the selected outlet:

wattbox.powerReset(<outlet>)

Power cycle the outlet with a custom period of time:

wattbox.powerResetTimeout(<outlet>, <time>)

Enable auto reboot:

wattbox.autoRebootOn()

Disable auto reboot:

wattbox.autoRebootOff()

Get info about the wattbox. Returns a JSON object containing device info:

wattbox.getInfo()

Subscribe to device status updates. Returns a JSON object containing the device status:

wattbox.subscribeStatus(<time>)

Receive the status and errors thusly:

wattbox.on('status', (status) => {
    console.log(status)
})

wattbox.on('error', (error) => {
    console.log(error)
})

Unsubscribe from status updates:

wattbox.unsubscribeStatus()

Issues and Feature Requests

Please open an issue on the GitHub page

This project is licensed under the MIT license

Readme

Keywords

none

Package Sidebar

Install

npm i wattbox

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

27.7 kB

Total Files

15

Last publish

Collaborators

  • jtf4