Allow bridge to be configured in config.json

Fixes #104
This commit is contained in:
Nick Farina
2015-08-19 21:51:25 -07:00
parent 8a58328ad7
commit 9c63ce5017
2 changed files with 16 additions and 6 deletions

15
app.js
View File

@@ -21,12 +21,15 @@ if (!fs.existsSync(configPath)) {
// Initialize HAP-NodeJS
hap.init();
// 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));
// pull out our custom Bridge settings from config.json, if any
var bridgeConfig = config.bridge || {};
// Start by creating our Bridge which will host all loaded Accessories
var bridge = new Bridge(bridgeConfig.name || 'Homebridge', uuid.generate("HomeBridge"));
// 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;
@@ -139,9 +142,9 @@ function loadPlatforms() {
function publish() {
bridge.publish({
username: "CC:22:3D:E3:CE:27",
port: 51826,
pincode: "031-45-154",
username: bridgeConfig.username || "CC:22:3D:E3:CE:27",
port: bridgeConfig.port || 51826,
pincode: bridgeConfig.pin || "031-45-154",
category: Accessory.Categories.OTHER
});
}

View File

@@ -1,4 +1,11 @@
{
"bridge": {
"name": "Homebridge",
"username": "CC:22:3D:E3:CE:27",
"port": 51826,
"pin": "031-45-154"
},
"description": "This is an example configuration file with all supported devices. You can use this as a template for creating your own configuration file containing devices you actually own.",
"platforms": [