From 5e03e8cc0e9d429ba4e23e0fdacbf910cd62f103 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Sun, 6 Mar 2016 01:24:58 -0500 Subject: [PATCH 1/5] add option for hub ip --- config/config.sample.json | 1 + 1 file changed, 1 insertion(+) diff --git a/config/config.sample.json b/config/config.sample.json index 38cb4ca..037aa2c 100644 --- a/config/config.sample.json +++ b/config/config.sample.json @@ -1,3 +1,4 @@ { + "hub_ip": "192.168.1.106", "mqtt_host": "http://127.0.0.1" } From 81c135114c11f36ad15cb4e21250c8151cac5074 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Sun, 6 Mar 2016 01:26:05 -0500 Subject: [PATCH 2/5] factor out processing and conditionally do it directly on a client or after discovery --- app.js | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/app.js b/app.js index 6e85da8..a05c867 100755 --- a/app.js +++ b/app.js @@ -53,29 +53,34 @@ discover.on('online', function(hubInfo) { console.log('Stopping discovery.') discover.stop() - harmony(hubInfo.ip).then(function(harmonyClient) { - console.log('Harmony client created.') - - harmonyHubClient = harmonyClient - - // update the list of activities - updateActivities() - // then do it on the set interval - clearInterval(harmonyActivityUpdateTimer) - harmonyActivityUpdateTimer = setInterval(function(){ updateActivities() }, harmonyActivityUpdateInterval) - - // update the list of activities on the set interval - clearInterval(harmonyStateUpdateTimer) - harmonyStateUpdateTimer = setInterval(function(){ updateState() }, harmonyStateUpdateInterval) - }) + harmony(hubInfo.ip).then(startProcessing) } }) +if (config['hub_ip']) { + // Connect to hub: + console.log('Connecting to Harmony hub at ' + config['hub_ip']) + harmony(config['hub_ip']).then(startProcessing) +}else{ + // Look for hubs: + console.log('Starting discovery.') + discover.start() +} + +function startProcessing(harmonyClient){ + harmonyHubClient = harmonyClient -// Look for hubs: -console.log('Starting discovery.') -discover.start() + // update the list of activities + updateActivities() + // then do it on the set interval + clearInterval(harmonyActivityUpdateTimer) + harmonyActivityUpdateTimer = setInterval(function(){ updateActivities() }, harmonyActivityUpdateInterval) + + // update the list of activities on the set interval + clearInterval(harmonyStateUpdateTimer) + harmonyStateUpdateTimer = setInterval(function(){ updateState() }, harmonyStateUpdateInterval) +} function updateActivities(){ if (!harmonyHubClient) { return } From 1566b792bd445ec0e67a54bb0aa6d9ae825f022a Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Sun, 6 Mar 2016 01:33:30 -0500 Subject: [PATCH 3/5] document static ip --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9620330..beed7e9 100755 --- a/README.md +++ b/README.md @@ -19,8 +19,20 @@ to control your Harmony Hub, so your control is just a simple HTTP request away. script/bootstrap +## Settings + +Harmony API can discover your hub automatically. You can optionally provide an +IP address for your hub and avoid the discovery process. Add a line to your +`config.json` file to provide the IP address. + +```json +{ + "hub_ip": "192.168.1.106" +} +``` + ## Running It -Get up and running immediatly with `script/server`. +Get up and running immediately with `script/server`. Harmony API will run on port `8282` by default. Use the `PORT` environment variable to use your own port. From a0ee6fc50e69fe93073b9803bb06b218268ede41 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Sun, 6 Mar 2016 01:34:44 -0500 Subject: [PATCH 4/5] remove hub_ip from sample config --- config/config.sample.json | 1 - 1 file changed, 1 deletion(-) diff --git a/config/config.sample.json b/config/config.sample.json index 037aa2c..38cb4ca 100644 --- a/config/config.sample.json +++ b/config/config.sample.json @@ -1,4 +1,3 @@ { - "hub_ip": "192.168.1.106", "mqtt_host": "http://127.0.0.1" } From 4c3f6d4d9402097d3abe43922896a2f3a3e9b2f9 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Sun, 6 Mar 2016 01:34:54 -0500 Subject: [PATCH 5/5] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 81a1307..9b92c6c 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "harmony-api", - "version": "0.4.1", + "version": "0.5.0", "description": "A simple server providing a RESTful service for controlling a Harmony Hub.", "scripts": { "start": "node app.js"