OpenHAB2 Hue changing rule

I am trying to make a rule that changes the Hue value of a HSB Type value. The rule looks like this:

val HSBType color = Light_RGB.state as HSBType
val DecimalType Hue = color.getHue()
while (Button.state == ON) {
	//Hue = Hue + 10.0;
	color = new HSBType(Hue,(color.getSaturation() as PercentType),(color.getBrightness() as PercentType));
	sendCommand(Light_RGB,color);
	Thread::sleep(250);
}

This works fine, it just doesn’t change the value. Once I uncomment the line //Hue = Hue + 10.0; I receive Rule 'Hue Switcher': An error occured during the script execution: Could not invoke constructor: org.eclipse.smarthome.core.library.types.HSBType.HSBType(org.eclipse.smarthome.core.library.types.DecimalType,org.eclipse.smarthome.core.library.types.PercentType,org.eclipse.smarthome.core.library.types.PercentType). I have removed the rule ‘xxx’ when ‘yyy’ then ‘zzz’ part as that is working perfectly, just to avoid confusion.

Why is it not possible to add a value to the Hue like i want it to? Of course I would have to check for the maximum value once I want to use this in production, but this should work just fine for now, but it doesn’t.

Maybe a detailed explanation of the HSBType could help:

I have cleaned up the rule a little bit and rebuilt what you are doing, with the addition of some debug lines:

rule "Test for Flole"
  when Item Button received command
  then
    var HSBType color = aacc_color.state as HSBType
    var DecimalType Hue = color.getHue()
    logError("Flole 1", Hue.class.toString)
    while (Button.state == ON) {
      logError("Flole 2", Hue.class.toString)
    	Hue = Hue + 10.0
      logError("Flole 3", Hue.class.toString)
    	color = new HSBType(Hue,color.getSaturation(),color.getBrightness());
    	sendCommand(aacc_color,color);
    	Thread::sleep(4000)
    }
end

This is what OpenHAB spits out in its logs:

.script.Flole 1] - class org.eclipse.smarthome.core.library.types.DecimalType
.script.Flole 2] - class org.eclipse.smarthome.core.library.types.DecimalType
.script.Flole 3] - class java.math.BigDecimal
ExecutionThread] - Rule 'Test for Flole': An error occured during the script execution: Could not invoke constructor: org.eclipse.smarthome.core.library.types.HSBType.HSBType(org.eclipse.smarthome.core.library.types.DecimalType,org.eclipse.smarthome.core.library.types.PercentType,org.eclipse.smarthome.core.library.types.PercentType)

For some super weird reason the Hue variable changes its class to java.math.BigDecimal. I honestly don’t know how this is even possible…

However, assigning a new class to the variable (of the same type) somehow works:

hue = new DecimalType(hue + 10)

Please note that I write hue and not Hue because I was too scared that there was a class or something with this name. Keeping variable names with lowercase first letters is generally a good idea.

This is my working version:

rule "Test for Flole"
  when Item Button received command
  then
    var HSBType color = aacc_color.state
    var DecimalType hue = color.getHue
    while (Button.state == ON) {
    	hue = new DecimalType(hue + 10)
    	color = new HSBType(hue,color.getSaturation,color.getBrightness)
    	aacc_color.sendCommand(color)
    	Thread::sleep(4000)
    }
end

And yes, it completely explodes when reaching 360 Hue ^^

I left out the () because this is allowed in Xtend grammar and I changed val to var because val denotes final variables that should not be changed anymore. It also throws some warnings in the openhab console on the snapshot channel.