0.3.3 • Published 7 years ago

nomiku v0.3.3

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

Nomiku JavaScript SDK

This library provides a simple interface to control your WiFi Nomiku. Currently compatible with node v6.x.x

Installing

Installing is as easy as:

npm install --save nomiku

Example

Some example usage:

var NomikuClient = require("nomiku");

var nomiku = new NomikuClient();

nomiku.on("state", function({ state }) {
  console.log("State: " + JSON.stringify(state));
});

nomiku.connect({
  email: process.env.TENDER_EMAIL,
  password: process.env.TENDER_PASSWORD
});

nomiku.on("connect", function() {
  nomiku.set().on();
  nomiku.set().setpoint(55.0);
});

On connect, the client grabs the login token and the list of devices and starts listening to the default device indicated in Tender. It will return the state whenever it changes.

See longer examples in the examples directory

Getting the state

The state event is documented in the API, but the further details of the state object are:

NameTypeDescription
recipeIDnumberRecipe ID currently cooking
recipeTitlestringIndicates whether the state has been emitted before
setpointnumberSet temperature in °C
showFbooleanTrue if temp should be displayed in °F
statenumber-1: offline, 0: online but not heating/circulating, 1: online and running
tempnumberCurrent temperature in °C
timerEndnumberTimer end time in UTC seconds (if timer is running)
timerRunningbooleanWhether timer is running
timerSecsnumberTime remaining in seconds (if timer is not running)

Setting the state

The most straightforward way to update the state is to pass a new state object (only changed keys need to be included) to the set function of device id (omit id to use default device):

nomiku.set(id).state(state)

A number of other convenience functions were created on top of nomiku.set(id):

  • .off() turns off the device
  • .on() turns on the device
  • .setpoint(setpoint) changes setpoint to setpoint in °C
  • .timer.start() starts the timer
  • .timer.stop() stops the timer
  • .timer.set(secs) stops the timer and sets it to secs seconds
  • .units(unit) changes displayed units, unit is either the char 'C' or 'F'
  • .recipe(recipe) starts cooking a new recipe, where recipe has properties:
NameTypeDescription
idnumber(optional) Recipe ID
titlestring(optional) Recipe title
tempnumberSet temperature in °C
timenumberNumber of seconds for the timer

Client API

Functions

Client

Kind: global class

new Client(options)

The Nomiku Client controls the connection to the Nomiku. Descends from EventEmitter

ParamTypeDescription
optionsObjectThe option object. Can also be passed to connect.
options.emailstringtender account email (for email, password login)
options.passwordstringtender account password (for email, password login)
options.userIDstringID of the user (for token login)
options.apiTokenstringAPI token (for token login)

"event:connect"

Successfully connected

Kind: event emitted by Client

"event:close"

Connection is closed

Kind: event emitted by Client

"event:state"

New state

Kind: event emitted by Client
Properties

NameTypeDescription
idnumberTender ID of device
newbooleanIndicates whether the state has been emitted before
stateobjectLatest state
provisionalobjectDict with same keys as state, key is true if it is unconfirmed
validbooleanIndicates whether the state is valid

connect(options)

Connects to server for streaming data

Kind: global function

ParamTypeDescription
optionsObjectThe option object Options:
options.emailstringtender account email (for email, password login)
options.passwordstringtender account password (for email, password login)
options.userIDstringID of the user (for token login)
options.apiTokenstringAPI token (for token login)
options.defaultDevicestring | number(optional) default device to connect to
options.devicesarray(optional) array of devices, {hwid,id,name}
options.verboseStateboolean(optional) will send state event with every message

auth(options)

Gets API token from tender

Kind: global function

ParamTypeDescription
optionsobjectInfo needed to auth with Tender API (email/password)

loadDevices()

Gets device list from Tender

Kind: global function

getDefaultDevice()

Gets default device from Tender

Kind: global function

listen(id)

Listens for state on device

Kind: global function

ParamTypeDescription
idstring | numberTender ID of nomiku to listen to

set(id)

Set state on device

Kind: global function

ParamTypeDescription
idstring | numberTender ID of nomiku to set