Search in sources :

Example 16 with StringType

use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.

the class ItemUIRegistryImplTest method getLabel_labelWithMappedOption.

@Test
public void getLabel_labelWithMappedOption() 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("State1"));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label [This is the state 1]", 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 17 with StringType

use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.

the class GroupItemTest method assertCyclicGroupItemsCalculateState.

@Test
public void assertCyclicGroupItemsCalculateState() {
    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");
    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, sub2-1, sub2-2, sub2-3
    assertThat(rootGroup.getStateAs(DecimalType.class), is(new DecimalType(5)));
}
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) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 18 with StringType

use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.

the class StateUtil method getAllStates.

public static List<State> getAllStates() {
    LinkedList<State> states = new LinkedList<>();
    DateTimeType dateTime = new DateTimeType();
    states.add(dateTime);
    DecimalType decimal = new DecimalType(23);
    states.add(decimal);
    PercentType percent = new PercentType(50);
    states.add(percent);
    HSBType hsb = new HSBType("50,75,42");
    states.add(hsb);
    states.add(OnOffType.ON);
    states.add(OnOffType.OFF);
    states.add(OpenClosedType.OPEN);
    states.add(OpenClosedType.CLOSED);
    states.add(PlayPauseType.PLAY);
    states.add(PlayPauseType.PAUSE);
    PointType point = new PointType("42.23,23.5");
    states.add(point);
    RawType raw = new RawType(new byte[0], "application/octet-stream");
    states.add(raw);
    states.add(RewindFastforwardType.REWIND);
    states.add(RewindFastforwardType.FASTFORWARD);
    StringListType stringList = new StringListType(new String[] { "foo", "bar" });
    states.add(stringList);
    StringType string = new StringType("foo");
    states.add(string);
    states.add(UnDefType.NULL);
    states.add(UnDefType.UNDEF);
    states.add(UpDownType.UP);
    states.add(UpDownType.DOWN);
    QuantityType<Temperature> quantityType = new QuantityType<Temperature>("12 °C");
    states.add(quantityType);
    return states;
}
Also used : Temperature(javax.measure.quantity.Temperature) StringType(org.eclipse.smarthome.core.library.types.StringType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) LinkedList(java.util.LinkedList) DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) QuantityType(org.eclipse.smarthome.core.library.types.QuantityType) State(org.eclipse.smarthome.core.types.State) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PointType(org.eclipse.smarthome.core.library.types.PointType) RawType(org.eclipse.smarthome.core.library.types.RawType) HSBType(org.eclipse.smarthome.core.library.types.HSBType) StringListType(org.eclipse.smarthome.core.library.types.StringListType)

Example 19 with StringType

use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.

the class StringItemTest method setStringType.

@Test
public void setStringType() {
    StringItem item = new StringItem("test");
    State state = new StringType("foobar");
    item.setState(state);
    assertEquals(state, item.getState());
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) State(org.eclipse.smarthome.core.types.State) Test(org.junit.Test)

Example 20 with StringType

use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.

the class DeviceHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    BridgeHandler dssBridgeHandler = getDssBridgeHandler();
    if (dssBridgeHandler == null) {
        logger.debug("BridgeHandler not found. Cannot handle command without bridge.");
        return;
    }
    if (device == null) {
        logger.debug("Device not known on StructureManager or DeviceStatusListener is not registerd. Cannot handle command.");
        return;
    }
    if (command instanceof RefreshType) {
        try {
            SensorEnum sensorType = SensorEnum.valueOf(channelUID.getId());
            dssBridgeHandler.sendComandsToDSS(device, new DeviceStateUpdateImpl(sensorType, 1));
        } catch (IllegalArgumentException e) {
            dssBridgeHandler.sendComandsToDSS(device, new DeviceStateUpdateImpl(DeviceStateUpdate.REFRESH_OUTPUT, 0));
        }
    } else if (!device.isShade()) {
        if (DsChannelTypeProvider.isOutputChannel(channelUID.getId())) {
            if (command instanceof PercentType) {
                device.setOutputValue((short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxOutputValue()));
            } else if (command instanceof OnOffType) {
                if (OnOffType.ON.equals(command)) {
                    device.setIsOn(true);
                } else {
                    device.setIsOn(false);
                }
            } else if (command instanceof IncreaseDecreaseType) {
                if (IncreaseDecreaseType.INCREASE.equals(command)) {
                    device.increase();
                } else {
                    device.decrease();
                }
            } else if (command instanceof StringType) {
                device.setOutputValue(Short.parseShort(((StringType) command).toString()));
            }
        } else {
            logger.debug("Command sent to an unknown channel id: {}", channelUID);
        }
    } else {
        if (channelUID.getId().contains(DsChannelTypeProvider.ANGLE)) {
            if (command instanceof PercentType) {
                device.setAnglePosition((short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxSlatAngle()));
            } else if (command instanceof OnOffType) {
                if (OnOffType.ON.equals(command)) {
                    device.setAnglePosition(device.getMaxSlatAngle());
                } else {
                    device.setAnglePosition(device.getMinSlatAngle());
                }
            } else if (command instanceof IncreaseDecreaseType) {
                if (IncreaseDecreaseType.INCREASE.equals(command)) {
                    device.increaseSlatAngle();
                } else {
                    device.decreaseSlatAngle();
                }
            }
        } else if (channelUID.getId().contains(DsChannelTypeProvider.SHADE)) {
            if (command instanceof PercentType) {
                int percent = ((PercentType) command).intValue();
                if (!device.getHWinfo().equals("GR-KL200")) {
                    percent = 100 - percent;
                }
                device.setSlatPosition(fromPercentToValue(percent, device.getMaxSlatPosition()));
                this.lastComand = command;
            } else if (command instanceof StopMoveType) {
                if (StopMoveType.MOVE.equals(command)) {
                    handleCommand(channelUID, this.lastComand);
                } else {
                    dssBridgeHandler.stopOutputValue(device);
                }
            } else if (command instanceof UpDownType) {
                if (UpDownType.UP.equals(command)) {
                    device.setIsOpen(true);
                    this.lastComand = command;
                } else {
                    device.setIsOpen(false);
                    this.lastComand = command;
                }
            }
        } else {
            logger.debug("Command sent to an unknown channel id: {}", channelUID);
        }
    }
}
Also used : SensorEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) StringType(org.eclipse.smarthome.core.library.types.StringType) DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) UpDownType(org.eclipse.smarthome.core.library.types.UpDownType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType) StopMoveType(org.eclipse.smarthome.core.library.types.StopMoveType)

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