Search in sources :

Example 1 with Dimensionless

use of javax.measure.quantity.Dimensionless 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)

Aggregations

Dimensionless (javax.measure.quantity.Dimensionless)1 Pressure (javax.measure.quantity.Pressure)1 Temperature (javax.measure.quantity.Temperature)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 Test (org.junit.Test)1