[SOLVED] New HSBType struggle

On snapshot #1655 (same day as M2 came through)
Trying to increase the brightness of a color item:

Color CanvasKitchenColor { channel = "nanoleaf:controller:9F276836E179:color" }

This works fine: (keeping the current state values)

     case 38949: {
          var HSBType currentState
          currentState = CanvasKitchenColor.state as HSBType
          var DecimalType new_H = currentState.hue
          var PercentType new_S = currentState.saturation
          var PercentType new_B = currentState.brightness
          logInfo("File", "color test: hue = {} sat = {} bright = {}", new_H, new_S, new_B)
          var HSBType newState = new HSBType(new_H, new_S, new_B)
          logInfo("File", "color test: hue = {} sat = {} bright = {}", new_H, new_S, new_B)
          CanvasKitchenColor.sendCommand(newState)
          logInfo("CanvasTouch", "CanvasKitchenColor=" + CanvasKitchenColor.state)
      }

log:

2019-08-12 22:35:35.715 [INFO ] [e.smarthome.model.script.CanvasTouch] - CanvasTouchGesture State=0
2019-08-12 22:35:35.715 [INFO ] [e.smarthome.model.script.CanvasTouch] - CanvasTouchId State=38949
2019-08-12 22:35:35.716 [INFO ] [e.smarthome.model.script.CanvasTouch] - PanelId=38949 gesture=0
2019-08-12 22:35:35.717 [INFO ] [.eclipse.smarthome.model.script.File] - color test: hue = 0 sat = 0 bright = 25
2019-08-12 22:35:35.718 [INFO ] [.eclipse.smarthome.model.script.File] - color test: hue = 0 sat = 0 bright = 25
2019-08-12 22:35:35.719 [INFO ] [e.smarthome.model.script.CanvasTouch] - CanvasKitchenColor=0,0,25

This crashes: (trying to increase the brightness)

      case 38949: {
          var HSBType currentState
          currentState = CanvasKitchenColor.state as HSBType
          var DecimalType new_H = currentState.hue
          var PercentType new_S = currentState.saturation
          var PercentType new_B = currentState.brightness + 10
          logInfo("File", "color test: hue = {} sat = {} bright = {}", new_H, new_S, new_B)
          var HSBType newState = new HSBType(new_H, new_S, new_B)
          logInfo("File", "color test: hue = {} sat = {} bright = {}", new_H, new_S, new_B)
          CanvasKitchenColor.sendCommand(newState)
          logInfo("CanvasTouch", "CanvasKitchenColor=" + CanvasKitchenColor.state)
      }

log:

2019-08-12 22:46:50.753 [INFO ] [e.smarthome.model.script.CanvasTouch] - CanvasTouchGesture State=0
2019-08-12 22:46:50.753 [INFO ] [e.smarthome.model.script.CanvasTouch] - CanvasTouchId State=38949
2019-08-12 22:46:50.754 [INFO ] [e.smarthome.model.script.CanvasTouch] - PanelId=38949 gesture=0
2019-08-12 22:46:50.755 [INFO ] [.eclipse.smarthome.model.script.File] - color test: hue = 0 sat = 0 bright = 35
2019-08-12 22:46:50.755 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Nanoleaf touch': An error occurred 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)

Only difference is the ‘+ 10’. Tried + new PersentType(10), same error.

I’m stumped …

You could try

(currentState.brightness as DecimalType) + 10

Thanks, but same error:

2019-08-12 23:16:25.090 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Nanoleaf touch': An error occurred 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)

Try

var PercentType new B = new PercentType(currentState.brightness as Number + 10)

If that doesn’t work try:

var HSBType newState = new HSBType(new_H.toString+","+new_S.toString+","+new_B.toString)

If you use the String approach, then there is no need to create a new HSBType, just pass the String to sendCommand.

Nice!
This one worked:

var PercentType new_B = new PercentType(currentState.brightness as Number + 10)

Thanks.
Really picky syntax for this kind of arithmetic :wink:

It’s not picky so much as the way you are doing it you need to be very specific about type. You are telling it that new_B is a PercentType so you need to make sure the result of the calculation is a PercentType. That doesn’t happen automatically. By default the result of a calculation is of type BigDecimal which is a Number.