use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class GroupItemTest method assertCyclicGroupItemsCalculateStateWithSubGroupFunction.
@Test
public void assertCyclicGroupItemsCalculateStateWithSubGroupFunction() {
GroupFunction countFn = new ArithmeticGroupFunction.Count(new StringType(".*"));
GroupItem rootGroup = new GroupItem("rootGroup", new SwitchItem("baseItem"), countFn);
TestItem rootMember = new TestItem("rootMember");
rootGroup.addMember(rootMember);
GroupItem group1 = new GroupItem("group1");
GroupItem group2 = new GroupItem("group2", new SwitchItem("baseItem"), new ArithmeticGroupFunction.Sum());
rootGroup.addMember(group1);
group1.addMember(group2);
group2.addMember(group1);
group1.addMember(new TestItem("sub1"));
group2.addMember(new TestItem("sub2-1"));
group2.addMember(new TestItem("sub2-2"));
group2.addMember(new TestItem("sub2-3"));
// count: rootMember, sub1, group2
assertThat(rootGroup.getStateAs(DecimalType.class), is(new DecimalType(3)));
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_labelWithUnmappedOption.
@Test
public void getLabel_labelWithUnmappedOption() throws ItemNotFoundException {
String testLabel = "Label";
StateDescription stateDescription = mock(StateDescription.class);
List<StateOption> options = new ArrayList<>();
options.add(new StateOption("State0", "This is the state 0"));
options.add(new StateOption("State1", "This is the state 1"));
when(widget.getLabel()).thenReturn(testLabel);
when(item.getStateDescription()).thenReturn(stateDescription);
when(stateDescription.getPattern()).thenReturn("%s");
when(stateDescription.getOptions()).thenReturn(options);
when(item.getState()).thenReturn(new StringType("State"));
String label = uiRegistry.getLabel(widget);
assertEquals("Label [State]", label);
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_labelWithoutStateDescription.
@Test
public void getLabel_labelWithoutStateDescription() throws ItemNotFoundException {
String testLabel = "Label";
when(widget.getLabel()).thenReturn(testLabel);
when(item.getStateDescription()).thenReturn(null);
when(item.getState()).thenReturn(new StringType("State"));
String label = uiRegistry.getLabel(widget);
assertEquals("Label", label);
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class RuleHumanLanguageInterpreter method interpret.
@Override
public String interpret(Locale locale, String text) throws InterpretationException {
Event event = ItemEventFactory.createCommandEvent(itemName, new StringType(text));
eventPublisher.post(event);
return null;
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class DeviceHandler method channelLinked.
@Override
public void channelLinked(ChannelUID channelUID) {
if (device != null) {
SensorEnum sensorType = getSensorEnum(channelUID.getId());
if (sensorType != null) {
Float val = device.getFloatSensorValue(sensorType);
if (val != null) {
updateState(channelUID, new DecimalType(val));
}
}
Short val = device.getBinaryInputState(getBinaryInput(channelUID.getId()));
if (val != null) {
if (val == 1) {
updateState(channelUID, OnOffType.ON);
} else {
updateState(channelUID, OnOffType.OFF);
}
}
if (channelUID.getId().contains(DsChannelTypeProvider.DIMMER)) {
if (device.isOn()) {
updateState(channelUID, new PercentType(fromValueToPercent(device.getOutputValue(), device.getMaxOutputValue())));
} else {
updateState(channelUID, new PercentType(0));
}
return;
}
if (channelUID.getId().contains(DsChannelTypeProvider.SWITCH)) {
if (device.isOn()) {
updateState(channelUID, OnOffType.ON);
} else {
updateState(channelUID, OnOffType.OFF);
}
return;
}
if (channelUID.getId().contains(DsChannelTypeProvider.SHADE)) {
updateState(channelUID, new PercentType(fromValueToPercent(device.getSlatPosition(), device.getMaxSlatPosition())));
return;
}
if (channelUID.getId().contains(DsChannelTypeProvider.ANGLE)) {
updateState(channelUID, new PercentType(fromValueToPercent(device.getAnglePosition(), device.getMaxSlatAngle())));
return;
}
if (channelUID.getId().contains(DsChannelTypeProvider.STAGE)) {
if (channelUID.getId().contains(TWO_STAGE_SWITCH_IDENTICATOR)) {
updateState(channelUID, new StringType(convertStageValue((short) 2, device.getOutputValue())));
return;
}
if (channelUID.getId().contains(THREE_STAGE_SWITCH_IDENTICATOR)) {
updateState(channelUID, new StringType(convertStageValue((short) 3, device.getOutputValue())));
return;
}
}
}
}
Aggregations