From c479b8b39967ae6e3f6749d320b0a34fde94bde6 Mon Sep 17 00:00:00 2001 From: Peter Murray Date: Wed, 4 Feb 2015 22:54:50 +0000 Subject: [PATCH] - Fixes #44, error in processing state value if the id is in error --- hue-api/index.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/hue-api/index.js b/hue-api/index.js index df0ab89..fe2c646 100644 --- a/hue-api/index.js +++ b/hue-api/index.js @@ -991,23 +991,24 @@ HueApi.prototype._getLightStateOptions = function (lightId, stateValues) { } else { state = lightState.create(stateValues); } - } - if (state.hasRGB()) { - promise = self.lightStatus(lightId) - .then(function (lightDetails) { - state = state.applyRGB(lightDetails.modelid); - options.values = state.payload(); + if (state.hasRGB()) { + promise = self.lightStatus(lightId) + .then(function (lightDetails) { + state = state.applyRGB(lightDetails.modelid); + options.values = state.payload(); - return options; - }); - } else { - options.values = state.payload(); + return options; + }); + } else { + options.values = state.payload(); + + deferred = Q.defer(); + deferred.resolve(options); - deferred = Q.defer(); - deferred.resolve(options); + promise = deferred.promise; + } - promise = deferred.promise; } return promise;