Fix name/log var corruption

This commit is contained in:
Nick Farina
2015-08-04 16:21:06 -07:00
parent c756ea9456
commit f7f953b8d1
+32 -27
View File
@@ -100,34 +100,39 @@ function loadPlatforms() {
var platformInstance = new platformConstructor(log, platformConfig); var platformInstance = new platformConstructor(log, platformConfig);
// query for devices // wrap name and log in a closure so they don't change in the callback
asyncCalls++; function getAccessories(name, log) {
platformInstance.accessories(function(foundAccessories){ asyncCalls++;
asyncCalls--; platformInstance.accessories(function(foundAccessories){
// loop through accessories adding them to the list and registering them asyncCalls--;
for (var i = 0; i < foundAccessories.length; i++) { // loop through accessories adding them to the list and registering them
var accessoryInstance = foundAccessories[i]; for (var i = 0; i < foundAccessories.length; i++) {
var accessoryInstance = foundAccessories[i];
log("Initializing device with name " + accessoryInstance.name + "...")
log("Initializing device with name " + accessoryInstance.name + "...")
// 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. // Extract the raw "services" for this accessory which is a big array of objects describing the various
var services = accessoryInstance.getServices(); // hooks in and out of HomeKit for the HAP-NodeJS server.
var services = accessoryInstance.getServices();
// Create the actual HAP-NodeJS "Accessory" instance
var accessory = accessoryLoader.parseAccessoryJSON({ // Create the actual HAP-NodeJS "Accessory" instance
displayName: name, var accessory = accessoryLoader.parseAccessoryJSON({
services: services displayName: name,
}); services: services
});
// add it to the bridge // add it to the bridge
bridge.addBridgedAccessory(accessory); bridge.addBridgedAccessory(accessory);
} }
// were we the last callback? // were we the last callback?
if (asyncCalls === 0 && !asyncWait) if (asyncCalls === 0 && !asyncWait)
publish(); publish();
}) })
}
// query for devices
getAccessories(name, log);
} }
} }