From 56fa90549602bbcbc84f75428bbd91e93c503135 Mon Sep 17 00:00:00 2001 From: obones Date: Wed, 26 Jun 2024 14:02:06 +0200 Subject: [PATCH] feat: declare and use the JOULES_PER_KILOGRAM unit --- .../internal/handler/OpenMeteoForecastThingHandler.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/obones/binding/openmeteo/internal/handler/OpenMeteoForecastThingHandler.java b/src/main/java/com/obones/binding/openmeteo/internal/handler/OpenMeteoForecastThingHandler.java index 2ee096f..ec4c5ea 100644 --- a/src/main/java/com/obones/binding/openmeteo/internal/handler/OpenMeteoForecastThingHandler.java +++ b/src/main/java/com/obones/binding/openmeteo/internal/handler/OpenMeteoForecastThingHandler.java @@ -20,6 +20,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.measure.Unit; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.i18n.CommunicationException; @@ -47,8 +49,12 @@ import com.openmeteo.sdk.Variable; import com.openmeteo.sdk.WeatherApiResponse; +import tech.units.indriya.unit.ProductUnit; + @NonNullByDefault public class OpenMeteoForecastThingHandler extends OpenMeteoBaseThingHandler { + private static Unit JOULES_PER_KILOGRAM = new ProductUnit<>( + Units.JOULE.divide(tech.units.indriya.unit.Units.KILOGRAM)); private @NonNullByDefault({}) final Logger logger = LoggerFactory.getLogger(OpenMeteoBridgeHandler.class); @@ -726,7 +732,7 @@ protected State getForecastState(String channelId, @Nullable Float floatValue, @ state = getQuantityTypeState(floatValue, MetricPrefix.HECTO(SIUnits.PASCAL)); break; case CHANNEL_FORECAST_CAPE: - state = getDecimalTypeState(floatValue); // no J/kg unit + state = getQuantityTypeState(floatValue, JOULES_PER_KILOGRAM); break; case CHANNEL_FORECAST_EVAPOTRANSPIRATION: state = getQuantityTypeState(floatValue, MetricPrefix.MILLI(SIUnits.METRE));