Search in sources :

Example 1 with GroupFunctionDTO

use of org.eclipse.smarthome.core.items.dto.GroupFunctionDTO 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 GroupFunctionDTO

use of org.eclipse.smarthome.core.items.dto.GroupFunctionDTO in project smarthome by eclipse.

the class ManagedItemProvider method getGroupFunction.

private GroupFunction getGroupFunction(PersistedItem persistedItem, GenericItem baseItem) {
    GroupFunctionDTO functionDTO = new GroupFunctionDTO();
    functionDTO.name = persistedItem.functionName;
    if (persistedItem.functionParams != null) {
        functionDTO.params = persistedItem.functionParams.toArray(new String[persistedItem.functionParams.size()]);
    }
    return ItemDTOMapper.mapFunction(baseItem, functionDTO);
}
Also used : GroupFunctionDTO(org.eclipse.smarthome.core.items.dto.GroupFunctionDTO)

Example 3 with GroupFunctionDTO

use of org.eclipse.smarthome.core.items.dto.GroupFunctionDTO in project smarthome by eclipse.

the class GenericItemProvider method applyGroupFunction.

private GroupItem applyGroupFunction(GenericItem baseItem, ModelGroupItem modelGroupItem, ModelGroupFunction function) {
    GroupFunctionDTO dto = new GroupFunctionDTO();
    dto.name = function.getName();
    dto.params = modelGroupItem.getArgs().toArray(new String[modelGroupItem.getArgs().size()]);
    GroupFunction groupFunction = ItemDTOMapper.mapFunction(baseItem, dto);
    return new GroupItem(modelGroupItem.getName(), baseItem, groupFunction);
}
Also used : GroupFunction(org.eclipse.smarthome.core.items.GroupFunction) ModelGroupFunction(org.eclipse.smarthome.model.items.ModelGroupFunction) GroupItem(org.eclipse.smarthome.core.items.GroupItem) ModelGroupItem(org.eclipse.smarthome.model.items.ModelGroupItem) GroupFunctionDTO(org.eclipse.smarthome.core.items.dto.GroupFunctionDTO)

Example 4 with GroupFunctionDTO

use of org.eclipse.smarthome.core.items.dto.GroupFunctionDTO 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 5 with GroupFunctionDTO

use of org.eclipse.smarthome.core.items.dto.GroupFunctionDTO in project smarthome by eclipse.

the class ManagedItemProvider method addFunctionToPersisedItem.

private void addFunctionToPersisedItem(PersistedItem persistedItem, GroupItem groupItem) {
    if (groupItem.getFunction() != null) {
        GroupFunctionDTO functionDTO = ItemDTOMapper.mapFunction(groupItem.getFunction());
        persistedItem.functionName = functionDTO.name;
        if (functionDTO.params != null) {
            persistedItem.functionParams = Arrays.asList(functionDTO.params);
        }
    }
}
Also used : GroupFunctionDTO(org.eclipse.smarthome.core.items.dto.GroupFunctionDTO)

Aggregations

GroupFunctionDTO (org.eclipse.smarthome.core.items.dto.GroupFunctionDTO)5 Temperature (javax.measure.quantity.Temperature)2 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)2 ArithmeticGroupFunction (org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction)2 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)2 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)2 Test (org.junit.Test)2 Dimensionless (javax.measure.quantity.Dimensionless)1 Pressure (javax.measure.quantity.Pressure)1 GroupFunction (org.eclipse.smarthome.core.items.GroupFunction)1 GroupItem (org.eclipse.smarthome.core.items.GroupItem)1 ModelGroupFunction (org.eclipse.smarthome.model.items.ModelGroupFunction)1 ModelGroupItem (org.eclipse.smarthome.model.items.ModelGroupItem)1