Search in sources :

Example 1 with Pressure

use of javax.measure.quantity.Pressure in project smarthome by eclipse.

the class GroupItemTest method assertThatNumberGroupItemWithDifferentDimensionsCalculatesCorrectState.

@Test
public void assertThatNumberGroupItemWithDifferentDimensionsCalculatesCorrectState() {
    NumberItem baseItem = createNumberItem("baseItem", Temperature.class, UnDefType.NULL);
    GroupFunctionDTO gfDTO = new GroupFunctionDTO();
    gfDTO.name = "sum";
    GroupFunction function = groupFunctionHelper.createGroupFunction(gfDTO, Collections.emptyList(), Temperature.class);
    GroupItem groupItem = new GroupItem("number", baseItem, function);
    groupItem.setUnitProvider(unitProvider);
    groupItem.setItemStateConverter(itemStateConverter);
    NumberItem celsius = createNumberItem("C", Temperature.class, new QuantityType<Temperature>("23 °C"));
    groupItem.addMember(celsius);
    NumberItem hectoPascal = createNumberItem("F", Pressure.class, new QuantityType<Pressure>("1010 hPa"));
    groupItem.addMember(hectoPascal);
    NumberItem percent = createNumberItem("K", Dimensionless.class, new QuantityType<Dimensionless>("110 %"));
    groupItem.addMember(percent);
    QuantityType<?> state = (QuantityType<?>) groupItem.getStateAs(QuantityType.class);
    assertThat(state, is(new QuantityType<Temperature>("23 °C")));
    groupItem.stateUpdated(celsius, UnDefType.NULL);
    assertThat(groupItem.getState(), is(new QuantityType<Temperature>("23 °C")));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) ArithmeticGroupFunction(org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction) Temperature(javax.measure.quantity.Temperature) Dimensionless(javax.measure.quantity.Dimensionless) QuantityType(org.eclipse.smarthome.core.library.types.QuantityType) GroupFunctionDTO(org.eclipse.smarthome.core.items.dto.GroupFunctionDTO) Pressure(javax.measure.quantity.Pressure) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 2 with Pressure

use of javax.measure.quantity.Pressure in project smarthome by eclipse.

the class SmartHomeUnitsTest method testinHg2PascalConversion.

@Test
public void testinHg2PascalConversion() {
    Quantity<Pressure> inHg = Quantities.getQuantity(BigDecimal.ONE, ImperialUnits.INCH_OF_MERCURY);
    assertThat(inHg.to(SIUnits.PASCAL), is(Quantities.getQuantity(new BigDecimal("3386.388"), SIUnits.PASCAL)));
    assertThat(inHg.to(HECTO(SIUnits.PASCAL)), is(Quantities.getQuantity(new BigDecimal("33.86388"), HECTO(SIUnits.PASCAL))));
}
Also used : Pressure(javax.measure.quantity.Pressure) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with Pressure

use of javax.measure.quantity.Pressure in project smarthome by eclipse.

the class SmartHomeUnitsTest method testPascal2inHgConversion.

@Test
public void testPascal2inHgConversion() {
    Quantity<Pressure> pascal = Quantities.getQuantity(new BigDecimal("3386.388"), SIUnits.PASCAL);
    assertThat(pascal.to(ImperialUnits.INCH_OF_MERCURY), is(Quantities.getQuantity(new BigDecimal("1.000"), ImperialUnits.INCH_OF_MERCURY)));
}
Also used : Pressure(javax.measure.quantity.Pressure) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with Pressure

use of javax.measure.quantity.Pressure in project smarthome by eclipse.

the class QuantityTypeArithmeticGroupFunctionTest method testMaxFunctionQuantityTypeIncompatibleUnits.

@Test
public void testMaxFunctionQuantityTypeIncompatibleUnits() {
    items.add(createNumberItem("TestItem1", Temperature.class, new QuantityType<Temperature>("23.54 °C")));
    items.add(createNumberItem("TestItem2", Temperature.class, UnDefType.NULL));
    items.add(createNumberItem("TestItem3", Pressure.class, new QuantityType<Pressure>("192.2 hPa")));
    function = new QuantityTypeArithmeticGroupFunction.Max(Temperature.class);
    State state = function.calculate(items);
    assertEquals(new QuantityType<Temperature>("23.54 °C"), state);
}
Also used : Temperature(javax.measure.quantity.Temperature) State(org.eclipse.smarthome.core.types.State) Pressure(javax.measure.quantity.Pressure) Test(org.junit.Test)

Example 5 with Pressure

use of javax.measure.quantity.Pressure in project smarthome by eclipse.

the class QuantityTypeArithmeticGroupFunctionTest method testMinFunctionQuantityTypeIncompatibleUnits.

@Test
public void testMinFunctionQuantityTypeIncompatibleUnits() {
    items.add(createNumberItem("TestItem1", Temperature.class, new QuantityType<Temperature>("23.54 °C")));
    items.add(createNumberItem("TestItem2", Temperature.class, UnDefType.NULL));
    items.add(createNumberItem("TestItem3", Pressure.class, new QuantityType<Pressure>("192.2 hPa")));
    function = new QuantityTypeArithmeticGroupFunction.Min(Temperature.class);
    State state = function.calculate(items);
    assertEquals(new QuantityType<Temperature>("23.54 °C"), state);
}
Also used : Temperature(javax.measure.quantity.Temperature) State(org.eclipse.smarthome.core.types.State) Pressure(javax.measure.quantity.Pressure) Test(org.junit.Test)

Aggregations

Pressure (javax.measure.quantity.Pressure)5 Test (org.junit.Test)5 Temperature (javax.measure.quantity.Temperature)3 BigDecimal (java.math.BigDecimal)2 State (org.eclipse.smarthome.core.types.State)2 Dimensionless (javax.measure.quantity.Dimensionless)1 GroupFunctionDTO (org.eclipse.smarthome.core.items.dto.GroupFunctionDTO)1 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)1 ArithmeticGroupFunction (org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction)1 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)1 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)1