Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do the light indexes match? #7

Closed
chmac opened this issue Nov 5, 2019 · 2 comments · Fixed by #8
Closed

Do the light indexes match? #7

chmac opened this issue Nov 5, 2019 · 2 comments · Fixed by #8

Comments

@chmac
Copy link
Collaborator

chmac commented Nov 5, 2019

Here's the getLamps() code:

public async getLamps(): Promise<Lamp[]> {
const url = this.buildLampCompositeURL();
const { data } = await this.get(url);
return Object.keys(data).map(k => data[k]);
}

In the last line, the returned data is converted from an object into an array. The object I see in my tests looks like:

{
"1": Lamp,
"2": Lamp,
"3": Lamp
}

But the resulting array is zero indexed and so to be able to call setColor I need a 1 based index. So I end up adding 1 to the index. I'm wondering if this is deliberate. I assume that the Hue API will never skip number, nor return indexes out of sequence, but I can't see any way to actually get the index out of the getLamps() response. Would you be open to a PR which added a field called index to the Lamp type?

@chmac
Copy link
Collaborator Author

chmac commented Nov 5, 2019

PS> I forgot to say, most importantly, thanks for this package. Makes working with the Hue bridge from typescript a breeze!

@bjohnso5
Copy link
Owner

bjohnso5 commented Nov 6, 2019

Hey Callum, sorry for the late response.

The numeric key returned in the response is referred to as an index in my codebase, but it's more like an ID in the official Hue API docs. You need to keep track of the numbers returned by the bridge, as that's how the bridge actually addresses the lamps. I'd be OK with adding it to the Lamp object definition if it would help you out (I have to admit that my bulbs are tucked away in a closet and aren't currently in use).

I'll take a look at your PR when you've got it all set for review.

Also, thanks for the kind words, I'm glad you've had success using the library!

chmac added a commit to chmac/hue-hacking-npm that referenced this issue Nov 6, 2019
bjohnso5 pushed a commit that referenced this issue Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants