homebridge-plugin-wrapper
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -56,4 +56,4 @@ var path = require('path'); | ||
this._config = opts.config || this._loadConfig(); | ||
this._plugins = this._loadPlugins(); // plugins[name] = Plugin instance | ||
this._config = opts.config || this._loadConfig(); | ||
this._cachedPlatformAccessories = this._loadCachedPlatformAccessories(); | ||
@@ -137,2 +137,3 @@ this._bridge = this._createBridge(); | ||
var foundOnePlugin = false; | ||
var activePlugins = this._computeActivePluginList(); | ||
@@ -142,2 +143,6 @@ // load and validate plugins - check for valid package.json, etc. | ||
if (activePlugins !== undefined && activePlugins[plugin.name()] !== true) { | ||
return; | ||
} | ||
// attempt to load it | ||
@@ -248,2 +253,17 @@ try { | ||
Server.prototype._computeActivePluginList = function() { | ||
if (this._config.plugins === undefined) { | ||
return undefined; | ||
} | ||
var activePlugins = {}; | ||
for (var i=0; i<this._config.plugins.length; i++) { | ||
var pluginName = this._config.plugins[i]; | ||
activePlugins[pluginName] = true; | ||
} | ||
return activePlugins; | ||
} | ||
Server.prototype._createBridge = function() { | ||
@@ -529,6 +549,7 @@ // pull out our custom Bridge settings from config.json, if any | ||
Server.prototype._teardown = function() { | ||
this._updateCachedAccessories(); | ||
this._bridge.unpublish(); | ||
Object.keys(this._publishedCameras).forEach(function (advertiseAddress) { | ||
this._publishedCameras[advertiseAddress]._associatedHAPAccessory.unpublish(); | ||
var self = this; | ||
self._updateCachedAccessories(); | ||
self._bridge.unpublish(); | ||
Object.keys(self._publishedCameras).forEach(function (advertiseAddress) { | ||
self._publishedCameras[advertiseAddress]._associatedHAPAccessory.unpublish(); | ||
}); | ||
@@ -535,0 +556,0 @@ } |
58
index.js
@@ -7,32 +7,12 @@ /* jshint -W097 */ | ||
var mock = require('mock-require'); | ||
mock('hap-nodejs', './hap-nodejs'); | ||
mock('hap-nodejs/accessories/types.js', './hap-nodejs/accessories/types.js'); | ||
mock('hap-nodejs/lib/util/once', './hap-nodejs/lib/util/once'); | ||
mock('qrcode-terminal', { | ||
generate: function() {} | ||
}); | ||
mock('ed25519-hap', { | ||
MakeKeypair: function(seed) { return {privateKey: '', publicKey: ''};} | ||
}); | ||
mock('ip', {}); | ||
mock('chalk', { | ||
'gray': function(msg) {return msg;}, | ||
'yellow': function(msg) {return msg;}, | ||
'cyan': function(msg) {return msg;}, | ||
'white': function(msg) {return msg;}, | ||
'bold': { | ||
'red': function(msg) {return msg;}, | ||
} | ||
}); | ||
var inherits = require('util').inherits; | ||
var EventEmitter = require('events').EventEmitter; | ||
var User = require(__dirname + '/homebridge/user').User; | ||
var hap = require('./hap-nodejs'); | ||
var Server = require(__dirname + '/homebridge/server').Server; | ||
var hapTypes = require(__dirname + '/hap-nodejs/accessories/types'); | ||
var Service = hap.Service; | ||
var Accessory = hap.Accessory; | ||
var User; | ||
var hap; | ||
var Server; | ||
var hapTypes; | ||
var Service; | ||
var Accessory; | ||
@@ -46,2 +26,28 @@ function override(child, fn) { | ||
function HomebridgeWrapper(config) { | ||
mock('hap-nodejs', './hap-nodejs'); | ||
mock('hap-nodejs/accessories/types.js', './hap-nodejs/accessories/types.js'); | ||
mock('hap-nodejs/lib/util/once', './hap-nodejs/lib/util/once'); | ||
mock('qrcode-terminal', { | ||
generate: function() {} | ||
}); | ||
mock('ed25519-hap', { | ||
MakeKeypair: function(seed) { return {privateKey: '', publicKey: ''};} | ||
}); | ||
mock('ip', {}); | ||
mock('chalk', { | ||
'gray': function(msg) {return msg;}, | ||
'yellow': function(msg) {return msg;}, | ||
'cyan': function(msg) {return msg;}, | ||
'white': function(msg) {return msg;}, | ||
'bold': { | ||
'red': function(msg) {return msg;}, | ||
} | ||
}); | ||
User = require(__dirname + '/homebridge/user').User; | ||
hap = require('./hap-nodejs'); | ||
Server = require(__dirname + '/homebridge/server').Server; | ||
hapTypes = require(__dirname + '/hap-nodejs/accessories/types'); | ||
Service = hap.Service; | ||
Accessory = hap.Accessory; | ||
this.logger = config.logger; | ||
@@ -48,0 +54,0 @@ this.wrapperConfig = config.wrapperConfig; |
{ | ||
"name": "homebridge-plugin-wrapper", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "Wrapper for Homebridge and NodeJS-HAP with reduced dependecies", | ||
@@ -5,0 +5,0 @@ "author": { |
2129142
10736