npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nuki-bridge-api

v1.8.0

Published

An API for Nuki Bridge

Downloads

359

Readme

nuki-bridge-api

An API for Nuki Bridge

How it works

Get Bridge Connection

var NukiBridgeApi = require('nuki-bridge-api');

var ip = '127.0.0.1';
var port = 12345;
var token = 'token';

var bridge = new NukiBridgeApi.Bridge(ip, port, token);

Bridge Discovery

var NukiBridgeApi = require('nuki-bridge-api');

var bridge = NukiBridgeApi.DiscoveredBridge.discover().then(function connectNow (bridges) {
    // Connect to a bridge
    return bridges[0].connect();
}).then(function gotRealBridge (bridge) {
    // Do something with the bridge
});

Get Nukis

var bridge = new NukiBridgeApi.Bridge(ip, port, token);

bridge.list().then(function gotNukis (nukis) {
    // Do something with the nukis
});

Do something with the bridge

Get info:

bridge.info().then(function gotInfo (info) {
...
})

Get and remove logs:

bridge.log().then(function gotLogs (logs) {
  return bridge.clearlog();
})

Do a firmware update

bridge.fwupdate();

Reboot

bridge.reboot();

What can i do with a nuki instance

var NukiBridgeApi = require('nuki-bridge-api');
var lockStates = NukiBridgeApi.lockState;
var lockActions = NukiBridgeApi.lockAction;

...

nuki.lockState().then(function (lockState) {
    if (lockState === lockStates.LOCKED) {
        return nuki.lockAction(lockActions.UNLOCK);
    } else if (lockState === lockStates.UNLOCKED) {
        return nuki.lockAction(lockActions.LOCK);
    }
});

Getting Callbacks

nuki.getCallbacks().then(function doSomethingWithThe (callbacks) {
...
});

or add one (and with the 3rd 'listen' flag, it is easy to listen on the callbacks too)

nuki.addCallback('localhost', 12321, true).then(function gotCallbackRegistered (callback) {
...
});

Callbacks

The callbacks which you get with getCallbacks or addCallback have the functions remove which removes the callback from the bridge (and closes the webserver which gets created when you call addCallback with listen=true) and startListen which starts a webserver and listens for callbacks from the bridge.

If a callback is received, the nuki-instance and the callback itself emits events. The action event is fired with the state (a number corresponding to the LockStates) as first parameter and the full body as second. Additional a event is fired, with the name of the lock-state (e.g. 1 for an Locked-Event).

Does it warn me if the battery is low?

Yes, every nuki instance is an event-emitter, which emits a batteryCritical event if any request receives the flag.