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

haiku-senseme

v1.1.0

Published

Control SenseME enabled devices from Haiku

Downloads

7

Readme

haiku-senseme

Control your fans and other Big Ass devices

NPM Version GitHub license Dependency status

haiku-senseme is a Node.js module for controlling SenseME-enabled devices by Haiku.

Installation

This module is distributed through NPM:

npm install haiku-senseme --save

Examples

This module handles two aspects of working with SenseME devices: discovery and control. Discovered devices are presented as a series of founddevice events; when devices disappear, a lostdevice event will be emitted.

For example, to print the names of all SenseME devices on the local network:

import { SenseME } from 'haiku-senseme';

SenseME
  .on('founddevice', dev => {
    console.log(`Found: ${dev.name}`);
  })
  .on('lostdevice', dev => {
    console.log(`Lost: ${dev.name}`);
  })
  .discover();

Discovery will continue indefinitely until you stop it:

import { SenseME } from 'haiku-senseme';

SenseME.cancelDiscovery();
SenseME.getAllDevices().forEach(dev => dev.disconnect());

If you know the IP address and either the name or the MAC address of your device, you can skip discovery altogether if you prefer:

import { Device } from 'haiku-senseme';

const dev = new Device({ name: 'Living Room Fan', ip: 'aaa.bbb.ccc.ddd' });

// It's too cold in here.
dev.fan.power.value = 'off';

Controllable properties of the fan are exposed as a set of nested properties on the Device object. For instance:

// Turn the fan on
dev.fan.power.value = 'on';

// How about a light breeze?
dev.fan.whooshMode.value = 'on';

// Plus, it's a little dark...
dev.light.power.value = 'on';

// But that's too much!
dev.light.brightness.value = 3;

For full details, see the API docs.

Since other devices on the network might change some of these values, it's also possible to request fresh values directly from the fan, as well as to get notification when values change:

dev.fan.speed.refresh();

// keep track of changes in speed
dev.fan.speed.listen()
  .on('change', speed => console.log(`Current speed: ${speed}`));

// keep track of any change to any property
dev.listenAll()
  .on('change', ({ path, value }) => {
      console.log(JSON.stringify(path));
      // prints ["fan", "speed"]

      console.log(value);
      // prints 5
  });

dev.fan.speed.value = 5;

If you install one of the Observable libraries supported by any-observable, you can also get property change notifications as an Observable stream:

import 'any-observable/register/rxjs-all';
import { Device } from 'haiku-senseme';

const dev = new Device({ name: 'Living Room', ip: '...' });

// It's very important that I know when the fan speed drops below 3...
dev.fan.speed
  .observe()
  .map(x => x < 3)
  .distinctUntilChanged()
  .filter(x => x)
  .subscribe(
    x => console.log(`Oh no! The fan's going too slow! (current speed: ${x}`)
  );

// You can also observe changes in all properties
dev.observeAll()
  // but really I only care about fan properties
  .filter(({ path: [category] }) => category === 'fan')
  .subscribe(
    ({ path: [, ...prop], value }) => {
      console.log(`Something about the fan has changed: ${prop}, ${value}`);
    }
  );

Contributing

Contributions are of course always welcome. If you find problems, please report them in the Issue Tracker. If you've made an improvement, open a pull request.

Getting set up for development is very easy:

git clone <your fork>
cd haiku-senseme
npm install -g babel-cli # if you don't already have it
npm install

And the development workflow is likewise straightforward:

# make a change to the src/ file, then...
npm run build
npm run example # run the bundled example script

# if you change the documentation:
npm run docs

# or if you want to clean up all the leftover build products:
npm run clean

Release History

  • 1.1.0

    • Split QueuedSocket.js into its own module, now called message-socket
    • Switch from js-logger to debug for logging.
  • 1.0.0

    • The first release.

Meta

Zach Bean – [email protected]

Distributed under the MIT license. See LICENSE for more detail.