michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
411 stars 114 forks source link

SetColor() in v2 does not work #276

Closed getsolved closed 1 year ago

getsolved commented 2 years ago

Hi. Embedded in a VB.NET Project I am trying to use the v2 API (HueApi and HueApi.ColorConverters 0.5.42). The given code snippet is not working:

Dim request As UpdateLight = New UpdateLight().SetColor(New HueApi.ColorConverters.RGBColor("FF0000"))

gives an error "value of type RGBColor cannot be converted to Integer".

So at this moment I cannot use SetColor() to pass RGB values, only X/Y values or CT value. How can I get X/Y coordinates of a color from RGB or HSB values?

michielpost commented 2 years ago

Does the error happen on that line? Or when submitting the request?

When I run this in C#, it works fine and I get an UpdateLight object with a Color X/Y filled in:

var request = new UpdateLight().SetColor(new HueApi.ColorConverters.RGBColor("FF0000"));
getsolved commented 2 years ago

The debugger shows the error at design time in the editor on that line.

Hours later I found a workaround using UpdateLightExtensions:

Dim request As New UpdateLight() Dim RGBColor As New HueApi.ColorConverters.RGBColor("FF0000") HueApi.ColorConverters.Original.Extensions.UpdateLightExtensions.SetColor(Of UpdateLight)(request, RGBColor)

If you send that request to the bridge, the color is passed correctly.

But it would be easier if the object RGBColor has just X and Y coordinates as properties.

michielpost commented 2 years ago

Not sure what going on here. The code you post that is working is the same, but then as three seperate calls on three lines. It calls the same SetColor extension method.

If you know the XY you want to set, you can also call: request.Color = new Color() { Xy = new XyPosition() { X = 0, Y = 0 } };

There are different methods for converting between HEX / RGB and XY per Lamp model etc. So that's why there are different converters available.

getsolved commented 2 years ago

Maybe it is caused by different behaviours between VB.NET and C# for the extension methods? I have a working solution, my problem is currently solved, especially because you confirmed that I used the same methods as the RGBColor class. But maybe it is worth another look.