/** * Transforms the given {@link PercentType} into a light state containing the brightness and the * 'on' value represented by {@link PercentType}. * * @param percentType brightness represented as {@link PercentType} * @return light state containing the brightness and the 'on' value */ public static StateUpdate toBrightnessLightState(PercentType percentType) { boolean on = percentType.equals(PercentType.ZERO) ? false : true; final StateUpdate stateUpdate = new StateUpdate().setOn(on); int brightness = (int) Math.round(percentType.floatValue() * BRIGHTNESS_FACTOR); if (brightness > 0) { stateUpdate.setBrightness(brightness); } return stateUpdate; }
/** * Transforms the given {@link PercentType} into a light state containing the color temperature * represented by {@link PercentType}. * * @param percentType color temperature represented as {@link PercentType} * @return light state containing the color temperature */ public static StateUpdate toColorTemperatureLightState(PercentType percentType) { int colorTemperature = MIN_COLOR_TEMPERATURE + Math.round((COLOR_TEMPERATURE_RANGE * percentType.floatValue()) / 100); StateUpdate stateUpdate = new StateUpdate().setColorTemperature(colorTemperature); return stateUpdate; }