From 6e61287f59c414300583a5d6c800f433f8d36d67 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Mon, 3 Aug 2015 08:33:41 -0700 Subject: [PATCH 01/16] Use WIP version of HAP-NodeJS refactor --- accessories/WeMo.js | 2 +- app.js | 130 ++++++++++---------------------------------- package.json | 2 +- 3 files changed, 32 insertions(+), 102 deletions(-) diff --git a/accessories/WeMo.js b/accessories/WeMo.js index 0313878..273e4b3 100644 --- a/accessories/WeMo.js +++ b/accessories/WeMo.js @@ -68,7 +68,7 @@ WeMoAccessory.prototype = { if (!err) { var binaryState = parseInt(result) that.log("power state for " + that.wemoName + " is: " + binaryState) - callback(binaryState) + callback(binaryState > 0 ? 1 : 0); } else { that.log(err) diff --git a/app.js b/app.js index 7ed29d1..272bde7 100644 --- a/app.js +++ b/app.js @@ -1,7 +1,10 @@ var fs = require('fs'); var path = require('path'); var storage = require('node-persist'); -var crypto = require('crypto'); +var uuid = require('HAP-NodeJS').uuid; +var Bridge = require('HAP-NodeJS').Bridge; +var Accessory = require('HAP-NodeJS').Accessory; +var accessoryLoader = require('HAP-NodeJS').AccessoryLoader; console.log("Starting HomeBridge server..."); @@ -15,23 +18,34 @@ if (!fs.existsSync(configPath)) { } // Initialize persistent storage -storage.initSync(); +//storage.initSync(); + +// Start by creating our Bridge which will host all loaded Accessories +var bridge = new Bridge('HomeBridge', uuid.generate("HomeBridge")); // Load up the configuration file var config = JSON.parse(fs.readFileSync(configPath)); -// Just to prevent them getting garbage collected -var accessories = []; +// keep track of async calls we're waiting for callbacks on before we can start up +var asyncCalls = 0; function startup() { - if (config.platforms) loadPlatforms(); +// if (config.platforms) loadPlatforms(); if (config.accessories) loadAccessories(); + + bridge.publish({ + username: "CC:22:3D:E3:CE:27", + port: 51826, + pincode: "031-45-154", + category: Accessory.Categories.OTHER + }); } function loadAccessories() { // Instantiate all accessories in the config console.log("Loading " + config.accessories.length + " accessories..."); + for (var i=0; i Date: Tue, 4 Aug 2015 09:24:35 -0700 Subject: [PATCH 02/16] Update HAP-NodeJS version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dcdeedb..1f8a536 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#aaa5770488d698d777e7d7706909c3afa888b031", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#4bf650d", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From f71730cff6925692af83ef662e15837f72af2965 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Tue, 4 Aug 2015 15:48:52 -0700 Subject: [PATCH 03/16] Restore platform support --- app.js | 58 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/app.js b/app.js index 272bde7..f692477 100644 --- a/app.js +++ b/app.js @@ -18,7 +18,7 @@ if (!fs.existsSync(configPath)) { } // Initialize persistent storage -//storage.initSync(); +storage.initSync(); // Start by creating our Bridge which will host all loaded Accessories var bridge = new Bridge('HomeBridge', uuid.generate("HomeBridge")); @@ -27,18 +27,19 @@ var bridge = new Bridge('HomeBridge', uuid.generate("HomeBridge")); var config = JSON.parse(fs.readFileSync(configPath)); // keep track of async calls we're waiting for callbacks on before we can start up +// this is hacky but this is all going away once we build proper plugin support var asyncCalls = 0; +var asyncWait = false; function startup() { -// if (config.platforms) loadPlatforms(); + asyncWait = true; + if (config.platforms) loadPlatforms(); if (config.accessories) loadAccessories(); + asyncWait = false; - bridge.publish({ - username: "CC:22:3D:E3:CE:27", - port: 51826, - pincode: "031-45-154", - category: Accessory.Categories.OTHER - }); + // publish now unless we're waiting on anyone + if (asyncCalls == 0) + publish(); } function loadAccessories() { @@ -81,6 +82,7 @@ function loadAccessories() { function loadPlatforms() { console.log("Loading " + config.platforms.length + " platforms..."); + for (var i=0; i Date: Tue, 4 Aug 2015 15:49:50 -0700 Subject: [PATCH 04/16] Use latest refactor commit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1f8a536..f3c80ce 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#4bf650d", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#a03e73b", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From c756ea9456805546bb70679fcd9c4fb8f31a7a16 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Tue, 4 Aug 2015 16:00:52 -0700 Subject: [PATCH 05/16] HAP-NodeJS Bump for stable IDs --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f3c80ce..564c097 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#a03e73b", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#b1d5257", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From f7f953b8d121f8f535319e09536798ed3b635bf5 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Tue, 4 Aug 2015 16:21:06 -0700 Subject: [PATCH 06/16] Fix name/log var corruption --- app.js | 59 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/app.js b/app.js index f692477..e2fe09d 100644 --- a/app.js +++ b/app.js @@ -100,34 +100,39 @@ function loadPlatforms() { var platformInstance = new platformConstructor(log, platformConfig); - // query for devices - asyncCalls++; - platformInstance.accessories(function(foundAccessories){ - asyncCalls--; - // loop through accessories adding them to the list and registering them - for (var i = 0; i < foundAccessories.length; i++) { - var accessoryInstance = foundAccessories[i]; - - log("Initializing device with name " + accessoryInstance.name + "...") - - // Extract the raw "services" for this accessory which is a big array of objects describing the various - // hooks in and out of HomeKit for the HAP-NodeJS server. - var services = accessoryInstance.getServices(); - - // Create the actual HAP-NodeJS "Accessory" instance - var accessory = accessoryLoader.parseAccessoryJSON({ - displayName: name, - services: services - }); + // wrap name and log in a closure so they don't change in the callback + function getAccessories(name, log) { + asyncCalls++; + platformInstance.accessories(function(foundAccessories){ + asyncCalls--; + // loop through accessories adding them to the list and registering them + for (var i = 0; i < foundAccessories.length; i++) { + var accessoryInstance = foundAccessories[i]; + + log("Initializing device with name " + accessoryInstance.name + "...") + + // Extract the raw "services" for this accessory which is a big array of objects describing the various + // hooks in and out of HomeKit for the HAP-NodeJS server. + var services = accessoryInstance.getServices(); + + // Create the actual HAP-NodeJS "Accessory" instance + var accessory = accessoryLoader.parseAccessoryJSON({ + displayName: name, + services: services + }); - // add it to the bridge - bridge.addBridgedAccessory(accessory); - } - - // were we the last callback? - if (asyncCalls === 0 && !asyncWait) - publish(); - }) + // add it to the bridge + bridge.addBridgedAccessory(accessory); + } + + // were we the last callback? + if (asyncCalls === 0 && !asyncWait) + publish(); + }) + } + + // query for devices + getAccessories(name, log); } } From c9aea1b7317ab5d14d57b9f0ebbf20ebadb812c2 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Tue, 4 Aug 2015 16:44:34 -0700 Subject: [PATCH 07/16] Initialize HAP storage --- app.js | 5 +++-- package.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index e2fe09d..b24ad18 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,7 @@ var fs = require('fs'); var path = require('path'); var storage = require('node-persist'); +var hap = require('HAP-NodeJS'); var uuid = require('HAP-NodeJS').uuid; var Bridge = require('HAP-NodeJS').Bridge; var Accessory = require('HAP-NodeJS').Accessory; @@ -17,8 +18,8 @@ if (!fs.existsSync(configPath)) { process.exit(1); } -// Initialize persistent storage -storage.initSync(); +// Initialize HAP-NodeJS +hap.init(); // Start by creating our Bridge which will host all loaded Accessories var bridge = new Bridge('HomeBridge', uuid.generate("HomeBridge")); diff --git a/package.json b/package.json index 564c097..760cb6b 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#b1d5257", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#96414ff", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 9653a3173d109ee9ffc8231a86d2aabd7a50fb66 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Tue, 4 Aug 2015 20:32:05 -0700 Subject: [PATCH 08/16] Bump HAP-NodeJS --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 760cb6b..7e14532 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#96414ff", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#efaf9d2", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 43c03464363c29de30e78b92282c2de4a730ad2c Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Wed, 5 Aug 2015 08:55:19 -0700 Subject: [PATCH 09/16] [Sonos] SUB isn't playable --- platforms/Sonos.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/Sonos.js b/platforms/Sonos.js index 15523c6..7ff0efc 100644 --- a/platforms/Sonos.js +++ b/platforms/Sonos.js @@ -17,7 +17,7 @@ SonosPlatform.prototype = { that.log("Found device at " + device.host); device.deviceDescription(function (err, description) { - if (description["zoneType"] != '11') { + if (description["zoneType"] != '11' && description["zoneType"] != '8') { // 8 is the Sonos SUB that.log("Found playable device - " + description["roomName"]); // device is an instance of sonos.Sonos var accessory = new SonosAccessory(that.log, that.config, device, description); From 6fff108ccd250ed3cc0814ca2ddcdb6b010fae6b Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Thu, 6 Aug 2015 09:58:03 -0700 Subject: [PATCH 10/16] Bump HAP-NodeJS --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7e14532..8b106e5 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#efaf9d2", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#3b1eaa8", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 3a819e202d354f4e4583aaf830b3dc2183bcef7d Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Thu, 13 Aug 2015 09:28:50 -0700 Subject: [PATCH 11/16] Bump HAP-NodeJS --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8b106e5..21429ea 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#3b1eaa8", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#3cd0026", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From e1647d22ad8fe7ffae4252fe027c6be50cb16d1f Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Thu, 13 Aug 2015 10:10:55 -0700 Subject: [PATCH 12/16] Bump HAP-NodeJS with socket fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 21429ea..0ae84c6 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#3cd0026", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#04b61c9", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 9f0aaa53d6bc7b3d3b06116a4611ee8f7870a034 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Wed, 19 Aug 2015 13:48:27 -0700 Subject: [PATCH 13/16] HAP bump for socket timeouts --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9473049..79367f3 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "carwingsjs": "0.0.x", "color": "0.10.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#04b61c9", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#ea91d4b", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 867aec36d87c4161bf15ed7a1a1e20eb7ff76c3a Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Wed, 19 Aug 2015 14:08:53 -0700 Subject: [PATCH 14/16] One more bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 79367f3..1fa4052 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "carwingsjs": "0.0.x", "color": "0.10.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#ea91d4b", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#5ec4bea", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 84c08d360cc64985d7baa03cbefa6a670a18ed48 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Wed, 19 Aug 2015 16:23:09 -0700 Subject: [PATCH 15/16] Bump HAP with new types --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1fa4052..29eba99 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "carwingsjs": "0.0.x", "color": "0.10.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#5ec4bea", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#d337abf", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From bf3d7460898448633a8f72d54ed974118c8bb4a5 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Wed, 19 Aug 2015 21:45:16 -0700 Subject: [PATCH 16/16] Use now-official refactored HAP-NodeJS --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 29eba99..8db6503 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "carwingsjs": "0.0.x", "color": "0.10.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#d337abf", + "hap-nodejs": "git+https://github.com/KhaosT/HAP-NodeJS#b237a56de3299fba82b1c5d988a1ac665bc44a6a", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4",