Search in sources :

Example 6 with Temperature

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

the class QuantityTypeArithmeticGroupFunctionTest method testMinFunctionQuantityTypeDifferentUnits.

@Test
public void testMinFunctionQuantityTypeDifferentUnits() {
    items.add(createNumberItem("TestItem1", Temperature.class, new QuantityType<Temperature>("100 °C")));
    items.add(createNumberItem("TestItem2", Temperature.class, UnDefType.NULL));
    items.add(createNumberItem("TestItem3", Temperature.class, new QuantityType<Temperature>("113 °F")));
    items.add(createNumberItem("TestItem4", Temperature.class, UnDefType.UNDEF));
    items.add(createNumberItem("TestItem5", Temperature.class, new QuantityType<Temperature>("294.15 K")));
    function = new QuantityTypeArithmeticGroupFunction.Min(Temperature.class);
    State state = function.calculate(items);
    assertEquals(new QuantityType<Temperature>("294.15 K"), state);
}
Also used : Temperature(javax.measure.quantity.Temperature) State(org.eclipse.smarthome.core.types.State) Test(org.junit.Test)

Example 7 with Temperature

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

the class QuantityTypeArithmeticGroupFunctionTest method testAvgFunctionQuantityType.

@Test
public void testAvgFunctionQuantityType() {
    items.add(createNumberItem("TestItem1", Temperature.class, new QuantityType<Temperature>("100 °C")));
    items.add(createNumberItem("TestItem2", Temperature.class, UnDefType.NULL));
    items.add(createNumberItem("TestItem3", Temperature.class, new QuantityType<Temperature>("200 °C")));
    items.add(createNumberItem("TestItem4", Temperature.class, UnDefType.UNDEF));
    items.add(createNumberItem("TestItem5", Temperature.class, new QuantityType<Temperature>("300 °C")));
    function = new QuantityTypeArithmeticGroupFunction.Avg(Temperature.class);
    State state = function.calculate(items);
    assertEquals(new QuantityType<Temperature>("200 °C"), state);
}
Also used : Temperature(javax.measure.quantity.Temperature) State(org.eclipse.smarthome.core.types.State) Test(org.junit.Test)

Example 8 with Temperature

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

the class CoreItemFactoryTest method createNumberItemWithDimension.

@Test
public void createNumberItemWithDimension() {
    NumberItem numberItem = (NumberItem) coreItemFactory.createItem(CoreItemFactory.NUMBER + ":Temperature", "myNumberItem");
    assertThat(numberItem.getDimension(), equalTo(Temperature.class));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Temperature(javax.measure.quantity.Temperature) Test(org.junit.Test)

Example 9 with Temperature

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

the class GroupItemTest method assertThatNumberGroupItemWithDimensionCalculatesCorrectState.

@SuppressWarnings("null")
@Test
public void assertThatNumberGroupItemWithDimensionCalculatesCorrectState() {
    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);
    NumberItem celsius = createNumberItem("C", Temperature.class, new QuantityType<Temperature>("23 °C"));
    groupItem.addMember(celsius);
    NumberItem fahrenheit = createNumberItem("F", Temperature.class, new QuantityType<Temperature>("23 °F"));
    groupItem.addMember(fahrenheit);
    NumberItem kelvin = createNumberItem("K", Temperature.class, new QuantityType<Temperature>("23 K"));
    groupItem.addMember(kelvin);
    QuantityType<?> state = (QuantityType<?>) groupItem.getStateAs(QuantityType.class);
    assertThat(state.getUnit(), is(Units.CELSIUS));
    assertThat(state.doubleValue(), is(-232.15d));
    celsius.setState(new QuantityType<Temperature>("265 °C"));
    state = (QuantityType<?>) groupItem.getStateAs(QuantityType.class);
    assertThat(state.getUnit(), is(Units.CELSIUS));
    assertThat(state.doubleValue(), is(9.85d));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) ArithmeticGroupFunction(org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction) Temperature(javax.measure.quantity.Temperature) QuantityType(org.eclipse.smarthome.core.library.types.QuantityType) GroupFunctionDTO(org.eclipse.smarthome.core.items.dto.GroupFunctionDTO) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 10 with Temperature

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

the class SmartHomeUnitsTest method testFahrenheit2Kelvin.

@Test
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));
    assertThat(kelvin.getValue().doubleValue(), is(closeTo(310.92777777777777778d, DEFAULT_ERROR)));
}
Also used : Temperature(javax.measure.quantity.Temperature) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

Temperature (javax.measure.quantity.Temperature)19 Test (org.junit.Test)18 State (org.eclipse.smarthome.core.types.State)13 Pressure (javax.measure.quantity.Pressure)5 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)4 BigDecimal (java.math.BigDecimal)3 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)3 GroupFunctionDTO (org.eclipse.smarthome.core.items.dto.GroupFunctionDTO)2 ArithmeticGroupFunction (org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction)2 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)2 LinkedList (java.util.LinkedList)1 Dimensionless (javax.measure.quantity.Dimensionless)1 Item (org.eclipse.smarthome.core.items.Item)1 DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)1 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)1 HSBType (org.eclipse.smarthome.core.library.types.HSBType)1 PercentType (org.eclipse.smarthome.core.library.types.PercentType)1 PointType (org.eclipse.smarthome.core.library.types.PointType)1 RawType (org.eclipse.smarthome.core.library.types.RawType)1 StringListType (org.eclipse.smarthome.core.library.types.StringListType)1