/** * Constructs a HSBType instance with the given values * * @param h the hue value in the range from 0 <= h < 360 * @param s the saturation as a percent value * @param b the brightness as a percent value */ public HSBType(DecimalType h, PercentType s, PercentType b) { this.hue = h.toBigDecimal(); this.saturation = s.toBigDecimal(); this.value = b.toBigDecimal(); validateValue(this.hue, this.saturation, this.value); }
@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); } } }
@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 == DecimalType.class) { return target.cast(new DecimalType(toBigDecimal().divide(BigDecimal.valueOf(100), 8, RoundingMode.UP))); } else if (target == UpDownType.class) { if (equals(ZERO)) { return target.cast(UpDownType.UP); } else if (equals(HUNDRED)) { return target.cast(UpDownType.DOWN); } else { return null; } } else if (target == OpenClosedType.class) { if (equals(ZERO)) { return target.cast(OpenClosedType.CLOSED); } else if (equals(HUNDRED)) { return target.cast(OpenClosedType.OPEN); } else { return null; } } else if (target == HSBType.class) { return target.cast(new HSBType(DecimalType.ZERO, PercentType.ZERO, this)); } else if (target == QuantityType.class) { return target.cast(new QuantityType<>(toBigDecimal().doubleValue(), SmartHomeUnits.PERCENT)); } else { return defaultConversion(target); } }
/** * Constructs a HSBType instance with the given values * * @param h the hue value in the range from 0 <= h < 360 * @param s the saturation as a percent value * @param b the brightness as a percent value */ public HSBType(DecimalType h, PercentType s, PercentType b) { this.hue = h.toBigDecimal(); this.saturation = s.toBigDecimal(); this.value = b.toBigDecimal(); validateValue(this.hue, this.saturation, this.value); }
@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); } } }
@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 == DecimalType.class) { return target.cast(new DecimalType(toBigDecimal().divide(BigDecimal.valueOf(100), 8, RoundingMode.UP))); } else if (target == UpDownType.class) { if (equals(ZERO)) { return target.cast(UpDownType.UP); } else if (equals(HUNDRED)) { return target.cast(UpDownType.DOWN); } else { return null; } } else if (target == OpenClosedType.class) { if (equals(ZERO)) { return target.cast(OpenClosedType.CLOSED); } else if (equals(HUNDRED)) { return target.cast(OpenClosedType.OPEN); } else { return null; } } else if (target == HSBType.class) { return target.cast(new HSBType(DecimalType.ZERO, PercentType.ZERO, this)); } else if (target == QuantityType.class) { return target.cast(new QuantityType<>(toBigDecimal().doubleValue(), SmartHomeUnits.PERCENT)); } else { return defaultConversion(target); } }