Skip to content

Commit

Permalink
Reduce currency unit work-around after core fix (openhab#16217)
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur authored Jan 6, 2024
1 parent 3415397 commit 89803c1
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,14 @@ private void updatePriceState(String channelID, @Nullable BigDecimal price, Curr
}

private State getEnergyPrice(BigDecimal price, Currency currency) {
Unit<?> unit = CurrencyUnits.getInstance().getUnit(currency.getCurrencyCode());
String currencyCode = currency.getCurrencyCode();
Unit<?> unit = CurrencyUnits.getInstance().getUnit(currencyCode);
if (unit == null) {
logger.trace("Currency {} is unknown, falling back to DecimalType", currency.getCurrencyCode());
return new DecimalType(price);
}
try {
String currencyUnit = unit.getSymbol();
if (currencyUnit == null) {
currencyUnit = unit.getName();
}
return new QuantityType<>(price + " " + currencyUnit + "/kWh");
return new QuantityType<>(price + " " + currencyCode + "/kWh");
} catch (IllegalArgumentException e) {
logger.debug("Unable to create QuantityType, falling back to DecimalType", e);
return new DecimalType(price);
Expand Down

0 comments on commit 89803c1

Please sign in to comment.