tzmanics / U-Go-Hue-Go-Tutorial

Code for a tutorial on creating an app that let's you control your Philips Hue system wherever you go (Kendo UI, Angular, Philips Hue API) 🌈
0 stars 1 forks source link

The lightNumber used can be wrong #1

Open apapanto opened 6 years ago

apapanto commented 6 years ago

The Philips Hue API returns the list of lights as a JSON object and not a JSON list, putting each light's number as the property name for that light object: { "1": { ... }, "2": { ...}, ... }

(this seems like a bad practice to me but that's how it is defined).

The current code assumes that the 'list' of lights returned by the API is like the above, converts it to an array and then uses the index (0, 1, ...) plus one to send as lightNumber.

But if we start with a setup of three lights ( 1: Lamp1, 2: Lamp2, 3: Lamp3 ), remove the first light and add/discover it again, we will get back something like: { "2": { ... }, "3": { ...}, "4": {...} } with our Lamp1 having lightNumber 4 now.

Obviously using just the indices of the array produced by the object returned by the API will yield wrong lightNumbers.

tzmanics commented 6 years ago

I see! Thanks for pointing that out. Thanks too for the PR, I want to try and get the docs matched up.