Can I get a bit of help on my code?

One line of code is giving me trouble. I've a driver that was written some years ago, that causes a bug in HE to show - groups do not handle values for HSL that have decimal places and needs integers. The original developer has been very sick and I don't want to bother him, so I've taken it upon myself to make a personal, customized version of his driver (which works very well I might add!)

The original line:
sendEvent(name: "hue", value: settings.enableHueInDegrees ? parameters.hue/3.6 : parameters.hue)

My code:
sendEvent(name: "hue", value: settings.enableHueInDegrees ? (parameters.hue/3.6).intValue() : parameters.hue.intValue())

I don't understand what the Question mark does or the Colon so I'm just stuffing .intValue() on all the sendEvents which is working but I hiccup in this one spot. Thanks.

Here's a helpful reference: The Apache Groovy programming language - Operators

The x ? y : z thing is an example of the "tenary operator," which I'm sure you'd find in the link above. Just a shorter way of something like:

if (x)
  y
else
  z

For your actual problem, it's not clear to me why what you have would fail, at least from a techincal persepective. What, exactly, "hiccups," and are there any errors (in logs)? However, from a practical perspective, I'd probably use Math.round(x) instead of x.intValue() so that you get the nearest integer rather than just truncating everything fractional.

1 Like

thanks. I had guessed it was a shorthanded if/then!

Okay - @bertacbd1234 - very good point. I'll go change the hue.intValue() to a Math.round(hue)...

I wasn't actually getting an error, it just wasn't changing the color of the light strip.

2 Likes

Color me pink!

the customizations to the Magichome Wifi strip driver work perfectly! Even getting white to work!

4 Likes