2.0.1 • Published 5 months ago

nanoleaf-client-multi v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

nanoleaf-client

NPM version MIT License Bundle size Build Coverage Status

Prerequisites

Make sure you have installed all of the following prerequisites on your development machine:

Cloning and the GitHub repository

The recommended way to get Nanoleaf Client is to use git to directly clone repository:

$ git clone https://github.com/VadimGarkusha/nanoleaf-client.git

This will clone the latest version of the Nanoleaf Client repository.

Installing the npm package

To install the dependencies, run this in the application folder from the command-line:

$ npm install nanoleaf-client

Service Discovery

In order to use the client you need to know your device IP on the network and a user token.

Get device IP. NOTE: before running this command make sure the device is plugged in and is connected to the network. You can check it with phone app.

Be careful with IPs! Sometimes, if you plug out the device or a router an IP address might change.

Getting device IP

import { ServiceDiscovery } from 'nanoleaf-client';

let serviceDiscovery = new ServiceDiscovery();

serviceDiscovery.discoverNanoleaf().then(devices => {

  // devices is an array of all Nanoleaf devices found on the network.
  // device info contains location info, uuid and device Id.
  console.log(devices);
});

Getting token

Before executing this command, hold power button on your nanoleaf device for 5 seconds until the white LED starts glowing. After that you have 30 seconds to execute this command and get a token. Client will be authorized automatically.

NOTE: Device can hold up to 5 tokens. New tokens come in FIFO order.

client.authorize().then(token => {
    console.log(token);
}).catch(err => {
    console.log(err);
});

Supported Methods

Nanoleaf Client

General Requests

  • getInfo() - returns object with information about current state of device
  • identify() - causes panels to flash in unison, returns response with status if successful
  • authorize() - authorizes nanoleaf client for future requests and returns string auth token
  • getGlobalOrientation() - returns object with global orientation value

Power

  • turnOn() - turns on the device
  • turnOff() - turns off the device
  • power(power) - accepts boolean parameter and sets device power status
  • getPowerStatus() - returns object with power status

Saturation

  • getSaturation() - returns object with current saturation value
  • setSaturation(value) - accepts numerical parameter and sets saturation value
  • incrementSaturation(increment) - accepts numerical parameter and incerements saturation value by it

Brightness

  • getBrightness() - returns object with current brightness value
  • setBrightness(value) - accepts numerical parameter and sets brightness value
  • increaseBrightness(increment) - accepts numerical parameter and incerements brightness value by it
  • setDurationBrightness(value, duration) - accepts two numerical parameter and sets brightness value for duration period

Hue

  • getHue() - returns object with current hue value
  • setHue(value) - accepts numerical parameter and sets hue value
  • increaseHue(increment) - accepts numerical parameter and incerements hue value by it

Color Temperature

  • getColorTemperature() - returns current color temperature value
  • setColorTemperature(value) - accepts numerical parameter and sets color temperature value
  • incrementColorTemperature(increment) - accepts numerical parameter and incerements color temperature value by it

Effect/Theme

  • getColorMode() - returns string with current color temperature value ct (color temperature), hs (hue/saturation), or effect
  • getSelectedEffect() - returns string with selected effect
  • getEffectInfo(effectName) - accepts string with effect name and returns object with effect properties
  • setEffect(value) - accepts string with effect names and sets it as current effect
  • getEffectList() - returns array of strings with available effects

Color

  • setHsvColor(h, s, v) - accepts three numerical parameters and sets hsv color based on them
  • setHslColor(h, s, l) - accepts three numerical parameters and sets hsl color based on them
  • setHexColor(hexString) - accepts string parameter with hex values and sets color based on it
  • setRgbColor(r, g, b) - accepts three numerical parameters and sets rgb color based on them

Examples

Setting up client

import { NanoleafClient } from 'nanoleaf-client';

 let client = new NanoleafClient('<device_ip>', '<user_token>');

// For example
let client = new NanoleafClient('192.168.0.10', 'qEQ8ZLcPuOVesarDXIW6eGQQd1Hhn1d9');

// Without token
let noTokenClient = new NanoleafClient('192.168.0.10');

// Adding token later
noTokenClient.authorize('qEQ8ZLcPuOVesarDXIW6eGQQd1Hhn1d9');

Turn on/off

client.turnOn().then(res => {
    console.log(res);
}).catch(err => {
    console.log(err);
});

client.turnOff().then(res => {
    console.log(res);
}).catch(err => {
    console.log(err);
});

Get device info

client.getInfo().then(res => {
    console.log(res);
}).catch(err => {
    console.log(err);
});

License

This project is licensed under the MIT License - see the LICENSE.md file for details