コード例 #1
0
  /**
   * 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;
  }
コード例 #2
0
  /**
   * Transforms the given {@link HSBType} into a light state.
   *
   * @param hsbType HSB type
   * @return light state representing the {@link HSBType}.
   */
  public static StateUpdate toColorLightState(HSBType hsbType) {
    int hue = (int) Math.round(hsbType.getHue().doubleValue() * HUE_FACTOR);
    int saturation = (int) Math.round(hsbType.getSaturation().doubleValue() * SATURATION_FACTOR);
    int brightness = (int) Math.round(hsbType.getBrightness().doubleValue() * BRIGHTNESS_FACTOR);

    StateUpdate stateUpdate = new StateUpdate().setHue(hue).setSat(saturation);
    if (brightness > 0) {
      stateUpdate.setBrightness(brightness);
    }
    return stateUpdate;
  }