Skip to content

Commit

Permalink
[mqtt] support mired<->Kelvin unit conversion (openhab#13575)
Browse files Browse the repository at this point in the history
Just have to use the newer toInvertibleUnit method that allows
the dimension to change.

Signed-off-by: Cody Cutrer <cody@cutrer.us>
  • Loading branch information
ccutrer authored and psmedley committed Feb 23, 2023
1 parent e09f5e2 commit 24c03f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private BigDecimal getOldValue() {
private BigDecimal getQuantityTypeAsDecimal(QuantityType<?> qType) {
BigDecimal val = qType.toBigDecimal();
if (!qType.getUnit().isCompatible(Units.ONE)) {
QuantityType<?> convertedType = qType.toUnit(unit);
QuantityType<?> convertedType = qType.toInvertibleUnit(unit);
if (convertedType != null) {
val = convertedType.toBigDecimal();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ public void numberUpdate() {
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
public void numberPercentageUpdate() {
NumberValue v = new NumberValue(null, null, new BigDecimal(10), Units.PERCENT);
Expand Down

0 comments on commit 24c03f2

Please sign in to comment.