Use core unit classes (#9261)
Add-ons should not depend on tec.uom.se classes but use core unit classes instead so they are less impacted when this library is replaced or upgraded. Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
@@ -23,14 +23,13 @@ import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.IncreaseDecreaseType;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.library.types.UpDownType;
|
||||
import org.openhab.core.library.unit.SmartHomeUnits;
|
||||
import org.openhab.core.types.Command;
|
||||
import org.openhab.core.types.StateDescriptionFragmentBuilder;
|
||||
import org.openhab.core.types.UnDefType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import tec.uom.se.AbstractUnit;
|
||||
|
||||
/**
|
||||
* Implements a number value.
|
||||
*
|
||||
@@ -111,7 +110,7 @@ public class NumberValue extends Value {
|
||||
} else if (command instanceof QuantityType<?>) {
|
||||
QuantityType<?> qType = (QuantityType<?>) command;
|
||||
|
||||
if (qType.getUnit().isCompatible(AbstractUnit.ONE)) {
|
||||
if (qType.getUnit().isCompatible(SmartHomeUnits.ONE)) {
|
||||
newValue = qType.toBigDecimal();
|
||||
} else {
|
||||
qType = qType.toUnit(unit);
|
||||
|
||||
@@ -27,12 +27,11 @@ import org.openhab.core.library.types.PercentType;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
import org.openhab.core.library.types.UpDownType;
|
||||
import org.openhab.core.library.unit.SmartHomeUnits;
|
||||
import org.openhab.core.types.Command;
|
||||
import org.openhab.core.types.StateDescriptionFragmentBuilder;
|
||||
import org.openhab.core.types.UnDefType;
|
||||
|
||||
import tec.uom.se.unit.Units;
|
||||
|
||||
/**
|
||||
* Implements a percentage value. Minimum and maximum are definable.
|
||||
*
|
||||
@@ -88,7 +87,7 @@ public class PercentageValue extends Value {
|
||||
} else //
|
||||
// A quantity type need to be converted according to the current min/max values
|
||||
if (command instanceof QuantityType) {
|
||||
QuantityType<?> qty = ((QuantityType<?>) command).toUnit(Units.PERCENT);
|
||||
QuantityType<?> qty = ((QuantityType<?>) command).toUnit(SmartHomeUnits.PERCENT);
|
||||
if (qty != null) {
|
||||
BigDecimal v = qty.toBigDecimal();
|
||||
v = v.subtract(min).multiply(HUNDRED).divide(max.subtract(min), MathContext.DECIMAL128);
|
||||
|
||||
Reference in New Issue
Block a user