Skip to content

Commit

Permalink
Make QuantityType.toUnitRelative accept a String (openhab#3802)
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng authored Oct 6, 2023
1 parent fb3d4e8 commit 0d355fb
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,15 @@ && getUnit().inverse().isCompatible(targetUnit)) {
return new QuantityType<>(result.getValue(), targetUnit);
}

public @Nullable QuantityType<T> toUnitRelative(String targetUnit) {
Unit<T> unit = (Unit<T>) AbstractUnit.parse(targetUnit);
if (unit != null) {
return toUnitRelative(unit);
}

return null;
}

public BigDecimal toBigDecimal() {
return new BigDecimal(quantity.getValue().toString());
}
Expand Down

0 comments on commit 0d355fb

Please sign in to comment.