Q42.HueApi icon indicating copy to clipboard operation
Q42.HueApi copied to clipboard

SetColor() in v2 does not work

Open getsolved opened this issue 3 years ago • 4 comments

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?

getsolved avatar Apr 03 '22 10:04 getsolved

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"));

michielpost avatar Apr 04 '22 09:04 michielpost

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.

getsolved avatar Apr 04 '22 09:04 getsolved

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.

michielpost avatar Apr 04 '22 09:04 michielpost

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.

getsolved avatar Apr 04 '22 15:04 getsolved