|
25 | 25 | import org.openhab.core.library.types.QuantityType;
|
26 | 26 | import org.openhab.core.library.types.StringType;
|
27 | 27 | import org.openhab.core.library.types.UpDownType;
|
| 28 | +import org.openhab.core.library.unit.Units; |
28 | 29 | import org.openhab.core.types.Command;
|
29 | 30 | import org.openhab.core.types.StateDescriptionFragmentBuilder;
|
30 | 31 | import org.openhab.core.types.Type;
|
31 | 32 | import org.openhab.core.types.UnDefType;
|
| 33 | +import org.openhab.core.types.util.UnitUtils; |
32 | 34 | import org.slf4j.Logger;
|
33 | 35 | import org.slf4j.LoggerFactory;
|
34 | 36 |
|
@@ -56,14 +58,25 @@ public class NumberValue extends Value {
|
56 | 58 |
|
57 | 59 | public NumberValue(@Nullable BigDecimal min, @Nullable BigDecimal max, @Nullable BigDecimal step,
|
58 | 60 | @Nullable Unit<?> unit) {
|
59 |
| - super(CoreItemFactory.NUMBER, List.of(DecimalType.class, QuantityType.class, IncreaseDecreaseType.class, |
| 61 | + super(getItemType(unit), List.of(DecimalType.class, QuantityType.class, IncreaseDecreaseType.class, |
60 | 62 | UpDownType.class, StringType.class));
|
61 | 63 | this.min = min;
|
62 | 64 | this.max = max;
|
63 | 65 | this.step = step == null ? BigDecimal.ONE : step;
|
64 | 66 | this.unit = unit;
|
65 | 67 | }
|
66 | 68 |
|
| 69 | + private static String getItemType(@Nullable Unit<?> unit) { |
| 70 | + if (unit == null) { |
| 71 | + return CoreItemFactory.NUMBER; |
| 72 | + } |
| 73 | + String dimension = Units.MIRED.equals(unit) ? "Temperature" : UnitUtils.getDimensionName(unit); |
| 74 | + if (dimension == null) { |
| 75 | + return CoreItemFactory.NUMBER; |
| 76 | + } |
| 77 | + return CoreItemFactory.NUMBER + ":" + dimension; |
| 78 | + } |
| 79 | + |
67 | 80 | protected boolean checkConditions(BigDecimal newValue) {
|
68 | 81 | BigDecimal min = this.min;
|
69 | 82 | if (min != null && newValue.compareTo(min) == -1) {
|
|
0 commit comments