Reduce currency unit work-around after core fix (#16217)

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-01-06 18:19:55 +01:00 committed by GitHub
parent 3415397a83
commit 89803c1a19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -340,17 +340,14 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
}
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);