Skip to content

Commit 82379f0

Browse files
authored
[jpa] Fix return value for UoM items (openhab#16977)
Signed-off-by: Jan N. Klug <[email protected]>
1 parent 0a7ed2b commit 82379f0

File tree

1 file changed

+7
-2
lines changed
  • bundles/org.openhab.persistence.jpa/src/main/java/org/openhab/persistence/jpa/internal

1 file changed

+7
-2
lines changed

bundles/org.openhab.persistence.jpa/src/main/java/org/openhab/persistence/jpa/internal/JpaHistoricItem.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.List;
2020
import java.util.stream.Collectors;
2121

22+
import javax.measure.Unit;
23+
2224
import org.eclipse.jdt.annotation.NonNullByDefault;
2325
import org.openhab.core.items.Item;
2426
import org.openhab.core.library.items.ContactItem;
@@ -34,6 +36,7 @@
3436
import org.openhab.core.library.types.OpenClosedType;
3537
import org.openhab.core.library.types.PercentType;
3638
import org.openhab.core.library.types.PointType;
39+
import org.openhab.core.library.types.QuantityType;
3740
import org.openhab.core.library.types.StringListType;
3841
import org.openhab.core.library.types.StringType;
3942
import org.openhab.core.persistence.HistoricItem;
@@ -100,8 +103,10 @@ public static List<HistoricItem> fromResultList(List<JpaPersistentItem> jpaQuery
100103
*/
101104
public static HistoricItem fromPersistedItem(JpaPersistentItem pItem, Item item) {
102105
State state;
103-
if (item instanceof NumberItem) {
104-
state = new DecimalType(Double.valueOf(pItem.getValue()));
106+
if (item instanceof NumberItem numberItem) {
107+
Unit<?> unit = numberItem.getUnit();
108+
double value = Double.parseDouble(pItem.getValue());
109+
state = (unit == null) ? new DecimalType(value) : new QuantityType<>(value, unit);
105110
} else if (item instanceof DimmerItem) {
106111
state = new PercentType(Integer.parseInt(pItem.getValue()));
107112
} else if (item instanceof SwitchItem) {

0 commit comments

Comments
 (0)