[mqtt] support mired<->Kelvin unit conversion (#13575)
Just have to use the newer toInvertibleUnit method that allows the dimension to change. Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
parent
790e5d58c4
commit
5f6241cbc6
@ -130,7 +130,7 @@ public class NumberValue extends Value {
|
|||||||
private BigDecimal getQuantityTypeAsDecimal(QuantityType<?> qType) {
|
private BigDecimal getQuantityTypeAsDecimal(QuantityType<?> qType) {
|
||||||
BigDecimal val = qType.toBigDecimal();
|
BigDecimal val = qType.toBigDecimal();
|
||||||
if (!qType.getUnit().isCompatible(Units.ONE)) {
|
if (!qType.getUnit().isCompatible(Units.ONE)) {
|
||||||
QuantityType<?> convertedType = qType.toUnit(unit);
|
QuantityType<?> convertedType = qType.toInvertibleUnit(unit);
|
||||||
if (convertedType != null) {
|
if (convertedType != null) {
|
||||||
val = convertedType.toBigDecimal();
|
val = convertedType.toBigDecimal();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -184,6 +184,14 @@ public class ValueTests {
|
|||||||
assertThat(v.getChannelState(), is(new QuantityType<>(20, Units.WATT)));
|
assertThat(v.getChannelState(), is(new QuantityType<>(20, Units.WATT)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void numberUpdateMireds() {
|
||||||
|
NumberValue v = new NumberValue(null, null, new BigDecimal(10), Units.MIRED);
|
||||||
|
|
||||||
|
v.update(new QuantityType<>(2700, Units.KELVIN));
|
||||||
|
assertThat(v.getMQTTpublishValue("%.0f"), is("370"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void numberPercentageUpdate() {
|
public void numberPercentageUpdate() {
|
||||||
NumberValue v = new NumberValue(null, null, new BigDecimal(10), Units.PERCENT);
|
NumberValue v = new NumberValue(null, null, new BigDecimal(10), Units.PERCENT);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user