|
19 | 19 | import java.util.List;
|
20 | 20 | import java.util.stream.Collectors;
|
21 | 21 |
|
| 22 | +import javax.measure.Unit; |
| 23 | + |
22 | 24 | import org.eclipse.jdt.annotation.NonNullByDefault;
|
23 | 25 | import org.openhab.core.items.Item;
|
24 | 26 | import org.openhab.core.library.items.ContactItem;
|
|
34 | 36 | import org.openhab.core.library.types.OpenClosedType;
|
35 | 37 | import org.openhab.core.library.types.PercentType;
|
36 | 38 | import org.openhab.core.library.types.PointType;
|
| 39 | +import org.openhab.core.library.types.QuantityType; |
37 | 40 | import org.openhab.core.library.types.StringListType;
|
38 | 41 | import org.openhab.core.library.types.StringType;
|
39 | 42 | import org.openhab.core.persistence.HistoricItem;
|
@@ -100,8 +103,10 @@ public static List<HistoricItem> fromResultList(List<JpaPersistentItem> jpaQuery
|
100 | 103 | */
|
101 | 104 | public static HistoricItem fromPersistedItem(JpaPersistentItem pItem, Item item) {
|
102 | 105 | 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); |
105 | 110 | } else if (item instanceof DimmerItem) {
|
106 | 111 | state = new PercentType(Integer.parseInt(pItem.getValue()));
|
107 | 112 | } else if (item instanceof SwitchItem) {
|
|
0 commit comments