Expose User object to Plugin API

Closes #379
Changes #378
This commit is contained in:
Nick Farina
2015-11-04 15:59:38 -08:00
parent 8f1a043121
commit 7bfc5ee84d
2 changed files with 5 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
var hap = require("hap-nodejs"); var hap = require("hap-nodejs");
var hapLegacyTypes = require("hap-nodejs/accessories/types.js"); var hapLegacyTypes = require("hap-nodejs/accessories/types.js");
var log = require("./logger")._system; var log = require("./logger")._system;
var User = require("./user").User;
// The official homebridge API is the object we feed the plugin's exported initializer function. // The official homebridge API is the object we feed the plugin's exported initializer function.
@@ -12,6 +13,9 @@ function API() {
this._accessories = {}; // this._accessories[pluginName.accessoryName] = accessory constructor this._accessories = {}; // this._accessories[pluginName.accessoryName] = accessory constructor
this._platforms = {}; // this._platforms[pluginName.platformName] = platform constructor this._platforms = {}; // this._platforms[pluginName.platformName] = platform constructor
// expose the User class methods to plugins to get paths. Example: homebridge.user.storagePath()
this.user = User;
// expose HAP-NodeJS in its entirely for plugins to use instead of making Plugins // expose HAP-NodeJS in its entirely for plugins to use instead of making Plugins
// require() it as a dependency - it's a heavy dependency so we don't want it in // require() it as a dependency - it's a heavy dependency so we don't want it in
// every single plugin. // every single plugin.

View File

@@ -13,7 +13,7 @@ module.exports = function() {
program program
.version(version) .version(version)
.option('-P, --plugin-path [path]', 'look for plugins installed at [path] as well as the default locations ([path] can also point to a single plugin)', function(p) { Plugin.addPluginPath(p); }) .option('-P, --plugin-path [path]', 'look for plugins installed at [path] as well as the default locations ([path] can also point to a single plugin)', function(p) { Plugin.addPluginPath(p); })
.option('-H, --homebridge-home [path]', 'look for homebridge user files at [path] instead of the default location (~/.homebridge)', function(p) { User.setStoragePath(p); }) .option('-U, --user-storage-path [path]', 'look for homebridge user files at [path] instead of the default location (~/.homebridge)', function(p) { User.setStoragePath(p); })
.option('-D, --debug', 'turn on debug level logging', function() { require('./logger').setDebugEnabled(true) }) .option('-D, --debug', 'turn on debug level logging', function() { require('./logger').setDebugEnabled(true) })
.parse(process.argv); .parse(process.argv);