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")));
}
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);
}
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);
}
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));
}
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);
}
}
}
Aggregations