From 6e61287f59c414300583a5d6c800f433f8d36d67 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Mon, 3 Aug 2015 08:33:41 -0700 Subject: [PATCH] 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