Search in sources :

Example 26 with StringType

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)));
}
Also used : ArithmeticGroupFunction(org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction) StringType(org.eclipse.smarthome.core.library.types.StringType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) ArithmeticGroupFunction(org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 27 with StringType

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);
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StateOption(org.eclipse.smarthome.core.types.StateOption) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Test(org.junit.Test)

Example 28 with StringType

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);
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 29 with StringType

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;
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) Event(org.eclipse.smarthome.core.events.Event)

Example 30 with StringType

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;
            }
        }
    }
}
Also used : SensorEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum) StringType(org.eclipse.smarthome.core.library.types.StringType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType)

Aggregations

StringType (org.eclipse.smarthome.core.library.types.StringType)43 State (org.eclipse.smarthome.core.types.State)13 Test (org.junit.Test)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)9 PercentType (org.eclipse.smarthome.core.library.types.PercentType)8 StateDescription (org.eclipse.smarthome.core.types.StateDescription)6 SonosEntry (org.eclipse.smarthome.binding.sonos.internal.SonosEntry)5 DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)5 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)5 Date (java.util.Date)3 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)3 RefreshType (org.eclipse.smarthome.core.types.RefreshType)3 ArrayList (java.util.ArrayList)2 SensorEnum (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum)2 DeviceStateUpdateImpl (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl)2 Event (org.eclipse.smarthome.core.events.Event)2 Item (org.eclipse.smarthome.core.items.Item)2 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)2 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)2