peter-murray / node-hue-api

Node.js Library for interacting with the Philips Hue Bridge and Lights
Apache License 2.0
1.19k stars 145 forks source link

Not working as expected when using one state for multiple lamps #18

Closed kvendrik closed 9 years ago

kvendrik commented 9 years ago

Hi Peter,

First of all, awesome API! Great job! :+1:

Alright, so I recently started making a Hue CLI using your API and got some unexpected behaviour when using one state object for multiple lamps. I fixed this by creating a new state for each lamp. Have a look at the commit message below, any idea why this is happening?

Fixes unexpected behaviour issue when changing multiple lamps

We were using one state object to change multiple lamps. This turned out to give unexpected behaviour.
When for example doing something like './hue all --rgba=255,0.0' one lamp would turn red and the other
one would turn blue. They did however get the same state object with the same color x,y values.

This version creates a new state object for each lamp which seems to work as you'd expect.
peter-murray commented 9 years ago

Thanks for your kind words.

The LightState object is meant to be a throw away object, used to compose a single state (i.e. on with a particular color) and then used with a light state call to the API. If you do try to reuse the existing state object (and modify some values), then it is likely that you could get some odd behaviour.

The reason that I did it this way was to support developers that want to just pass the pure JSON state object that is documented in the official Phillips Hue API, instead of having to use the LightState object which is really just a fluent interface wrapper.

I will take a look at writing a test or two to see if I can reproduce the issue with reusing the state object across multiple lamps and come back to you on this.

peter-murray commented 9 years ago

This was a bug I introduced in the 0.2.5 release...

It is now fixed in 0.2.6, and I have tested it with your cli project and it works as expected.