1.0.1 • Published 2 years ago

nleaf.js v1.0.1

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

nleaf.js

A Wrapper for the Nanoleaf Open API with Typescript support

NOTE: This has only been tested on my Nanoleaf Shapes and i cannot confirm this will work on other devices as well

Install

npm i nleaf.js

1 Features

  • Authorization
  • General Panel Info and State
  • Effects Control (-- NEEDS MORE TESTING --)
  • Real-Time Touch Data
  • Events
  • Discovery

2 Examples

2.1 Simple Client

import { Nanoleaf } from "nleaf.js";

const device = new Nanoleaf({
    host: "192.168.1.100",
    accessToken: "abcdefghijklmnopqrstuvwxyz012345"
});

(async () => {
    /// Set color of all panels ///
    await device.setHSB(215, 81, 82); // Set all panels to a blue-ish color

    /// Panel Layout ///
    let layout = await device.layout();
    console.log(layout);

})();

2.2 Discovery

import { Nanoleaf } from "nleaf.js";

// This will be called when a device is discovered
Nanoleaf.discovery.onDiscovered = function(res) {
    console.log("Discovered a Nanoleaf Device:", res);
};

Nanoleaf.discovery.start();

// Nanoleaf.discovery.stop()
// Can be used to stop the search

2.3 Live Touch Data

This example shows how to get live touch data from the panels

import { Nanoleaf } from "nleaf.js";

const device = new Nanoleaf({
    host: "192.168.1.100",
    accessToken: "abcdefghijklmnopqrstuvwxyz012345",

    touch: {
        enabled: true
    }
});

device.on("touch", (event) => {
    console.log("Touch Event:", event);
})

2.4 Authorization

import { Nanoleaf } from "nleaf.js";

let token = Nanoleaf.auth.getToken("http://192.168.1.100/");
console.log(token);

3 Client Options

OptionTypeOptionalDefaultDescription
hoststringno-IP Address of the Device
accessTokenstringno-Access Token to the Device
portnumberyes16021API Port
versionstringyesv1API Version
touchobjectyes{}Live Touch Data Options
touch.enabledbooleanyesfalseLive Touch Data enabled?
touch.portnumberyes35508UDP Touch Server port on localhost