public static PercentType valueOf(String value) { return new PercentType(value); }
public PercentType getBrightness() { return new PercentType(value); }
public PercentType getSaturation() { return new PercentType(saturation); }
return new HSBType(new DecimalType((int) tmpHue), new PercentType((int) tmpSaturation), new PercentType((int) tmpBrightness));
@Override public <T extends State> @Nullable T as(@Nullable Class<T> target) { if (target == OnOffType.class) { return target.cast(equals(ZERO) ? OnOffType.OFF : OnOffType.ON); } else if (target == PercentType.class) { return target.cast(new PercentType(toBigDecimal().multiply(BigDecimal.valueOf(100)))); } else if (target == UpDownType.class) { if (equals(ZERO)) { return target.cast(UpDownType.UP); } else if (toBigDecimal().compareTo(BigDecimal.valueOf(1)) == 0) { return target.cast(UpDownType.DOWN); } else { return null; } } else if (target == OpenClosedType.class) { if (equals(ZERO)) { return target.cast(OpenClosedType.CLOSED); } else if (toBigDecimal().compareTo(BigDecimal.valueOf(1)) == 0) { return target.cast(OpenClosedType.OPEN); } else { return null; } } else if (target == HSBType.class) { return target.cast(new HSBType(DecimalType.ZERO, PercentType.ZERO, new PercentType(this.toBigDecimal().multiply(BigDecimal.valueOf(100))))); } else { return defaultConversion(target); } }
BigDecimal f = h.multiply(BigDecimal.valueOf(5)).divide(BigDecimal.valueOf(3), 10, BigDecimal.ROUND_HALF_UP) .remainder(BigDecimal.ONE); PercentType a = new PercentType(value.multiply(BigDecimal.ONE.subtract(s))); PercentType b = new PercentType(value.multiply(BigDecimal.ONE.subtract(s.multiply(f)))); PercentType c = new PercentType( value.multiply(BigDecimal.ONE.subtract((BigDecimal.ONE.subtract(f)).multiply(s))));
@Override public <T extends State> @Nullable T as(@Nullable Class<T> target) { if (target == OnOffType.class) { // if brightness is not completely off, we consider the state to be on return target.cast(getBrightness().equals(PercentType.ZERO) ? OnOffType.OFF : OnOffType.ON); } else if (target == DecimalType.class) { return target.cast(new DecimalType( getBrightness().toBigDecimal().divide(BigDecimal.valueOf(100), 8, RoundingMode.UP))); } else if (target == PercentType.class) { return target.cast(new PercentType(getBrightness().toBigDecimal())); } else { return defaultConversion(target); } } }
new PercentType(this.toBigDecimal().multiply(HUNDRED)))); } else if (target == PercentType.class) { if (SmartHomeUnits.PERCENT.equals(getUnit())) { return target.cast(new PercentType(toBigDecimal())); return target.cast(new PercentType(toBigDecimal().multiply(HUNDRED))); } else if (target == DecimalType.class) { return target.cast(new DecimalType(toBigDecimal()));
/** * Returns the xyY values representing this object's color in CIE XY color model. * Conversion from sRGB to CIE XY using D65 reference white * xy pair contains color information * Y represents relative luminance * * @param HSBType color object * @return PercentType[x, y, Y] values in the CIE XY color model */ public PercentType[] toXY() { // This makes sure we keep color information even if brightness is zero PercentType sRGB[] = new HSBType(getHue(), getSaturation(), PercentType.HUNDRED).toRGB(); float r = gammaDecompress(sRGB[0].floatValue() / 100.0f); float g = gammaDecompress(sRGB[1].floatValue() / 100.0f); float b = gammaDecompress(sRGB[2].floatValue() / 100.0f); float X = r * Rgb2Xy[0][0] + g * Rgb2Xy[0][1] + b * Rgb2Xy[0][2]; float Y = r * Rgb2Xy[1][0] + g * Rgb2Xy[1][1] + b * Rgb2Xy[1][2]; float Z = r * Rgb2Xy[2][0] + g * Rgb2Xy[2][1] + b * Rgb2Xy[2][2]; float x = X / (X + Y + Z); float y = Y / (X + Y + Z); return new PercentType[] { new PercentType(Float.valueOf(x * 100.0f).toString()), new PercentType(Float.valueOf(y * 100.0f).toString()), new PercentType(Float.valueOf(Y * getBrightness().floatValue()).toString()) }; }
} else if (state instanceof DecimalType && !(state instanceof HSBType)) { applyState(new HSBType(hue, saturation, new PercentType(((DecimalType) state).toBigDecimal().multiply(BigDecimal.valueOf(100))))); } else { applyState(state);
/** * Converts a ZigBee 8 bit level as used in Level Control cluster and others to a percentage * * @param level an integer between 0 and 254 * @return the scaled {@link PercentType} */ protected PercentType levelToPercent(int level) { return new PercentType((int) (level * 100.0 / 254.0 + 0.5)); }
/** * Convert color temperature given in Kelvin to percentage. */ private PercentType kelvinToPercent(int temperatureInKelvin) { double value = 100.0 - (temperatureInKelvin - kelvinMin) * 100.0 / kelvinRange; return new PercentType((int) (value + 0.5)); }
public PercentType getSaturation() { return new PercentType(saturation); }
public PercentType getBrightness() { return new PercentType(value); }
public static PercentType valueOf(String value) { return new PercentType(value); }
private void updateColorXY() { PercentType x = new PercentType(Float.valueOf(lastX * 100.0f).toString()); PercentType y = new PercentType(Float.valueOf(lastY * 100.0f).toString()); updateColorXY(x, y); xChanged = false; yChanged = false; }
private void updateColorHSB() { DecimalType hue = new DecimalType(Float.valueOf(lastHue).toString()); PercentType saturation = new PercentType(Float.valueOf(lastSaturation).toString()); updateColorHSB(hue, saturation); hueChanged = false; saturationChanged = false; }
@ActionDoc(text = "sets the master volume") public static void setMasterVolume( @ParamDoc(name = "volume", text = "volume in the range [0,1]") final float volume) throws IOException { if (volume < 0 || volume > 1) { throw new IllegalArgumentException("Volume value must be in the range [0,1]!"); } setMasterVolume(new PercentType(new BigDecimal(volume * 100f))); }
@Override public <T extends State> @Nullable T as(@Nullable Class<T> target) { if (target == OnOffType.class) { // if brightness is not completely off, we consider the state to be on return target.cast(getBrightness().equals(PercentType.ZERO) ? OnOffType.OFF : OnOffType.ON); } else if (target == DecimalType.class) { return target.cast(new DecimalType( getBrightness().toBigDecimal().divide(BigDecimal.valueOf(100), 8, RoundingMode.UP))); } else if (target == PercentType.class) { return target.cast(new PercentType(getBrightness().toBigDecimal())); } else { return defaultConversion(target); } } }
/** * Returns the xyY values representing this object's color in CIE XY color model. * Conversion from sRGB to CIE XY using D65 reference white * xy pair contains color information * Y represents relative luminance * * @param HSBType color object * @return PercentType[x, y, Y] values in the CIE XY color model */ public PercentType[] toXY() { // This makes sure we keep color information even if brightness is zero PercentType sRGB[] = new HSBType(getHue(), getSaturation(), PercentType.HUNDRED).toRGB(); float r = gammaDecompress(sRGB[0].floatValue() / 100.0f); float g = gammaDecompress(sRGB[1].floatValue() / 100.0f); float b = gammaDecompress(sRGB[2].floatValue() / 100.0f); float X = r * Rgb2Xy[0][0] + g * Rgb2Xy[0][1] + b * Rgb2Xy[0][2]; float Y = r * Rgb2Xy[1][0] + g * Rgb2Xy[1][1] + b * Rgb2Xy[1][2]; float Z = r * Rgb2Xy[2][0] + g * Rgb2Xy[2][1] + b * Rgb2Xy[2][2]; float x = X / (X + Y + Z); float y = Y / (X + Y + Z); return new PercentType[] { new PercentType(Float.valueOf(x * 100.0f).toString()), new PercentType(Float.valueOf(y * 100.0f).toString()), new PercentType(Float.valueOf(Y * getBrightness().floatValue()).toString()) }; }