mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-27 14:16:25 +01:00
Merge pull request #45 from alistairg/master
Changed approach to getting accessories
This commit is contained in:
+12
-9
@@ -102,25 +102,28 @@ var locateBridge = function (callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PhilipsHuePlatform.prototype = {
|
PhilipsHuePlatform.prototype = {
|
||||||
|
|
||||||
accessories: function(callback) {
|
accessories: function(callback) {
|
||||||
this.log("Fetching Philips Hue lights...");
|
this.log("Fetching Philips Hue lights...");
|
||||||
var that = this;
|
var that = this;
|
||||||
var getLights = function () {
|
var getLights = function () {
|
||||||
var api = new HueApi(that.ip_address, that.username);
|
var api = new HueApi(that.ip_address, that.username);
|
||||||
// Connect to the API and loop through lights
|
|
||||||
api.lights(function(err, response) {
|
// Connect to the API
|
||||||
|
// Get a dump of all lights, so as not to hit rate limiting for installations with larger amounts of bulbs
|
||||||
|
|
||||||
|
api.fullState(function(err, response) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
response.lights.map(function(light) {
|
|
||||||
var foundAccessories = [];
|
var foundAccessories = [];
|
||||||
// Get the state of each individual light and add to platform
|
for (var deviceId in response.lights) {
|
||||||
api.lightStatus(light.id, function(err, device) {
|
var device = response.lights[deviceId];
|
||||||
if (err) throw err;
|
device.id = deviceId;
|
||||||
device.id = light.id;
|
|
||||||
var accessory = new PhilipsHueAccessory(that.log, device, api);
|
var accessory = new PhilipsHueAccessory(that.log, device, api);
|
||||||
foundAccessories.push(accessory);
|
foundAccessories.push(accessory);
|
||||||
|
}
|
||||||
callback(foundAccessories);
|
callback(foundAccessories);
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user