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

typedhue

v1.0.0

Published

A PhillipsHue libary written in Typescript

Downloads

8

Readme

TypedHue

A NodjeJS libary for the Phillips Hue API written in Typescript.

What is this?

With this module you can controll your Phillips Hue bridge from NodeJS with all the benefits of Typescript!

Documentation

Run $ npm run generate-doc and open the documentation/ folder with an web-browser(you may need a webserver)

Install

$ npm i --save typedhue

Getting started

You need to get a username/"password" to controll you Huebridge. You can do this by creating a new instance of the Bridge class without an username(last parameter). Max. 30 seconds before executing this code(change the IP to the IP of your bridge) you need to press the button on the Huebridge:

let bridge = new TypedHue.Bridge('192.168.XXX.XXX', (success, username) => { console.log(username); });

The script will now log your username(something like 'SfJR8F3BZ2wb5DUToQNNFKljyNluPFIlx93KKjb4'), this needs to be done only once! With your now obtained username you can create a new instance of the Bridge class with the username(as last parameter) and start using the module! :) In this case the username is 'SfJR8F3BZ2wb5DUToQNNFKljyNluPFIlx93KKjb4' and the ip of the bridge '192.168.2.102'

let bridge = new TypedHue.Bridge('192.168.2.102', (success, username) => {
    // your code here
}, 'SfJR8F3BZ2wb5DUToQNNFKljyNluPFIlx93KKjb4');

How to do something with your lamps

You can access any lamp with the bridge.setLightState() function. The three parameters are

  • id: string - the id of the target light
  • state: State - an State generated by the StateCreator, more about this below
  • callback: Function - a function that ins called determining the success or failure of the statechange

How to generate a state for your lamps

You need to have a State to change a property on your lamp. These States can be generated with the StateCreator class. The class has serveral functions which return an Object that can be handed over the the setLightState() function. You can also combine multiple Stated with the StateCreator.joinStates() function.

Creating an State(this will toggle the light on):

let state = TypedHue.StateCreator.onOffState(true); // { on:true }

Joining/combining multiple states(this will toogle the light on and set its brightness to 200):

let state = TypedHue.StateCreator.joinStates([TypedHue.StateCreator.onOffState(true), TypedHue.StateCreator.setBrightness(200)])

Quick example

This will log all lights connected to the bridge to the console and turn the first one on.

Typescript:

import * as TypedHue from 'typedhue';

let bridge = new TypedHue.Bridge('192.168.2.102', (success:  boolean, username?:  string) => {
    bridge.getLights((lights:  any) => { console.log(lights); });
    bridge.setLightState('1', TypedHue.StateCreator.onOffState(true), (success:  boolean) => {});
}, 'SfJR8F3BZ2wb5DUToQNNFKljyNluPFIlx93KKjb4');

Javascrpt:

const TypedHue = require('typedhue');

let bridge = new TypedHue.Bridge('192.168.2.102', (success, username) => {
    bridge.getLights((lights) => { console.log(lights); });
    bridge.setLightState('1', TypedHue.StateCreator.onOffState(true), () => {});
}, 'SfJR8F3BZ2wb5DUToQNNFKljyNluPFIlx93KKjb4');

Building

Just run $ npm run build