Skip to content

Commit

Permalink
Added standard gravity and dBm units.
Browse files Browse the repository at this point in the history
Signed-off-by: Hilbrand Bouwkamp <[email protected]>
  • Loading branch information
Hilbrand authored and maggu2810 committed Mar 1, 2019
1 parent 21bf4d9 commit 4517f39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
import tec.uom.se.AbstractSystemOfUnits;
import tec.uom.se.AbstractUnit;
import tec.uom.se.format.SimpleUnitFormat;
import tec.uom.se.function.ExpConverter;
import tec.uom.se.function.LogConverter;
import tec.uom.se.function.MultiplyConverter;
import tec.uom.se.function.PiMultiplierConverter;
import tec.uom.se.function.RationalConverter;
import tec.uom.se.unit.AlternateUnit;
Expand All @@ -79,6 +81,8 @@ public final class SmartHomeUnits extends AbstractSystemOfUnits {

// Alphabetical ordered by Unit.
public static final Unit<Acceleration> METRE_PER_SQUARE_SECOND = addUnit(Units.METRE_PER_SQUARE_SECOND);
public static final Unit<Acceleration> STANDARD_GRAVITY = new TransformedUnit<>("gₙ",
SmartHomeUnits.METRE_PER_SQUARE_SECOND, new MultiplyConverter(9.80665));
public static final Unit<AmountOfSubstance> MOLE = addUnit(Units.MOLE);
public static final Unit<AmountOfSubstance> DEUTSCHE_HAERTE = addUnit(new TransformedUnit<AmountOfSubstance>("°dH",
(Unit<AmountOfSubstance>) MetricPrefix.MILLI(Units.MOLE).divide(Units.LITRE),
Expand Down Expand Up @@ -123,6 +127,8 @@ public final class SmartHomeUnits extends AbstractSystemOfUnits {
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<Power> DECIBEL_MILLIWATTS = new TransformedUnit<>("dBm",
MetricPrefix.MILLI(SmartHomeUnits.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,
Expand Down Expand Up @@ -169,6 +175,7 @@ public final class SmartHomeUnits extends AbstractSystemOfUnits {
SimpleUnitFormat.getInstance().label(CUBICMETRE_PER_MINUTE, "m³/min");
SimpleUnitFormat.getInstance().label(CUBICMETRE_PER_SECOND, "m³/s");
SimpleUnitFormat.getInstance().label(DECIBEL, "dB");
SimpleUnitFormat.getInstance().label(DECIBEL_MILLIWATTS, "dBm");
SimpleUnitFormat.getInstance().label(DEGREE_ANGLE, "°");
SimpleUnitFormat.getInstance().label(DEUTSCHE_HAERTE, "°dH");
SimpleUnitFormat.getInstance().label(DOBSON_UNIT, "DU");
Expand All @@ -182,6 +189,7 @@ public final class SmartHomeUnits extends AbstractSystemOfUnits {
SimpleUnitFormat.getInstance().label(MILLIBAR, "mbar");
SimpleUnitFormat.getInstance().label(MILLIMETRE_OF_MERCURY, MILLIMETRE_OF_MERCURY.getSymbol());
SimpleUnitFormat.getInstance().label(PARTS_PER_MILLION, "ppm");
SimpleUnitFormat.getInstance().label(STANDARD_GRAVITY, "gₙ");
SimpleUnitFormat.getInstance().label(WATT_HOUR, "Wh");
SimpleUnitFormat.getInstance().label(WATT_SECOND, "Ws");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import static org.eclipse.smarthome.core.library.unit.MetricPrefix.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.number.IsCloseTo.closeTo;
import static org.junit.Assert.*;

import javax.measure.Quantity;
Expand Down Expand Up @@ -62,6 +63,12 @@ public void whenValidDimensionIsGiven_shouldCreateQuantityClass() {
assertTrue(Intensity.class.isAssignableFrom(intensity));
}

@Test
public void testConversionOfUnit() {
assertThat(SmartHomeUnits.DECIBEL_MILLIWATTS.getConverterTo(SmartHomeUnits.WATT).convert(50), closeTo(100, 3));
assertThat(SmartHomeUnits.WATT.getConverterTo(SmartHomeUnits.DECIBEL_MILLIWATTS).convert(0.1), closeTo(20, 3));
}

@Test
public void shouldParseUnitFromPattern() {
assertThat(UnitUtils.parseUnit("%.2f °F"), is(ImperialUnits.FAHRENHEIT));
Expand Down

0 comments on commit 4517f39

Please sign in to comment.