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

harmonyhub-api

v1.0.8

Published

Harmony Hub API that use the local websocket API of the hub

Downloads

99

Readme

Harmony Hub API (with local websocket)

This module tend to replace the old XMPP API which was removed with the firemware 4.15.206 (see more here).

It uses the local websocket API of the hub.

UPDATE 23/12/2018 Logitech reversed his decision about the XMPP API. It makes available back the API but only for developers. see more here. The local websocket API remains available.

Usage

Installation

$ npm install harmonyhub-api

Get the remote id of the hub

Use the following helper:

$ node_modules/.bin/harmonyhub-remote-id <hub_ip_or_host>

Or juste make the following http post

Host: <hub_host_or_ip>:8088
Origin: http://sl.dhg.myharmony.com
Content-Type: application/json
Accept-Charset: utf-8

{
    "id ": 1,
    "cmd": "setup.account?getProvisionInfo",
    "params": {}
}

Example with curl

$ curl -X POST <hub_host_or_ip>:8088 -H 'Accept: utf-8' -H 'Content-Type: application/json' -H 'Origin: http://sl.dhg.myharmony.com' -d '{"id":1,"cmd":"setup.account?getProvisionInfo","params":{}}'

Connection and configuration

const HarmonyHub = require('harmonyhub-api').HarmonyHub;
const HUB_HOST = 'X.X.X.X';
const HUB_REMOTE_ID = 'XXXXXXX';
const hub = new HarmonyHub(HUB_HOST, HUB_REMOTE_ID);

hub.connect()
    .then((config) => {
        console.log('Connected to the hub');

        console.log('\nActivities\n==========');
        config.activity.forEach(activity => {
            console.log(`${activity.label} (${activity.id})`);
        });

        console.log('\nDevices\n========');
        config.device.forEach(device => {
            console.log(`${device.label} (${device.id})`);
        });
    });

:warning: Without activities, the connection is automatically closed after 60 seconds. You can periodically send a ping or catch the close event to open a new connection.

Start an activity

The list of activityId can be found in the configuration object or with hub.getActivities()

hub.startActivity('xxxxxx');

Send command to a device

The list of commands and deviceId can be found in the configuration object of each devices. Browse the content of hub.getDevices().

// Simple press
hub.sendCommand('VolumeUp', '53161273');

// Hold a press for 1 second
hub.holdCommand('VolumeUp', '53161273', 1000);

Close the connection

hub.disconnect();

Listen for events

The HarmonyHub object is a EventEmitter for some events :

hub.on('error|connect|close|message', callback)
  • error : On error on the websocket
    • 1 argument: the error
  • connect : On connection to the websocket of the hub
    • 1 argument: the config of the hub
  • close : On the websocket connection close
    • 2 arguments: code and description
  • message : On incoming message from the hub
    • 1 argument: The message data

Log level

By default, the logger is set on 'warn'. You can override with the LOG_LEVEL environnement variable. eg:

$ LOG_LEVEL=debug node test.js

API documentation

The full API documentation is available in the docs/ folder.