From ecda18029f6d9d106a38f9f3ed673271c4f6e42b Mon Sep 17 00:00:00 2001 From: Max Metral Date: Mon, 21 Nov 2016 14:58:39 -0500 Subject: [PATCH 1/3] Allow externally specified config --- lib/server.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/server.js b/lib/server.js index ca0659b..bd2ed8e 100644 --- a/lib/server.js +++ b/lib/server.js @@ -23,7 +23,9 @@ module.exports = { Server: Server } -function Server(insecureAccess) { +function Server(insecureAccess, opts) { + opts = opts || {}; + // Setup Accessory Cache Storage accessoryStorage.initSync({ dir: User.cachedAccessoryPath() }); @@ -46,7 +48,7 @@ function Server(insecureAccess) { }.bind(this)); this._plugins = this._loadPlugins(); // plugins[name] = Plugin instance - this._config = this._loadConfig(); + this._config = opts.config || this._loadConfig(); this._cachedPlatformAccessories = this._loadCachedPlatformAccessories(); this._bridge = this._createBridge(); @@ -55,7 +57,7 @@ function Server(insecureAccess) { this._publishedCameras = {}; this._setupManager = new BridgeSetupManager(); this._setupManager.on('newConfig', this._handleNewConfig.bind(this)); - + this._setupManager.on('requestCurrentConfig', function(callback) { callback(this._config); }.bind(this)); @@ -93,7 +95,7 @@ Server.prototype.run = function() { Server.prototype._publish = function() { // pull out our custom Bridge settings from config.json, if any var bridgeConfig = this._config.bridge || {}; - + var info = this._bridge.getService(Service.AccessoryInformation); if (bridgeConfig.manufacturer) info.setCharacteristic(Characteristic.Manufacturer, bridgeConfig.manufacturer); @@ -168,7 +170,7 @@ Server.prototype._loadConfig = function() { // Complain and exit if it doesn't exist yet if (!fs.existsSync(configPath)) { log.warn("config.json (%s) not found.", configPath); - + var config = {}; config.bridge = { @@ -427,7 +429,7 @@ Server.prototype._handleRegisterPlatformAccessories = function(accessories) { accessory._prepareAssociatedHAPAccessory(); hapAccessories.push(accessory._associatedHAPAccessory); - + this._cachedPlatformAccessories.push(accessory); } @@ -513,7 +515,7 @@ Server.prototype._handleNewConfig = function(type, name, replace, config) { } else { var targetName; if (name.indexOf('.') !== -1) { - targetName = name.split(".")[1]; + targetName = name.split(".")[1]; } var found = false; for (var index in this._config.accessories) { @@ -545,7 +547,7 @@ Server.prototype._handleNewConfig = function(type, name, replace, config) { } else { var targetName; if (name.indexOf('.') !== -1) { - targetName = name.split(".")[1]; + targetName = name.split(".")[1]; } var found = false; From e1867b2bc0fb68fe09adcece40cfc239245f2f94 Mon Sep 17 00:00:00 2001 From: Khaos Tian Date: Sun, 27 Nov 2016 15:24:27 -0800 Subject: [PATCH 2/3] Improve error handling. --- lib/plugin.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/plugin.js b/lib/plugin.js index e7e9c1f..3b3d1e5 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -165,9 +165,13 @@ Plugin.installed = function() { // reconstruct full path var pluginPath = path.join(requirePath, name); - - // we only care about directories - if (!fs.statSync(pluginPath).isDirectory()) continue; + + try { + // we only care about directories + if (!fs.statSync(pluginPath).isDirectory()) continue; + } catch (e) { + continue; + } // does this module contain a package.json? var pjson; From 48840870416444fa71b3a4156f5bbac2779013cd Mon Sep 17 00:00:00 2001 From: Khaos Tian Date: Sun, 27 Nov 2016 15:24:43 -0800 Subject: [PATCH 3/3] 0.4.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 40caa5f..a499444 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebridge", "description": "HomeKit support for the impatient", - "version": "0.4.9", + "version": "0.4.10", "scripts": { "dev": "DEBUG=* ./bin/homebridge -D -P example-plugins/ || true" },