Skip to content

Commit

Permalink
feat: declare and use the JOULES_PER_KILOGRAM unit
Browse files Browse the repository at this point in the history
  • Loading branch information
obones committed Jun 26, 2024
1 parent 7c27e65 commit 56fa905
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 56fa905

Please sign in to comment.