mirror of
https://github.com/mtan93/homebridge.git
synced 2026-05-10 14:26:05 +01:00
@@ -20,9 +20,45 @@ storage.initSync();
|
||||
// Load up the configuration file
|
||||
var config = JSON.parse(fs.readFileSync(configPath));
|
||||
|
||||
// Just to prevent them getting garbage collected
|
||||
var accessories = [];
|
||||
|
||||
function startup() {
|
||||
if (config.platforms) loadPlatforms();
|
||||
if (config.accessories) loadAccessories();
|
||||
}
|
||||
|
||||
function loadAccessories() {
|
||||
|
||||
var accessories = [];
|
||||
// Instantiate all accessories in the config
|
||||
console.log("Loading " + config.accessories.length + " accessories...");
|
||||
for (var i=0; i<config.accessories.length; i++) {
|
||||
|
||||
var accessoryConfig = config.accessories[i];
|
||||
|
||||
// Load up the class for this accessory
|
||||
var accessoryName = accessoryConfig["accessory"]; // like "WeMo"
|
||||
var accessoryModule = require('./accessories/' + accessoryName + ".js"); // like "./accessories/WeMo.js"
|
||||
var accessoryConstructor = accessoryModule.accessory; // like "WeMoAccessory", a JavaScript constructor
|
||||
|
||||
// Create a custom logging function that prepends the device display name for debugging
|
||||
var name = accessoryConfig["name"];
|
||||
var log = function(name) { return function(s) { console.log("[" + name + "] " + s); }; }(name);
|
||||
|
||||
log("Initializing " + accessoryName + " accessory...");
|
||||
var accessory = new accessoryConstructor(log, accessoryConfig);
|
||||
accessories.push(accessory);
|
||||
|
||||
// Extract the raw "services" for this accessory which is a big array of objects describing the various
|
||||
// hooks in and out of HomeKit for the HAP-NodeJS server.
|
||||
var services = accessory.getServices();
|
||||
|
||||
// Create the HAP server for this accessory
|
||||
createHAPServer(name, services);
|
||||
}
|
||||
}
|
||||
|
||||
function loadPlatforms() {
|
||||
|
||||
console.log("Loading " + config.platforms.length + " platforms...");
|
||||
for (var i=0; i<config.platforms.length; i++) {
|
||||
@@ -58,33 +94,6 @@ function loadAccessories() {
|
||||
accessories.push.apply(accessories, foundAccessories);
|
||||
})
|
||||
}
|
||||
|
||||
// Instantiate all accessories in the config
|
||||
console.log("Loading " + config.accessories.length + " accessories...");
|
||||
for (var i=0; i<config.accessories.length; i++) {
|
||||
|
||||
var accessoryConfig = config.accessories[i];
|
||||
|
||||
// Load up the class for this accessory
|
||||
var accessoryName = accessoryConfig["accessory"]; // like "WeMo"
|
||||
var accessoryModule = require('./accessories/' + accessoryName + ".js"); // like "./accessories/WeMo.js"
|
||||
var accessoryConstructor = accessoryModule.accessory; // like "WeMoAccessory", a JavaScript constructor
|
||||
|
||||
// Create a custom logging function that prepends the device display name for debugging
|
||||
var name = accessoryConfig["name"];
|
||||
var log = function(name) { return function(s) { console.log("[" + name + "] " + s); }; }(name);
|
||||
|
||||
log("Initializing " + accessoryName + " accessory...");
|
||||
var accessory = new accessoryConstructor(log, accessoryConfig);
|
||||
accessories.push(accessory);
|
||||
|
||||
// Extract the raw "services" for this accessory which is a big array of objects describing the various
|
||||
// hooks in and out of HomeKit for the HAP-NodeJS server.
|
||||
var services = accessory.getServices();
|
||||
|
||||
// Create the HAP server for this accessory
|
||||
createHAPServer(name, services);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -175,4 +184,4 @@ function createUsername(str) {
|
||||
hash[10] + hash[11];
|
||||
}
|
||||
|
||||
loadAccessories();
|
||||
startup();
|
||||
|
||||
Reference in New Issue
Block a user