Rename classes with "SmartHome" in their name (#1896)

* Rename SmartHomeUnits to Units
* Rename SmartHome Servlets and HTTP Context

Signed-off-by: Wouter Born <github@maindrain.net>
pull/1897/head
Wouter Born 2020-12-06 23:35:37 +01:00 committed by GitHub
parent f99135ae3d
commit 13c2d7bf2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 222 additions and 223 deletions

View File

@ -34,7 +34,7 @@ import org.openhab.core.audio.AudioFormat;
import org.openhab.core.audio.AudioHTTPServer;
import org.openhab.core.audio.AudioStream;
import org.openhab.core.audio.FixedLengthAudioStream;
import org.openhab.core.io.http.servlet.SmartHomeServlet;
import org.openhab.core.io.http.servlet.OpenHABServlet;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
@ -49,7 +49,7 @@ import org.osgi.service.http.HttpService;
*/
@NonNullByDefault
@Component
public class AudioServlet extends SmartHomeServlet implements AudioHTTPServer {
public class AudioServlet extends OpenHABServlet implements AudioHTTPServer {
private static final long serialVersionUID = -3364664035854567854L;

View File

@ -50,7 +50,7 @@ import org.openhab.core.library.unit.BinaryPrefix;
import org.openhab.core.library.unit.ImperialUnits;
import org.openhab.core.library.unit.MetricPrefix;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.ThingRegistry;
import org.openhab.core.thing.binding.ThingActions;
import org.openhab.core.types.Command;
@ -150,7 +150,7 @@ public class DefaultScriptScopeProvider implements ScriptExtensionProvider {
elements.put("SIUnits", SIUnits.class);
elements.put("ImperialUnits", ImperialUnits.class);
elements.put("MetricPrefix", MetricPrefix.class);
elements.put("SmartHomeUnits", SmartHomeUnits.class);
elements.put("Units", Units.class);
elements.put("BinaryPrefix", BinaryPrefix.class);
// services

View File

@ -33,17 +33,17 @@ import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.http.HttpContext;
/**
* Default http context implementation which groups all Smart Home related http elements into one logical application.
* Default HTTP context implementation which groups all openHAB related HTTP elements into one logical application.
*
* Additionally to standard http context, this one provides its own implementation of
* {@link #handleSecurity(HttpServletRequest, HttpServletResponse)} method which is based on injected list of generic
* handlers.
* Additionally to the standard HTTP context, this class provides its own implementation of the
* {@link #handleSecurity(HttpServletRequest, HttpServletResponse)} method which is based on the injected list of
* {@link Handler}s.
*
* @author Łukasz Dywicki - Initial contribution
*/
@Component(service = { HttpContext.class, WrappingHttpContext.class }, property = {
"httpContext.id:String=oh-dfl-http-ctx" })
public class SmartHomeHttpContext implements WrappingHttpContext {
public class OpenHABHttpContext implements WrappingHttpContext {
/**
* Sorted list of handlers, where handler with priority 0 is first.

View File

@ -30,21 +30,21 @@ import org.slf4j.LoggerFactory;
* @author Łukasz Dywicki - Initial contribution
*/
@NonNullByDefault
public abstract class BaseSmartHomeServlet extends HttpServlet {
public abstract class BaseOpenHABServlet extends HttpServlet {
private static final long serialVersionUID = 6020752826735599455L;
/**
* Logger bound to child class.
*/
protected final Logger logger = LoggerFactory.getLogger(BaseSmartHomeServlet.class);
protected final Logger logger = LoggerFactory.getLogger(BaseOpenHABServlet.class);
/**
* Http service.
*/
protected final HttpService httpService;
public BaseSmartHomeServlet(HttpService httpService) {
public BaseOpenHABServlet(HttpService httpService) {
this.httpService = httpService;
}

View File

@ -25,11 +25,11 @@ import org.osgi.service.http.HttpService;
* @author Łukasz Dywicki - Initial contribution
*/
@NonNullByDefault
public abstract class SmartHomeBundleServlet extends BaseSmartHomeServlet {
public abstract class OpenHABBundleServlet extends BaseOpenHABServlet {
protected final HttpContextFactoryService httpContextFactoryService;
public SmartHomeBundleServlet(HttpService httpService, HttpContextFactoryService httpContextFactoryService) {
public OpenHABBundleServlet(HttpService httpService, HttpContextFactoryService httpContextFactoryService) {
super(httpService);
this.httpContextFactoryService = httpContextFactoryService;
}

View File

@ -22,7 +22,7 @@ import org.osgi.service.http.HttpService;
* @author Łukasz Dywicki - Initial contribution
*/
@NonNullByDefault
public abstract class SmartHomeServlet extends BaseSmartHomeServlet {
public abstract class OpenHABServlet extends BaseOpenHABServlet {
private static final long serialVersionUID = 6854521240046714164L;
@ -31,7 +31,7 @@ public abstract class SmartHomeServlet extends BaseSmartHomeServlet {
*/
protected final HttpContext httpContext;
public SmartHomeServlet(HttpService httpService, HttpContext httpContext) {
public OpenHABServlet(HttpService httpService, HttpContext httpContext) {
super(httpService);
this.httpContext = httpContext;
}

View File

@ -19,7 +19,7 @@ import javax.measure.quantity.Dimensionless;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.types.Type;
/**
@ -95,7 +95,7 @@ public class NumberExtensions {
public static boolean operator_equals(Number left, Number right) {
// in case one of the Number instances is of type QuantityType they are never equal (except for
// SmartHomeUnit.ONE).
// Units.ONE).
// for both instances being QuantityTypes the specific method
// operator_equals(QuantityType<?> left, QuantityType<?> right) is called by the script engine.
if (oneIsQuantity(left, right)) {
@ -282,7 +282,7 @@ public class NumberExtensions {
}
public static QuantityType<?> operator_divide(Number x, QuantityType<?> y) {
QuantityType<Dimensionless> xQuantity = new QuantityType<>(x, SmartHomeUnits.ONE);
QuantityType<Dimensionless> xQuantity = new QuantityType<>(x, Units.ONE);
return operator_divide(xQuantity, y);
}
@ -294,7 +294,7 @@ public class NumberExtensions {
return left.equals(right);
}
// support SmartHomeUnit.ONE as Number representation
// support Units.ONE as Number representation
public static boolean operator_equals(QuantityType<?> left, Number right) {
return operator_equals((Number) left, right);
}
@ -303,7 +303,7 @@ public class NumberExtensions {
return !operator_equals(left, right);
}
// support SmartHomeUnit.ONE as Number representation
// support Units.ONE as Number representation
public static boolean operator_notEquals(QuantityType<?> left, Number right) {
return operator_notEquals((Number) left, right);
}
@ -317,7 +317,7 @@ public class NumberExtensions {
}
}
// support SmartHomeUnit.ONE as Number representation
// support Units.ONE as Number representation
public static boolean operator_lessThan(QuantityType<?> x, Number y) {
return operator_lessThan((Number) x, y);
}
@ -331,7 +331,7 @@ public class NumberExtensions {
}
}
// support SmartHomeUnit.ONE as Number representation
// support Units.ONE as Number representation
public static boolean operator_lessEqualsThan(QuantityType<?> x, Number y) {
return operator_lessEqualsThan((Number) x, y);
}
@ -345,7 +345,7 @@ public class NumberExtensions {
}
}
// support SmartHomeUnit.ONE as Number representation
// support Units.ONE as Number representation
public static boolean operator_greaterThan(QuantityType<?> x, Number y) {
return operator_greaterThan((Number) x, y);
}
@ -359,7 +359,7 @@ public class NumberExtensions {
}
}
// support SmartHomeUnit.ONE as Number representation
// support Units.ONE as Number representation
public static boolean operator_greaterEqualsThan(QuantityType<?> x, Number y) {
return operator_greaterEqualsThan((Number) x, y);
}
@ -393,7 +393,7 @@ public class NumberExtensions {
}
private static boolean isAbstractUnitOne(QuantityType<?> left) {
return SmartHomeUnits.ONE.equals(left.getUnit());
return Units.ONE.equals(left.getUnit());
}
}

View File

@ -24,7 +24,7 @@ import org.openhab.core.library.unit.BinaryPrefix;
import org.openhab.core.library.unit.ImperialUnits;
import org.openhab.core.library.unit.MetricPrefix;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.model.script.actions.BusEvent;
import org.openhab.core.model.script.actions.Exec;
import org.openhab.core.model.script.actions.HTTP;
@ -96,7 +96,7 @@ public class ScriptImplicitlyImportedTypes extends ImplicitlyImportedFeatures {
result.add(ImperialUnits.class);
result.add(MetricPrefix.class);
result.add(SIUnits.class);
result.add(SmartHomeUnits.class);
result.add(Units.class);
result.add(BinaryPrefix.class);
// date time static functions

View File

@ -19,7 +19,7 @@ import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.profiles.ProfileCallback;
import org.openhab.core.thing.profiles.ProfileContext;
import org.openhab.core.thing.profiles.ProfileTypeUID;
@ -134,7 +134,7 @@ public class SystemHysteresisStateProfile implements StateProfile {
final QuantityType<?> qtState = (QuantityType<?>) value;
final QuantityType<?> finalLower;
final QuantityType<?> finalUpper;
if (lower.getUnit() == SmartHomeUnits.ONE && upper.getUnit() == SmartHomeUnits.ONE) {
if (lower.getUnit() == Units.ONE && upper.getUnit() == Units.ONE) {
// allow bounds without unit -> implicitly assume its the same as the one from the state, but warn
// the user
finalLower = new QuantityType<>(lower.toBigDecimal(), qtState.getUnit());

View File

@ -23,7 +23,7 @@ import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.ImperialUnits;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.profiles.ProfileCallback;
import org.openhab.core.thing.profiles.ProfileContext;
import org.openhab.core.thing.profiles.ProfileTypeUID;
@ -45,9 +45,9 @@ import org.slf4j.LoggerFactory;
public class SystemOffsetProfile implements StateProfile {
private static final @Nullable QuantityType<Temperature> ZERO_CELSIUS_IN_KELVIN = new QuantityType<>(0,
SIUnits.CELSIUS).toUnit(SmartHomeUnits.KELVIN);
SIUnits.CELSIUS).toUnit(Units.KELVIN);
private static final @Nullable QuantityType<Temperature> ZERO_FAHRENHEIT_IN_KELVIN = new QuantityType<>(0,
ImperialUnits.FAHRENHEIT).toUnit(SmartHomeUnits.KELVIN);
ImperialUnits.FAHRENHEIT).toUnit(Units.KELVIN);
static final String OFFSET_PARAM = "offset";
private final Logger logger = LoggerFactory.getLogger(SystemOffsetProfile.class);
@ -115,7 +115,7 @@ public class SystemOffsetProfile implements StateProfile {
if (state instanceof QuantityType) {
QuantityType qtState = (QuantityType) state;
try {
if (finalOffset.getUnit() == SmartHomeUnits.ONE) {
if (finalOffset.getUnit() == Units.ONE) {
// allow offsets without unit -> implicitly assume its the same as the one from the state, but warn
// the user
finalOffset = new QuantityType<>(finalOffset.toBigDecimal(), qtState.getUnit());
@ -124,7 +124,7 @@ public class SystemOffsetProfile implements StateProfile {
state, offset);
}
// take care of temperatures because they start at offset -273°C = 0K
if (SmartHomeUnits.KELVIN.equals(qtState.getUnit().getSystemUnit())) {
if (Units.KELVIN.equals(qtState.getUnit().getSystemUnit())) {
QuantityType<Temperature> tmp = handleTemperature(qtState, finalOffset);
if (tmp != null) {
result = tmp;
@ -135,7 +135,7 @@ public class SystemOffsetProfile implements StateProfile {
} catch (UnconvertibleException e) {
logger.warn("Cannot apply offset '{}' to state '{}' because types do not match.", finalOffset, qtState);
}
} else if (state instanceof DecimalType && finalOffset.getUnit() == SmartHomeUnits.ONE) {
} else if (state instanceof DecimalType && finalOffset.getUnit() == Units.ONE) {
DecimalType decState = (DecimalType) state;
result = new DecimalType(decState.toBigDecimal().add(finalOffset.toBigDecimal()));
} else {
@ -150,8 +150,8 @@ public class SystemOffsetProfile implements StateProfile {
private @Nullable QuantityType<Temperature> handleTemperature(QuantityType<Temperature> qtState,
QuantityType<Temperature> offset) {
// do the math in Kelvin and afterwards convert it back to the unit of the state
final QuantityType<Temperature> kelvinState = qtState.toUnit(SmartHomeUnits.KELVIN);
final QuantityType<Temperature> kelvinOffset = offset.toUnit(SmartHomeUnits.KELVIN);
final QuantityType<Temperature> kelvinState = qtState.toUnit(Units.KELVIN);
final QuantityType<Temperature> kelvinOffset = offset.toUnit(Units.KELVIN);
if (kelvinState == null || kelvinOffset == null) {
return null;
}

View File

@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.io.http.servlet.SmartHomeServlet;
import org.openhab.core.io.http.servlet.OpenHABServlet;
import org.openhab.core.ui.icon.IconProvider;
import org.openhab.core.ui.icon.IconSet.Format;
import org.osgi.service.component.annotations.Activate;
@ -48,7 +48,7 @@ import org.slf4j.LoggerFactory;
*/
@Component
@NonNullByDefault
public class IconServlet extends SmartHomeServlet {
public class IconServlet extends OpenHABServlet {
private static final long serialVersionUID = 2880642275858634578L;

View File

@ -33,7 +33,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.openhab.core.config.core.ConfigurableService;
import org.openhab.core.io.http.servlet.SmartHomeServlet;
import org.openhab.core.io.http.servlet.OpenHABServlet;
import org.openhab.core.items.ItemNotFoundException;
import org.openhab.core.ui.chart.ChartProvider;
import org.osgi.framework.Constants;
@ -68,7 +68,7 @@ import org.osgi.service.http.HttpService;
@Component(immediate = true, service = ChartServlet.class, configurationPid = "org.openhab.chart", //
property = Constants.SERVICE_PID + "=org.openhab.chart")
@ConfigurableService(category = "system", label = "Charts", description_uri = ChartServlet.CONFIG_URI)
public class ChartServlet extends SmartHomeServlet {
public class ChartServlet extends OpenHABServlet {
private static final long serialVersionUID = 7700873790924746422L;

View File

@ -44,7 +44,7 @@ import org.openhab.core.library.dimension.Intensity;
import org.openhab.core.library.types.PointType;
import org.openhab.core.library.unit.ImperialUnits;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.service.component.ComponentContext;
@ -364,18 +364,18 @@ public class I18nProviderImpl
dimensionMap.put(Length.class, lengthMap);
Map<SystemOfUnits, Unit<? extends Quantity<?>>> intensityMap = new HashMap<>();
intensityMap.put(SIUnits.getInstance(), SmartHomeUnits.IRRADIANCE);
intensityMap.put(ImperialUnits.getInstance(), SmartHomeUnits.IRRADIANCE);
intensityMap.put(SIUnits.getInstance(), Units.IRRADIANCE);
intensityMap.put(ImperialUnits.getInstance(), Units.IRRADIANCE);
dimensionMap.put(Intensity.class, intensityMap);
Map<SystemOfUnits, Unit<? extends Quantity<?>>> percentMap = new HashMap<>();
percentMap.put(SIUnits.getInstance(), SmartHomeUnits.ONE);
percentMap.put(ImperialUnits.getInstance(), SmartHomeUnits.ONE);
percentMap.put(SIUnits.getInstance(), Units.ONE);
percentMap.put(ImperialUnits.getInstance(), Units.ONE);
dimensionMap.put(Dimensionless.class, percentMap);
Map<SystemOfUnits, Unit<? extends Quantity<?>>> angleMap = new HashMap<>();
angleMap.put(SIUnits.getInstance(), SmartHomeUnits.DEGREE_ANGLE);
angleMap.put(ImperialUnits.getInstance(), SmartHomeUnits.DEGREE_ANGLE);
angleMap.put(SIUnits.getInstance(), Units.DEGREE_ANGLE);
angleMap.put(ImperialUnits.getInstance(), Units.DEGREE_ANGLE);
dimensionMap.put(Angle.class, angleMap);
}
}

View File

@ -14,7 +14,7 @@ package org.openhab.core.internal.library.unit;
import org.openhab.core.library.unit.ImperialUnits;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
/**
* Make sure static blocks from {@link SIUnits} & {@link ImperialUnits} are executed to initialize the unit parser.
@ -24,7 +24,7 @@ import org.openhab.core.library.unit.SmartHomeUnits;
public class UnitInitializer {
static {
SmartHomeUnits.getInstance();
Units.getInstance();
SIUnits.getInstance();
ImperialUnits.getInstance();
}

View File

@ -17,7 +17,7 @@ import java.math.RoundingMode;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.types.State;
/**
@ -87,7 +87,7 @@ public class PercentType extends DecimalType {
} else if (target == HSBType.class) {
return target.cast(new HSBType(DecimalType.ZERO, PercentType.ZERO, this));
} else if (target == QuantityType.class) {
return target.cast(new QuantityType<>(toBigDecimal().doubleValue(), SmartHomeUnits.PERCENT));
return target.cast(new QuantityType<>(toBigDecimal().doubleValue(), Units.PERCENT));
} else {
return defaultConversion(target);
}

View File

@ -33,7 +33,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.internal.library.unit.UnitInitializer;
import org.openhab.core.library.unit.MetricPrefix;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.types.Command;
import org.openhab.core.types.PrimitiveType;
import org.openhab.core.types.State;
@ -238,15 +238,15 @@ public class QuantityType<T extends Quantity<T>> extends Number
final String formatPattern;
if (unitPlaceholder) {
String unitSymbol = getUnit().equals(SmartHomeUnits.PERCENT) ? "%%" : getUnit().toString();
String unitSymbol = getUnit().equals(Units.PERCENT) ? "%%" : getUnit().toString();
formatPattern = pattern.replace(UnitUtils.UNIT_PLACEHOLDER, unitSymbol);
} else {
formatPattern = pattern;
}
// The dimension could be a time value thus we want to support patterns to format datetime
if (quantity.getUnit().isCompatible(SmartHomeUnits.SECOND) && !unitPlaceholder) {
QuantityType<T> millis = toUnit(MetricPrefix.MILLI(SmartHomeUnits.SECOND));
if (quantity.getUnit().isCompatible(Units.SECOND) && !unitPlaceholder) {
QuantityType<T> millis = toUnit(MetricPrefix.MILLI(Units.SECOND));
if (millis != null) {
try {
return String.format(formatPattern,
@ -309,7 +309,7 @@ public class QuantityType<T extends Quantity<T>> extends Number
if (target == OnOffType.class) {
if (intValue() == 0) {
return target.cast(OnOffType.OFF);
} else if (SmartHomeUnits.PERCENT.equals(getUnit())) {
} else if (Units.PERCENT.equals(getUnit())) {
return target.cast(toBigDecimal().compareTo(BigDecimal.ZERO) > 0 ? OnOffType.ON : OnOffType.OFF);
} else if (toBigDecimal().compareTo(BigDecimal.ONE) == 0) {
return target.cast(OnOffType.ON);
@ -336,7 +336,7 @@ public class QuantityType<T extends Quantity<T>> extends Number
return target.cast(
new HSBType(DecimalType.ZERO, PercentType.ZERO, new PercentType(toBigDecimal().multiply(HUNDRED))));
} else if (target == PercentType.class) {
if (SmartHomeUnits.PERCENT.equals(getUnit())) {
if (Units.PERCENT.equals(getUnit())) {
return target.cast(new PercentType(toBigDecimal()));
}
return target.cast(new PercentType(toBigDecimal().multiply(HUNDRED)));

View File

@ -67,7 +67,6 @@ import tec.uom.se.function.RationalConverter;
import tec.uom.se.unit.AlternateUnit;
import tec.uom.se.unit.ProductUnit;
import tec.uom.se.unit.TransformedUnit;
import tec.uom.se.unit.Units;
/**
* Delegate common units to {@link Units} to hide this dependency from the rest of openHAB.
@ -77,108 +76,115 @@ import tec.uom.se.unit.Units;
* @author Henning Treu - Initial contribution
*/
@NonNullByDefault
public final class SmartHomeUnits extends CustomUnits {
public final class Units extends CustomUnits {
private static final SmartHomeUnits INSTANCE = new SmartHomeUnits();
private static final Units INSTANCE = new Units();
// Alphabetical ordered by Unit.
public static final Unit<Acceleration> METRE_PER_SQUARE_SECOND = addUnit(Units.METRE_PER_SQUARE_SECOND);
public static final Unit<Acceleration> METRE_PER_SQUARE_SECOND = addUnit(
tec.uom.se.unit.Units.METRE_PER_SQUARE_SECOND);
public static final Unit<Acceleration> STANDARD_GRAVITY = addUnit(METRE_PER_SQUARE_SECOND.multiply(9.80665));
public static final Unit<AmountOfSubstance> MOLE = addUnit(Units.MOLE);
public static final Unit<AmountOfSubstance> MOLE = addUnit(tec.uom.se.unit.Units.MOLE);
@SuppressWarnings("unchecked")
public static final Unit<AmountOfSubstance> DEUTSCHE_HAERTE = addUnit(
new TransformedUnit<>("°dH", (Unit<AmountOfSubstance>) MetricPrefix.MILLI(Units.MOLE).divide(Units.LITRE),
RationalConverter.of(5.6, 1)));
public static final Unit<Angle> DEGREE_ANGLE = addUnit(new TransformedUnit<>(Units.RADIAN,
new TransformedUnit<>("°dH", (Unit<AmountOfSubstance>) MetricPrefix.MILLI(tec.uom.se.unit.Units.MOLE)
.divide(tec.uom.se.unit.Units.LITRE), RationalConverter.of(5.6, 1)));
public static final Unit<Angle> DEGREE_ANGLE = addUnit(new TransformedUnit<>(tec.uom.se.unit.Units.RADIAN,
new PiMultiplierConverter().concatenate(new RationalConverter(BigInteger.ONE, BigInteger.valueOf(180)))));
public static final Unit<Angle> RADIAN = addUnit(Units.RADIAN);
public static final Unit<ArealDensity> DOBSON_UNIT = addUnit(
new ProductUnit<ArealDensity>(MetricPrefix.MILLI(Units.MOLE).multiply(0.4462).divide(Units.SQUARE_METRE)));
public static final Unit<CatalyticActivity> KATAL = addUnit(Units.KATAL);
public static final Unit<Angle> RADIAN = addUnit(tec.uom.se.unit.Units.RADIAN);
public static final Unit<ArealDensity> DOBSON_UNIT = addUnit(new ProductUnit<ArealDensity>(MetricPrefix
.MILLI(tec.uom.se.unit.Units.MOLE).multiply(0.4462).divide(tec.uom.se.unit.Units.SQUARE_METRE)));
public static final Unit<CatalyticActivity> KATAL = addUnit(tec.uom.se.unit.Units.KATAL);
public static final Unit<Density> KILOGRAM_PER_CUBICMETRE = addUnit(
new ProductUnit<Density>(Units.KILOGRAM.divide(Units.CUBIC_METRE)));
new ProductUnit<Density>(tec.uom.se.unit.Units.KILOGRAM.divide(tec.uom.se.unit.Units.CUBIC_METRE)));
public static final Unit<Density> MICROGRAM_PER_CUBICMETRE = addUnit(new TransformedUnit<>(KILOGRAM_PER_CUBICMETRE,
new RationalConverter(BigInteger.ONE, BigInteger.valueOf(1000000000))));
public static final Unit<Dimensionless> ONE = addUnit(AbstractUnit.ONE);
public static final Unit<Dimensionless> PERCENT = addUnit(Units.PERCENT);
public static final Unit<Dimensionless> PERCENT = addUnit(tec.uom.se.unit.Units.PERCENT);
public static final Unit<Dimensionless> PARTS_PER_BILLION = addUnit(
new TransformedUnit<>(ONE, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(1000000000))));
public static final Unit<Dimensionless> PARTS_PER_MILLION = addUnit(
new TransformedUnit<>(ONE, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(1000000))));
public static final Unit<Dimensionless> DECIBEL = addUnit(ONE.transform(
new LogConverter(10).inverse().concatenate(new RationalConverter(BigInteger.ONE, BigInteger.TEN))));
public static final Unit<ElectricCurrent> AMPERE = addUnit(Units.AMPERE);
public static final Unit<ElectricCapacitance> FARAD = addUnit(Units.FARAD);
public static final Unit<ElectricCharge> COULOMB = addUnit(Units.COULOMB);
public static final Unit<ElectricCharge> AMPERE_HOUR = addUnit(Units.COULOMB.multiply(3600));
public static final Unit<ElectricCurrent> AMPERE = addUnit(tec.uom.se.unit.Units.AMPERE);
public static final Unit<ElectricCapacitance> FARAD = addUnit(tec.uom.se.unit.Units.FARAD);
public static final Unit<ElectricCharge> COULOMB = addUnit(tec.uom.se.unit.Units.COULOMB);
public static final Unit<ElectricCharge> AMPERE_HOUR = addUnit(tec.uom.se.unit.Units.COULOMB.multiply(3600));
public static final Unit<ElectricCharge> MILLIAMPERE_HOUR = addUnit(MetricPrefix.MILLI(AMPERE_HOUR));
public static final Unit<ElectricConductance> SIEMENS = addUnit(Units.SIEMENS);
public static final Unit<ElectricConductance> SIEMENS = addUnit(tec.uom.se.unit.Units.SIEMENS);
public static final Unit<ElectricConductivity> SIEMENS_PER_METRE = addUnit(
new ProductUnit<ElectricConductivity>(Units.SIEMENS.divide(Units.METRE)));
public static final Unit<ElectricInductance> HENRY = addUnit(Units.HENRY);
public static final Unit<ElectricPotential> VOLT = addUnit(Units.VOLT);
public static final Unit<ElectricResistance> OHM = addUnit(Units.OHM);
public static final Unit<Energy> JOULE = addUnit(Units.JOULE);
public static final Unit<Energy> WATT_SECOND = addUnit(new ProductUnit<>(Units.WATT.multiply(Units.SECOND)));
public static final Unit<Energy> WATT_HOUR = addUnit(new ProductUnit<>(Units.WATT.multiply(Units.HOUR)));
new ProductUnit<ElectricConductivity>(tec.uom.se.unit.Units.SIEMENS.divide(tec.uom.se.unit.Units.METRE)));
public static final Unit<ElectricInductance> HENRY = addUnit(tec.uom.se.unit.Units.HENRY);
public static final Unit<ElectricPotential> VOLT = addUnit(tec.uom.se.unit.Units.VOLT);
public static final Unit<ElectricResistance> OHM = addUnit(tec.uom.se.unit.Units.OHM);
public static final Unit<Energy> JOULE = addUnit(tec.uom.se.unit.Units.JOULE);
public static final Unit<Energy> WATT_SECOND = addUnit(
new ProductUnit<>(tec.uom.se.unit.Units.WATT.multiply(tec.uom.se.unit.Units.SECOND)));
public static final Unit<Energy> WATT_HOUR = addUnit(
new ProductUnit<>(tec.uom.se.unit.Units.WATT.multiply(tec.uom.se.unit.Units.HOUR)));
public static final Unit<Energy> KILOWATT_HOUR = addUnit(MetricPrefix.KILO(WATT_HOUR));
public static final Unit<Energy> MEGAWATT_HOUR = addUnit(MetricPrefix.MEGA(WATT_HOUR));
public static final Unit<Power> VAR = addUnit(new AlternateUnit<>(Units.WATT, "var"));
public static final Unit<Power> VAR = addUnit(new AlternateUnit<>(tec.uom.se.unit.Units.WATT, "var"));
public static final Unit<Power> KILOVAR = addUnit(MetricPrefix.KILO(VAR));
public static final Unit<Energy> VAR_HOUR = addUnit(new ProductUnit<>(VAR.multiply(Units.HOUR)), Energy.class);
public static final Unit<Energy> KILOVAR_HOUR = addUnit(MetricPrefix.KILO(VAR_HOUR));
public static final Unit<Power> VOLT_AMPERE = addUnit(new AlternateUnit<>(Units.WATT, "VA"));
public static final Unit<Energy> VOLT_AMPERE_HOUR = addUnit(new ProductUnit<>(VOLT_AMPERE.multiply(Units.HOUR)),
public static final Unit<Energy> VAR_HOUR = addUnit(new ProductUnit<>(VAR.multiply(tec.uom.se.unit.Units.HOUR)),
Energy.class);
public static final Unit<Force> NEWTON = addUnit(Units.NEWTON);
public static final Unit<Frequency> HERTZ = addUnit(Units.HERTZ);
public static final Unit<Intensity> IRRADIANCE = addUnit(new ProductUnit<>(Units.WATT.divide(Units.SQUARE_METRE)));
public static final Unit<Energy> KILOVAR_HOUR = addUnit(MetricPrefix.KILO(VAR_HOUR));
public static final Unit<Power> VOLT_AMPERE = addUnit(new AlternateUnit<>(tec.uom.se.unit.Units.WATT, "VA"));
public static final Unit<Energy> VOLT_AMPERE_HOUR = addUnit(
new ProductUnit<>(VOLT_AMPERE.multiply(tec.uom.se.unit.Units.HOUR)), Energy.class);
public static final Unit<Force> NEWTON = addUnit(tec.uom.se.unit.Units.NEWTON);
public static final Unit<Frequency> HERTZ = addUnit(tec.uom.se.unit.Units.HERTZ);
public static final Unit<Intensity> IRRADIANCE = addUnit(
new ProductUnit<>(tec.uom.se.unit.Units.WATT.divide(tec.uom.se.unit.Units.SQUARE_METRE)));
public static final Unit<Intensity> MICROWATT_PER_SQUARE_CENTIMETRE = addUnit(
new TransformedUnit<>(IRRADIANCE, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(100))));
public static final Unit<Illuminance> LUX = addUnit(Units.LUX);
public static final Unit<LuminousFlux> LUMEN = addUnit(Units.LUMEN);
public static final Unit<LuminousIntensity> CANDELA = addUnit(Units.CANDELA);
public static final Unit<MagneticFlux> WEBER = addUnit(Units.WEBER);
public static final Unit<MagneticFluxDensity> TESLA = addUnit(Units.TESLA);
public static final Unit<Power> WATT = addUnit(Units.WATT);
public static final Unit<Illuminance> LUX = addUnit(tec.uom.se.unit.Units.LUX);
public static final Unit<LuminousFlux> LUMEN = addUnit(tec.uom.se.unit.Units.LUMEN);
public static final Unit<LuminousIntensity> CANDELA = addUnit(tec.uom.se.unit.Units.CANDELA);
public static final Unit<MagneticFlux> WEBER = addUnit(tec.uom.se.unit.Units.WEBER);
public static final Unit<MagneticFluxDensity> TESLA = addUnit(tec.uom.se.unit.Units.TESLA);
public static final Unit<Power> WATT = addUnit(tec.uom.se.unit.Units.WATT);
public static final Unit<Power> DECIBEL_MILLIWATTS = new TransformedUnit<>("dBm", MetricPrefix.MILLI(WATT),
new ExpConverter(10.0).concatenate(new MultiplyConverter(0.1)));
public static final Unit<Pressure> MILLIMETRE_OF_MERCURY = addUnit(new TransformedUnit<>("mmHg", Units.PASCAL,
new RationalConverter(BigInteger.valueOf(133322368), BigInteger.valueOf(1000000))));
public static final Unit<Pressure> BAR = addUnit(new TransformedUnit<>("bar", Units.PASCAL,
public static final Unit<Pressure> MILLIMETRE_OF_MERCURY = addUnit(
new TransformedUnit<>("mmHg", tec.uom.se.unit.Units.PASCAL,
new RationalConverter(BigInteger.valueOf(133322368), BigInteger.valueOf(1000000))));
public static final Unit<Pressure> BAR = addUnit(new TransformedUnit<>("bar", tec.uom.se.unit.Units.PASCAL,
new RationalConverter(BigInteger.valueOf(100000), BigInteger.ONE)));
public static final Unit<Pressure> MILLIBAR = addUnit(MetricPrefix.MILLI(BAR));
public static final Unit<Radioactivity> BECQUEREL = addUnit(Units.BECQUEREL);
public static final Unit<Radioactivity> BECQUEREL = addUnit(tec.uom.se.unit.Units.BECQUEREL);
public static final Unit<Density> BECQUEREL_PER_CUBIC_METRE = addUnit(
new ProductUnit<>(Units.BECQUEREL.divide(Units.CUBIC_METRE)));
public static final Unit<RadiationDoseAbsorbed> GRAY = addUnit(Units.GRAY);
public static final Unit<RadiationDoseEffective> SIEVERT = addUnit(Units.SIEVERT);
public static final Unit<Speed> MILLIMETRE_PER_HOUR = addUnit(new TransformedUnit<>("mm/h",
Units.KILOMETRE_PER_HOUR, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(1000000))));
new ProductUnit<>(tec.uom.se.unit.Units.BECQUEREL.divide(tec.uom.se.unit.Units.CUBIC_METRE)));
public static final Unit<RadiationDoseAbsorbed> GRAY = addUnit(tec.uom.se.unit.Units.GRAY);
public static final Unit<RadiationDoseEffective> SIEVERT = addUnit(tec.uom.se.unit.Units.SIEVERT);
public static final Unit<Speed> MILLIMETRE_PER_HOUR = addUnit(
new TransformedUnit<>("mm/h", tec.uom.se.unit.Units.KILOMETRE_PER_HOUR,
new RationalConverter(BigInteger.ONE, BigInteger.valueOf(1000000))));
public static final Unit<Speed> INCHES_PER_HOUR = addUnit(new TransformedUnit<>("in/h",
ImperialUnits.MILES_PER_HOUR, new RationalConverter(BigInteger.ONE, BigInteger.valueOf(63360))));
public static final Unit<Speed> METRE_PER_SECOND = addUnit(Units.METRE_PER_SECOND);
public static final Unit<Speed> KNOT = addUnit(new TransformedUnit<>("kn", Units.KILOMETRE_PER_HOUR,
public static final Unit<Speed> METRE_PER_SECOND = addUnit(tec.uom.se.unit.Units.METRE_PER_SECOND);
public static final Unit<Speed> KNOT = addUnit(new TransformedUnit<>("kn", tec.uom.se.unit.Units.KILOMETRE_PER_HOUR,
new RationalConverter(BigInteger.valueOf(1852), BigInteger.valueOf(1000))));
public static final Unit<SolidAngle> STERADIAN = addUnit(Units.STERADIAN);
public static final Unit<Temperature> KELVIN = addUnit(Units.KELVIN);
public static final Unit<Time> SECOND = addUnit(Units.SECOND);
public static final Unit<Time> MINUTE = addUnit(Units.MINUTE);
public static final Unit<Time> HOUR = addUnit(Units.HOUR);
public static final Unit<Time> DAY = addUnit(Units.DAY);
public static final Unit<Time> WEEK = addUnit(Units.WEEK);
public static final Unit<Time> YEAR = addUnit(Units.YEAR);
public static final Unit<Volume> LITRE = addUnit(Units.LITRE);
public static final Unit<SolidAngle> STERADIAN = addUnit(tec.uom.se.unit.Units.STERADIAN);
public static final Unit<Temperature> KELVIN = addUnit(tec.uom.se.unit.Units.KELVIN);
public static final Unit<Time> SECOND = addUnit(tec.uom.se.unit.Units.SECOND);
public static final Unit<Time> MINUTE = addUnit(tec.uom.se.unit.Units.MINUTE);
public static final Unit<Time> HOUR = addUnit(tec.uom.se.unit.Units.HOUR);
public static final Unit<Time> DAY = addUnit(tec.uom.se.unit.Units.DAY);
public static final Unit<Time> WEEK = addUnit(tec.uom.se.unit.Units.WEEK);
public static final Unit<Time> YEAR = addUnit(tec.uom.se.unit.Units.YEAR);
public static final Unit<Volume> LITRE = addUnit(tec.uom.se.unit.Units.LITRE);
public static final Unit<VolumetricFlowRate> LITRE_PER_MINUTE = addUnit(
new ProductUnit<VolumetricFlowRate>(Units.LITRE.divide(Units.MINUTE)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_SECOND = addUnit(
new ProductUnit<VolumetricFlowRate>(Units.CUBIC_METRE.divide(Units.SECOND)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_MINUTE = addUnit(
new ProductUnit<VolumetricFlowRate>(Units.CUBIC_METRE.divide(Units.MINUTE)));
new ProductUnit<VolumetricFlowRate>(tec.uom.se.unit.Units.LITRE.divide(tec.uom.se.unit.Units.MINUTE)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_SECOND = addUnit(new ProductUnit<VolumetricFlowRate>(
tec.uom.se.unit.Units.CUBIC_METRE.divide(tec.uom.se.unit.Units.SECOND)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_MINUTE = addUnit(new ProductUnit<VolumetricFlowRate>(
tec.uom.se.unit.Units.CUBIC_METRE.divide(tec.uom.se.unit.Units.MINUTE)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_HOUR = addUnit(
new ProductUnit<VolumetricFlowRate>(Units.CUBIC_METRE.divide(Units.HOUR)));
new ProductUnit<VolumetricFlowRate>(tec.uom.se.unit.Units.CUBIC_METRE.divide(tec.uom.se.unit.Units.HOUR)));
public static final Unit<VolumetricFlowRate> CUBICMETRE_PER_DAY = addUnit(
new ProductUnit<VolumetricFlowRate>(Units.CUBIC_METRE.divide(Units.DAY)));
new ProductUnit<VolumetricFlowRate>(tec.uom.se.unit.Units.CUBIC_METRE.divide(tec.uom.se.unit.Units.DAY)));
public static final Unit<DataAmount> BIT = addUnit(new AlternateUnit<>(ONE, "bit"));
public static final Unit<DataAmount> KILOBIT = addUnit(MetricPrefix.KILO(BIT));
public static final Unit<DataAmount> MEGABIT = addUnit(MetricPrefix.MEGA(BIT));
@ -203,7 +209,7 @@ public final class SmartHomeUnits extends CustomUnits {
public static final Unit<DataAmount> TEBIOCTET = addUnit(BinaryPrefix.TEBI(OCTET));
public static final Unit<DataAmount> PEBIOCTET = addUnit(BinaryPrefix.PEBI(OCTET));
public static final Unit<DataTransferRate> BIT_PER_SECOND = addUnit(
new ProductUnit<DataTransferRate>(BIT.divide(Units.SECOND)));
new ProductUnit<DataTransferRate>(BIT.divide(tec.uom.se.unit.Units.SECOND)));
public static final Unit<DataTransferRate> KILOBIT_PER_SECOND = addUnit(MetricPrefix.KILO(BIT_PER_SECOND));
public static final Unit<DataTransferRate> MEGABIT_PER_SECOND = addUnit(MetricPrefix.MEGA(BIT_PER_SECOND));
public static final Unit<DataTransferRate> GIGABIT_PER_SECOND = addUnit(MetricPrefix.GIGA(BIT_PER_SECOND));
@ -278,7 +284,7 @@ public final class SmartHomeUnits extends CustomUnits {
SimpleUnitFormat.getInstance().label(WATT_SECOND, "Ws");
}
private SmartHomeUnits() {
private Units() {
// avoid external instantiation
}

View File

@ -32,14 +32,13 @@ import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.internal.library.unit.UnitInitializer;
import org.openhab.core.library.unit.ImperialUnits;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tec.uom.se.quantity.Quantities;
import tec.uom.se.unit.MetricPrefix;
import tec.uom.se.unit.TransformedUnit;
import tec.uom.se.unit.Units;
/**
* A utility for parsing dimensions to interface classes of {@link Quantity} and parsing units from format strings.
@ -58,7 +57,7 @@ public class UnitUtils {
private static final String FRAMEWORK_DIMENSION_PREFIX = "org.openhab.core.library.dimension.";
private static final Collection<Class<? extends SystemOfUnits>> ALL_SYSTEM_OF_UNITS = Arrays.asList(SIUnits.class,
ImperialUnits.class, SmartHomeUnits.class, Units.class);
ImperialUnits.class, Units.class, tec.uom.se.unit.Units.class);
static {
UnitInitializer.init();
@ -155,7 +154,7 @@ public class UnitUtils {
if (!UNIT_PLACEHOLDER.equals(unitSymbol)) {
if (UNIT_PERCENT_FORMAT_STRING.equals(unitSymbol)) {
return SmartHomeUnits.PERCENT;
return Units.PERCENT;
}
try {
Quantity<?> quantity = Quantities.getQuantity("1 " + unitSymbol);

View File

@ -23,14 +23,14 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.types.util.UnitUtils;
import tec.uom.se.ComparableQuantity;
import tec.uom.se.quantity.Quantities;
/**
* Test for volumentric flow rate constants defined in {@link SmartHomeUnits}.
* Test for volumentric flow rate constants defined in {@link Units}.
*
* @author Łukasz Dywicki - Initial contribution
*/
@ -40,7 +40,7 @@ public class VolumetricFlowRateTest {
/**
* While its not SI base unit it produces nice and fairly rounded numbers (si base is m3/s).
*/
private static final Unit<VolumetricFlowRate> BASE_UNIT = SmartHomeUnits.CUBICMETRE_PER_HOUR;
private static final Unit<VolumetricFlowRate> BASE_UNIT = Units.CUBICMETRE_PER_HOUR;
/**
* An additional test which converts given test quantity into base unit and then compares it with expected value.
@ -72,10 +72,10 @@ public class VolumetricFlowRateTest {
}
private static Stream<Arguments> arguments() {
return Stream.of(Arguments.of(SmartHomeUnits.LITRE_PER_MINUTE, "l/min", 100.0, 6.0),
Arguments.of(SmartHomeUnits.CUBICMETRE_PER_SECOND, "m³/s", 100.0, 360000.0),
Arguments.of(SmartHomeUnits.CUBICMETRE_PER_MINUTE, "m³/min", 100.0, 6000.0),
Arguments.of(SmartHomeUnits.CUBICMETRE_PER_HOUR, "m³/h", 100.0, 100.0),
Arguments.of(SmartHomeUnits.CUBICMETRE_PER_DAY, "m³/d", 100.0, 4.166666666666667));
return Stream.of(Arguments.of(Units.LITRE_PER_MINUTE, "l/min", 100.0, 6.0),
Arguments.of(Units.CUBICMETRE_PER_SECOND, "m³/s", 100.0, 360000.0),
Arguments.of(Units.CUBICMETRE_PER_MINUTE, "m³/min", 100.0, 6000.0),
Arguments.of(Units.CUBICMETRE_PER_HOUR, "m³/h", 100.0, 100.0),
Arguments.of(Units.CUBICMETRE_PER_DAY, "m³/d", 100.0, 4.166666666666667));
}
}

View File

@ -15,7 +15,7 @@ package org.openhab.core.library.types;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
/**
* @author Kai Kreuzer - Initial contribution
@ -75,7 +75,7 @@ public class PercentTypeTest {
public void testConversionToQuantityType() {
assertEquals(new QuantityType<>("100 %"), PercentType.HUNDRED.as(QuantityType.class));
assertEquals(new QuantityType<>("1 one"),
((QuantityType<?>) PercentType.HUNDRED.as(QuantityType.class)).toUnit(SmartHomeUnits.ONE));
((QuantityType<?>) PercentType.HUNDRED.as(QuantityType.class)).toUnit(Units.ONE));
}
@Test

View File

@ -37,11 +37,10 @@ import org.openhab.core.library.dimension.Intensity;
import org.openhab.core.library.unit.BinaryPrefix;
import org.openhab.core.library.unit.MetricPrefix;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.types.util.UnitUtils;
import tec.uom.se.quantity.QuantityDimension;
import tec.uom.se.unit.Units;
/**
* @author Gaël L'hopital - Initial contribution
@ -125,9 +124,9 @@ public class QuantityTypeTest {
@Test
public void testFormats() {
QuantityType<Time> seconds = new QuantityType<>(80, SmartHomeUnits.SECOND);
QuantityType<Time> millis = seconds.toUnit(MetricPrefix.MILLI(SmartHomeUnits.SECOND));
QuantityType<Time> minutes = seconds.toUnit(SmartHomeUnits.MINUTE);
QuantityType<Time> seconds = new QuantityType<>(80, Units.SECOND);
QuantityType<Time> millis = seconds.toUnit(MetricPrefix.MILLI(Units.SECOND));
QuantityType<Time> minutes = seconds.toUnit(Units.MINUTE);
assertThat(seconds.format("%.1f " + UnitUtils.UNIT_PLACEHOLDER), is("80" + SEP + "0 s"));
assertThat(millis.format("%.1f " + UnitUtils.UNIT_PLACEHOLDER), is("80000" + SEP + "0 ms"));
@ -152,7 +151,7 @@ public class QuantityTypeTest {
assertTrue(dt2.equals(dt3));
QuantityType<?> tempInC = new QuantityType<>("22 °C");
QuantityType<?> tempInK = tempInC.toUnit(SmartHomeUnits.KELVIN);
QuantityType<?> tempInK = tempInC.toUnit(Units.KELVIN);
assertTrue(tempInC.equals(tempInK));
tempInK = tempInC.toUnit("K");
assertTrue(tempInC.equals(tempInK));
@ -284,12 +283,12 @@ public class QuantityTypeTest {
public void testIntensity() {
QuantityType<Intensity> density = new QuantityType<>("10 W/m²");
assertEquals(10, density.doubleValue(), 1E-5);
assertEquals(SmartHomeUnits.IRRADIANCE.toString(), density.getUnit().toString());
assertEquals(Units.IRRADIANCE.toString(), density.getUnit().toString());
density = density.toUnit("W/cm²");
assertEquals("0.001 W/cm²", density.toString());
density = new QuantityType<>(2, SmartHomeUnits.IRRADIANCE);
density = new QuantityType<>(2, Units.IRRADIANCE);
assertEquals(2, density.doubleValue(), 1E-5);
assertEquals("2 W/m²", density.toString());
@ -327,36 +326,35 @@ public class QuantityTypeTest {
@Test
public void testDataAmount() {
QuantityType<DataAmount> amount = new QuantityType<>("8 bit");
QuantityType<DataAmount> octet = amount.toUnit(SmartHomeUnits.BYTE);
QuantityType<DataAmount> octet = amount.toUnit(Units.BYTE);
assertEquals(1, octet.byteValue());
QuantityType<DataAmount> bytes = new QuantityType<>("1 B");
assertEquals("1 B", bytes.toString());
QuantityType<DataAmount> bits = bytes.toUnit(SmartHomeUnits.BIT);
QuantityType<DataAmount> bits = bytes.toUnit(Units.BIT);
assertEquals(8, bits.byteValue());
bytes = new QuantityType<>("1 MB");
assertEquals("1 MB", bytes.toString());
bytes = new QuantityType<DataAmount>(1, MetricPrefix.MEGA(SmartHomeUnits.BYTE));
bytes = new QuantityType<DataAmount>(1, MetricPrefix.MEGA(Units.BYTE));
assertEquals("1 MB", bytes.toString());
bytes = new QuantityType<>("1 GiB");
assertEquals("1 GiB", bytes.toString());
bytes = new QuantityType<DataAmount>(1, BinaryPrefix.GIBI(SmartHomeUnits.BYTE));
bytes = new QuantityType<DataAmount>(1, BinaryPrefix.GIBI(Units.BYTE));
assertEquals("1 GiB", bytes.toString());
QuantityType<DataAmount> bigAmount = new QuantityType<>("1 Kio");
QuantityType<DataAmount> octets = bigAmount.toUnit(SmartHomeUnits.OCTET);
QuantityType<DataAmount> octets = bigAmount.toUnit(Units.OCTET);
assertEquals(1024, octets.intValue());
QuantityType<DataAmount> hugeAmount = new QuantityType<>("1024Gio");
QuantityType<DataAmount> lotOfOctets = hugeAmount.toUnit(SmartHomeUnits.OCTET);
QuantityType<DataAmount> lotOfOctets = hugeAmount.toUnit(Units.OCTET);
assertEquals("1099511627776 o", lotOfOctets.format("%d o"));
}
@Test
public void testDataTransferRate() {
QuantityType<DataTransferRate> speed = new QuantityType<>("1024 bit/s");
QuantityType<DataTransferRate> octet = speed.toUnit(SmartHomeUnits.OCTET.divide(Units.SECOND));
QuantityType<DataTransferRate> octet = speed.toUnit(Units.OCTET.divide(Units.SECOND));
assertEquals(128, octet.intValue());
QuantityType<DataTransferRate> gsm2G = new QuantityType<>("115 Mbit/s");
QuantityType<DataTransferRate> octets = gsm2G
.toUnit(MetricPrefix.KILO(SmartHomeUnits.OCTET).divide(Units.SECOND));
QuantityType<DataTransferRate> octets = gsm2G.toUnit(MetricPrefix.KILO(Units.OCTET).divide(Units.SECOND));
assertEquals(14375, octets.intValue());
}
}

View File

@ -35,14 +35,13 @@ import org.openhab.core.library.dimension.Intensity;
import org.openhab.core.library.types.QuantityType;
import tec.uom.se.quantity.Quantities;
import tec.uom.se.unit.Units;
/**
* Test for the framework defined {@link SmartHomeUnits}.
* Test for the framework defined {@link Units}.
*
* @author Henning Treu - Initial contribution
*/
public class SmartHomeUnitsTest {
public class UnitsTest {
private static final double DEFAULT_ERROR = 0.0000000000000001d;
@ -71,7 +70,7 @@ public class SmartHomeUnitsTest {
@Test
public void testmmHg2PascalConversion() {
Quantity<Pressure> mmHg = Quantities.getQuantity(BigDecimal.ONE, SmartHomeUnits.MILLIMETRE_OF_MERCURY);
Quantity<Pressure> mmHg = Quantities.getQuantity(BigDecimal.ONE, Units.MILLIMETRE_OF_MERCURY);
assertThat(mmHg.to(SIUnits.PASCAL), is(Quantities.getQuantity(new BigDecimal("133.322368"), SIUnits.PASCAL)));
assertThat(mmHg.to(MetricPrefix.HECTO(SIUnits.PASCAL)),
@ -80,16 +79,16 @@ public class SmartHomeUnitsTest {
@Test
public void testMmHgUnitSymbol() {
assertThat(SmartHomeUnits.MILLIMETRE_OF_MERCURY.getSymbol(), is("mmHg"));
assertThat(SmartHomeUnits.MILLIMETRE_OF_MERCURY.toString(), is("mmHg"));
assertThat(Units.MILLIMETRE_OF_MERCURY.getSymbol(), is("mmHg"));
assertThat(Units.MILLIMETRE_OF_MERCURY.toString(), is("mmHg"));
}
@Test
public void testPascal2mmHgConversion() {
Quantity<Pressure> pascal = Quantities.getQuantity(new BigDecimal("133.322368"), SIUnits.PASCAL);
assertThat(pascal.to(SmartHomeUnits.MILLIMETRE_OF_MERCURY),
is(Quantities.getQuantity(BigDecimal.ONE, SmartHomeUnits.MILLIMETRE_OF_MERCURY)));
assertThat(pascal.to(Units.MILLIMETRE_OF_MERCURY),
is(Quantities.getQuantity(BigDecimal.ONE, Units.MILLIMETRE_OF_MERCURY)));
}
@Test
@ -107,7 +106,7 @@ public class SmartHomeUnitsTest {
@Test
public void testKelvin2Fahrenheit() {
Quantity<Temperature> kelvin = Quantities.getQuantity(BigDecimal.ZERO, SmartHomeUnits.KELVIN);
Quantity<Temperature> kelvin = Quantities.getQuantity(BigDecimal.ZERO, Units.KELVIN);
assertThat(kelvin.to(ImperialUnits.FAHRENHEIT),
is(Quantities.getQuantity(new BigDecimal("-459.67"), ImperialUnits.FAHRENHEIT)));
@ -115,7 +114,7 @@ public class SmartHomeUnitsTest {
@Test
public void testKelvin2Fahrenheit2() {
Quantity<Temperature> kelvin = Quantities.getQuantity(new BigDecimal("300"), SmartHomeUnits.KELVIN);
Quantity<Temperature> kelvin = Quantities.getQuantity(new BigDecimal("300"), Units.KELVIN);
assertThat(kelvin.to(ImperialUnits.FAHRENHEIT),
is(Quantities.getQuantity(new BigDecimal("80.33"), ImperialUnits.FAHRENHEIT)));
@ -125,8 +124,8 @@ public class SmartHomeUnitsTest {
public void testFahrenheit2Kelvin() {
Quantity<Temperature> fahrenheit = Quantities.getQuantity(new BigDecimal("100"), ImperialUnits.FAHRENHEIT);
Quantity<Temperature> kelvin = fahrenheit.to(SmartHomeUnits.KELVIN);
assertThat(kelvin.getUnit(), is(SmartHomeUnits.KELVIN));
Quantity<Temperature> kelvin = fahrenheit.to(Units.KELVIN);
assertThat(kelvin.getUnit(), is(Units.KELVIN));
assertThat(kelvin.getValue().doubleValue(), is(closeTo(310.92777777777777778d, DEFAULT_ERROR)));
}
@ -152,14 +151,14 @@ public class SmartHomeUnitsTest {
public void testKmh2Knot() {
Quantity<Speed> kmh = Quantities.getQuantity(new BigDecimal("1.852"), SIUnits.KILOMETRE_PER_HOUR);
Quantity<Speed> knot = kmh.to(SmartHomeUnits.KNOT);
assertThat(knot.getUnit(), is(SmartHomeUnits.KNOT));
Quantity<Speed> knot = kmh.to(Units.KNOT);
assertThat(knot.getUnit(), is(Units.KNOT));
assertThat(knot.getValue().doubleValue(), is(closeTo(1.000, DEFAULT_ERROR)));
}
@Test
public void testKnot2Kmh() {
Quantity<Speed> knot = Quantities.getQuantity(BigDecimal.TEN, SmartHomeUnits.KNOT);
Quantity<Speed> knot = Quantities.getQuantity(BigDecimal.TEN, Units.KNOT);
Quantity<Speed> kmh = knot.to(SIUnits.KILOMETRE_PER_HOUR);
assertThat(kmh.getUnit(), is(SIUnits.KILOMETRE_PER_HOUR));
@ -168,26 +167,26 @@ public class SmartHomeUnitsTest {
@Test
public void testKnotUnitSymbol() {
assertThat(SmartHomeUnits.KNOT.getSymbol(), is("kn"));
assertThat(SmartHomeUnits.KNOT.toString(), is("kn"));
assertThat(Units.KNOT.getSymbol(), is("kn"));
assertThat(Units.KNOT.toString(), is("kn"));
}
@Test
public void testVarUnitSymbol() {
assertThat(SmartHomeUnits.VAR.getSymbol(), is("var"));
assertThat(SmartHomeUnits.VAR.toString(), is("var"));
assertThat(SmartHomeUnits.VAR_HOUR.toString(), is("varh"));
assertThat(Units.VAR.getSymbol(), is("var"));
assertThat(Units.VAR.toString(), is("var"));
assertThat(Units.VAR_HOUR.toString(), is("varh"));
}
@Test
public void testKVarUnitSymbol() {
assertThat(SmartHomeUnits.KILOVAR.toString(), is("kvar"));
assertThat(SmartHomeUnits.KILOVAR_HOUR.toString(), is("kvarh"));
assertThat(Units.KILOVAR.toString(), is("kvar"));
assertThat(Units.KILOVAR_HOUR.toString(), is("kvarh"));
Quantity<Power> kvar = Quantities.getQuantity(BigDecimal.TEN, MetricPrefix.KILO(SmartHomeUnits.VAR));
Quantity<Power> kvar = Quantities.getQuantity(BigDecimal.TEN, MetricPrefix.KILO(Units.VAR));
assertThat(kvar.getUnit().toString(), is("kvar"));
Quantity<Energy> kvarh = Quantities.getQuantity(BigDecimal.TEN, MetricPrefix.KILO(SmartHomeUnits.VAR_HOUR));
Quantity<Energy> kvarh = Quantities.getQuantity(BigDecimal.TEN, MetricPrefix.KILO(Units.VAR_HOUR));
assertThat(kvarh.getUnit().toString(), is("kvarh"));
}
@ -198,15 +197,14 @@ public class SmartHomeUnitsTest {
@Test
public void testVoltAmpereUnitSymbol() {
assertThat(SmartHomeUnits.VOLT_AMPERE.toString(), is("VA"));
assertThat(SmartHomeUnits.VOLT_AMPERE.getSymbol(), is("VA"));
assertThat(SmartHomeUnits.VOLT_AMPERE_HOUR.toString(), is("VAh"));
assertThat(Units.VOLT_AMPERE.toString(), is("VA"));
assertThat(Units.VOLT_AMPERE.getSymbol(), is("VA"));
assertThat(Units.VOLT_AMPERE_HOUR.toString(), is("VAh"));
Quantity<Power> kVA = Quantities.getQuantity(BigDecimal.TEN, MetricPrefix.KILO(SmartHomeUnits.VOLT_AMPERE));
Quantity<Power> kVA = Quantities.getQuantity(BigDecimal.TEN, MetricPrefix.KILO(Units.VOLT_AMPERE));
assertThat(kVA.getUnit().toString(), is("kVA"));
Quantity<Energy> kVAh = Quantities.getQuantity(BigDecimal.TEN,
MetricPrefix.KILO(SmartHomeUnits.VOLT_AMPERE_HOUR));
Quantity<Energy> kVAh = Quantities.getQuantity(BigDecimal.TEN, MetricPrefix.KILO(Units.VOLT_AMPERE_HOUR));
assertThat(kVAh.getUnit().toString(), is("kVAh"));
}
@ -271,10 +269,10 @@ public class SmartHomeUnitsTest {
@Test
public void testOneUnitSymbol() {
assertThat(SmartHomeUnits.ONE.getSymbol(), is(""));
assertThat(Units.ONE.getSymbol(), is(""));
Quantity<Dimensionless> one1 = Quantities.getQuantity(BigDecimal.ONE, SmartHomeUnits.ONE);
Quantity<Dimensionless> one2 = Quantities.getQuantity(BigDecimal.ONE, SmartHomeUnits.ONE);
Quantity<Dimensionless> one1 = Quantities.getQuantity(BigDecimal.ONE, Units.ONE);
Quantity<Dimensionless> one2 = Quantities.getQuantity(BigDecimal.ONE, Units.ONE);
assertThat(one1.add(one2).toString(), is("2 one"));
}
@ -295,27 +293,28 @@ public class SmartHomeUnitsTest {
public void testDobsonUnits() {
// https://en.wikipedia.org/wiki/Dobson_unit
QuantityType<ArealDensity> oneDU = new QuantityType<>("1 DU");
QuantityType<ArealDensity> mmolpsq = oneDU.toUnit(MetricPrefix.MILLI(Units.MOLE).multiply(Units.METRE.pow(-2)));
QuantityType<ArealDensity> mmolpsq = oneDU
.toUnit(MetricPrefix.MILLI(Units.MOLE).multiply(tec.uom.se.unit.Units.METRE.pow(-2)));
assertThat(mmolpsq.doubleValue(), is(closeTo(0.4462d, DEFAULT_ERROR)));
assertThat(mmolpsq.toUnit(SmartHomeUnits.DOBSON_UNIT).doubleValue(), is(closeTo(1, DEFAULT_ERROR)));
assertThat(mmolpsq.toUnit(Units.DOBSON_UNIT).doubleValue(), is(closeTo(1, DEFAULT_ERROR)));
}
@Test
public void testBar2Pascal() {
Quantity<Pressure> bar = Quantities.getQuantity(BigDecimal.valueOf(1), SmartHomeUnits.BAR);
Quantity<Pressure> bar = Quantities.getQuantity(BigDecimal.valueOf(1), Units.BAR);
assertThat(bar.to(SIUnits.PASCAL), is(Quantities.getQuantity(100000, SIUnits.PASCAL)));
}
@Test
public void testMicrogramPerCubicMeter2KilogramPerCubicMeter() {
Quantity<Density> oneKgM3 = Quantities.getQuantity(BigDecimal.ONE, SmartHomeUnits.KILOGRAM_PER_CUBICMETRE);
Quantity<Density> converted = oneKgM3.to(SmartHomeUnits.MICROGRAM_PER_CUBICMETRE);
Quantity<Density> oneKgM3 = Quantities.getQuantity(BigDecimal.ONE, Units.KILOGRAM_PER_CUBICMETRE);
Quantity<Density> converted = oneKgM3.to(Units.MICROGRAM_PER_CUBICMETRE);
assertThat(converted.getValue().doubleValue(), is(closeTo(1000000000, DEFAULT_ERROR)));
}
@Test
public void testMicrogramPerCubicMeterUnitSymbol() {
assertThat(SmartHomeUnits.MICROGRAM_PER_CUBICMETRE.toString(), is("µg/m³"));
assertThat(Units.MICROGRAM_PER_CUBICMETRE.toString(), is("µg/m³"));
}
@Test
@ -325,14 +324,14 @@ public class SmartHomeUnitsTest {
@Test
public void testMicrowattPerSquareCentimetre2KilogramPerSquareCentiMetre() {
Quantity<Intensity> oneMwCm2 = Quantities.getQuantity(BigDecimal.ONE, SmartHomeUnits.IRRADIANCE);
Quantity<Intensity> converted = oneMwCm2.to(SmartHomeUnits.MICROWATT_PER_SQUARE_CENTIMETRE);
Quantity<Intensity> oneMwCm2 = Quantities.getQuantity(BigDecimal.ONE, Units.IRRADIANCE);
Quantity<Intensity> converted = oneMwCm2.to(Units.MICROWATT_PER_SQUARE_CENTIMETRE);
assertThat(converted.getValue().doubleValue(), is(100d));
}
@Test
public void testMicrowattPerSquareCentimetreUnitSymbol() {
assertThat(SmartHomeUnits.MICROWATT_PER_SQUARE_CENTIMETRE.toString(), is("µW/cm²"));
assertThat(Units.MICROWATT_PER_SQUARE_CENTIMETRE.toString(), is("µW/cm²"));
}
@Test
@ -343,8 +342,8 @@ public class SmartHomeUnitsTest {
@Test
public void testElectricCharge() {
QuantityType<?> oneAh = QuantityType.valueOf("3600 C");
QuantityType<?> converted = oneAh.toUnit(SmartHomeUnits.AMPERE_HOUR);
QuantityType<?> converted2 = oneAh.toUnit(SmartHomeUnits.MILLIAMPERE_HOUR);
QuantityType<?> converted = oneAh.toUnit(Units.AMPERE_HOUR);
QuantityType<?> converted2 = oneAh.toUnit(Units.MILLIAMPERE_HOUR);
assertThat(converted.doubleValue(), is(closeTo(1.00, DEFAULT_ERROR)));
assertEquals("1000 mAh", converted2.toString());
}

View File

@ -32,7 +32,7 @@ import org.openhab.core.library.dimension.Intensity;
import org.openhab.core.library.unit.ImperialUnits;
import org.openhab.core.library.unit.MetricPrefix;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
/**
* @author Henning Treu - Initial contribution
@ -72,12 +72,9 @@ public class UnitUtilsTest {
@Test
public void testConversionOfUnit() {
assertThat(SmartHomeUnits.DECIBEL_MILLIWATTS.getConverterTo(SmartHomeUnits.WATT).convert(50),
closeTo(100, 0.001));
assertThat(SmartHomeUnits.WATT.getConverterTo(SmartHomeUnits.DECIBEL_MILLIWATTS).convert(0.1),
closeTo(20, 0.0001));
assertThat(
SmartHomeUnits.METRE_PER_SQUARE_SECOND.getConverterTo(SmartHomeUnits.STANDARD_GRAVITY).convert(9.8065),
assertThat(Units.DECIBEL_MILLIWATTS.getConverterTo(Units.WATT).convert(50), closeTo(100, 0.001));
assertThat(Units.WATT.getConverterTo(Units.DECIBEL_MILLIWATTS).convert(0.1), closeTo(20, 0.0001));
assertThat(Units.METRE_PER_SQUARE_SECOND.getConverterTo(Units.STANDARD_GRAVITY).convert(9.8065),
closeTo(1.0, 0.0001));
}
@ -86,25 +83,25 @@ public class UnitUtilsTest {
assertThat(UnitUtils.parseUnit("%.2f °F"), is(ImperialUnits.FAHRENHEIT));
assertThat(UnitUtils.parseUnit("%.2f °C"), is(SIUnits.CELSIUS));
assertThat(UnitUtils.parseUnit("myLabel km"), is(KILO(SIUnits.METRE)));
assertThat(UnitUtils.parseUnit("%.2f %%"), is(SmartHomeUnits.PERCENT));
assertThat(UnitUtils.parseUnit("%.2f %%"), is(Units.PERCENT));
assertThat(UnitUtils.parseUnit("myLabel %unit%"), is(nullValue()));
assertThat(UnitUtils.parseUnit("%.2f kvarh"), is(SmartHomeUnits.KILOVAR_HOUR));
assertThat(UnitUtils.parseUnit("%.2f kvarh"), is(Units.KILOVAR_HOUR));
}
@Test
public void testParsePureUnit() {
assertThat(UnitUtils.parseUnit("DU"), is(SmartHomeUnits.DOBSON_UNIT));
assertThat(UnitUtils.parseUnit("DU"), is(Units.DOBSON_UNIT));
assertThat(UnitUtils.parseUnit("°F"), is(ImperialUnits.FAHRENHEIT));
assertThat(UnitUtils.parseUnit("m"), is(SIUnits.METRE));
assertThat(UnitUtils.parseUnit("%"), is(SmartHomeUnits.PERCENT));
assertThat(UnitUtils.parseUnit("%"), is(Units.PERCENT));
}
@Test
public void testGetDimensionName() {
assertThat(UnitUtils.getDimensionName(SIUnits.CELSIUS), is(Temperature.class.getSimpleName()));
assertThat(UnitUtils.getDimensionName(SmartHomeUnits.KILOWATT_HOUR), is(Energy.class.getSimpleName()));
assertThat(UnitUtils.getDimensionName(SmartHomeUnits.WATT), is(Power.class.getSimpleName()));
assertThat(UnitUtils.getDimensionName(MetricPrefix.MEGA(SmartHomeUnits.KILOWATT_HOUR)),
assertThat(UnitUtils.getDimensionName(Units.KILOWATT_HOUR), is(Energy.class.getSimpleName()));
assertThat(UnitUtils.getDimensionName(Units.WATT), is(Power.class.getSimpleName()));
assertThat(UnitUtils.getDimensionName(MetricPrefix.MEGA(Units.KILOWATT_HOUR)),
is(Energy.class.getSimpleName()));
Unit<?> unit = UnitUtils.parseUnit("°F");

View File

@ -38,7 +38,7 @@ import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.MetricPrefix;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.model.script.ScriptServiceUtil;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.types.State;
@ -299,9 +299,9 @@ public class ScriptEngineOSGiTest extends JavaOSGiTest {
@Test
public void testToUnitQuantityType3() throws ScriptParsingException, ScriptExecutionException {
assertThat(runScript("new QuantityType(1, KELVIN)"), is(new QuantityType<>(1, SmartHomeUnits.KELVIN)));
assertThat(runScript("new QuantityType(1, KELVIN)"), is(new QuantityType<>(1, Units.KELVIN)));
assertThat(runScript("new QuantityType(1, MICRO(KELVIN))"),
is(new QuantityType<>(1, MetricPrefix.MICRO(SmartHomeUnits.KELVIN))));
is(new QuantityType<>(1, MetricPrefix.MICRO(Units.KELVIN))));
}
@Test

View File

@ -25,7 +25,7 @@ import javax.measure.quantity.Temperature;
import org.junit.jupiter.api.Test;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.library.unit.Units;
import org.openhab.core.types.Type;
/**
@ -43,8 +43,8 @@ public class NumberExtensionsTest {
private static final QuantityType<Length> Q_LENGTH_1_M = new QuantityType<>("1 m");
private static final QuantityType<Length> Q_LENGTH_2_CM = new QuantityType<>("2 cm");
private static final QuantityType<Dimensionless> Q_ONE_1 = new QuantityType<>(1, SmartHomeUnits.ONE);
private static final QuantityType<Dimensionless> Q_ONE_2 = new QuantityType<>(2, SmartHomeUnits.ONE);
private static final QuantityType<Dimensionless> Q_ONE_1 = new QuantityType<>(1, Units.ONE);
private static final QuantityType<Dimensionless> Q_ONE_2 = new QuantityType<>(2, Units.ONE);
@Test
public void operatorPlusNumberNumber() {