Search in sources :

Example 61 with StringType

use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.

the class LgtvBinding method convertDeviceValueToOpenHabState.

// function
/**
     * Convert receiver value to OpenHAB state.
     *
     * @param itemType
     * @param data
     *
     * @return
     */
private State convertDeviceValueToOpenHabState(Class<? extends Item> itemType, String data) {
    State state = UnDefType.UNDEF;
    try {
        int index;
        if (itemType == SwitchItem.class) {
            index = Integer.parseInt(data);
            state = index == 0 ? OnOffType.OFF : OnOffType.ON;
        } else if (itemType == NumberItem.class) {
            index = Integer.parseInt(data);
            state = new DecimalType(index);
        } else if (itemType == DimmerItem.class) {
            index = Integer.parseInt(data);
            state = new PercentType(index);
        } else if (itemType == RollershutterItem.class) {
            index = Integer.parseInt(data);
            state = new PercentType(index);
        } else if (itemType == StringItem.class) {
            // s = data.substring(3, data.length());
            state = new StringType(data);
        }
    } catch (Exception e) {
        logger.debug("Cannot convert value '{}' to data type {}", data, itemType);
    }
    // + itemType.toString() + " val=" + state.toString());
    return state;
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) State(org.openhab.core.types.State) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 62 with StringType

use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.

the class LightwaveRfHeatingInfoCommandTest method test.

/*
     * Commands Like
     * *!{
     * "trans":1232,
     * "mac":"03:02:71",
     * "time":1423827547,
     * "prod":"valve",
     * "serial":"5A4F02",
     * "signal":0,
     * "type":"temp",
     * "batt":2.72,
     * "ver":56,
     * "state":"run",
     * "cTemp":17.8,
     * "cTarg":19.0,
     * "output":80,
     * "nTarg":24.0,
     * "nSlot":"06:00",
     * "prof":5
     * }
     */
@Test
public void test() throws Exception {
    String message = "*!{\"trans\":1506,\"mac\":\"03:02:71\",\"time\":1423850746,\"prod\":\"valve\",\"serial\":\"064402\",\"signal\":54,\"type\":\"temp\",\"batt\":2.99,\"ver\":56,\"state\":\"boost\",\"cTemp\":22.3,\"cTarg\":24.0,\"output\":100,\"nTarg\":20.0,\"nSlot\":\"18:45\",\"prof\":5}";
    LightwaveRfSerialMessage command = new LightwaveRfHeatingInfoResponse(message);
    // LightwaveRfHeatingInfoResponse
    assertEquals(new DecimalType("2.99"), command.getState(LightwaveRfType.HEATING_BATTERY));
    assertEquals(new DecimalType("22.3").doubleValue(), ((DecimalType) command.getState(LightwaveRfType.HEATING_CURRENT_TEMP)).doubleValue(), 0.001);
    assertEquals(new DecimalType("24"), command.getState(LightwaveRfType.HEATING_SET_TEMP));
    assertEquals(new DecimalType("54"), command.getState(LightwaveRfType.SIGNAL));
    assertEquals(new StringType("56"), command.getState(LightwaveRfType.VERSION));
    assertEquals(message, command.getLightwaveRfCommandString());
    assertEquals("064402", command.getSerial());
    assertEquals("1506", command.getMessageId().getMessageIdString());
    LightwaveRfHeatingInfoResponse heatingInfoCommand = (LightwaveRfHeatingInfoResponse) command;
    assertEquals("03:02:71", heatingInfoCommand.getMac());
    assertEquals("valve", heatingInfoCommand.getProd());
    assertEquals("54", heatingInfoCommand.getSignal());
    assertEquals("temp", heatingInfoCommand.getType());
    assertEquals("2.99", heatingInfoCommand.getBatteryLevel());
    assertEquals("56", heatingInfoCommand.getVersion());
    assertEquals("boost", heatingInfoCommand.getState());
    assertEquals("22.3", heatingInfoCommand.getCurrentTemperature());
    assertEquals("24.0", heatingInfoCommand.getCurrentTargetTemperature());
    assertEquals("100", heatingInfoCommand.getOutput());
    assertEquals("20.0", heatingInfoCommand.getNextTargetTeperature());
    assertEquals("18:45", heatingInfoCommand.getNextSlot());
    assertEquals("5", heatingInfoCommand.getProf());
}
Also used : StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType) Test(org.junit.Test)

Example 63 with StringType

use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.

the class LightwaveRfBindingFunctionalTest method testHeatingInfoResponseReceived.

@Test
public void testHeatingInfoResponseReceived() throws Exception {
    String message = "*!{\"trans\":1506,\"mac\":\"03:02:71\",\"time\":1423850746,\"prod\":\"valve\",\"serial\":\"064402\",\"signal\":54,\"type\":\"temp\",\"batt\":2.99,\"ver\":56,\"state\":\"boost\",\"cTemp\":22.3,\"cTarg\":24.0,\"output\":100,\"nTarg\":20.0,\"nSlot\":\"18:45\",\"prof\":5}";
    List<ItemConfigAndExpectedState> itemConfigAndExpectedStates = new LinkedList<ItemConfigAndExpectedState>();
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new NumberItem("BATTERY"), "serial=064402,type=HEATING_BATTERY", new DecimalType("2.99")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new NumberItem("CURRENT_TEMP"), "serial=064402,type=HEATING_CURRENT_TEMP", new DecimalType("22.3")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("MODE"), "serial=064402,type=HEATING_MODE", new StringType("boost")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("VERSION"), "serial=064402,type=VERSION", new StringType("56")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new NumberItem("SIGNAL"), "serial=064402,type=SIGNAL", new DecimalType("54")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new NumberItem("SET_TEMP"), "serial=064402,type=HEATING_SET_TEMP", new DecimalType("24.0")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new NumberItem("OUTPUT"), "serial=064402,type=HEATING_OUTPUT", new DecimalType("100")));
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date(1423850746000L));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new DateTimeItem("TIME"), "serial=064402,type=UPDATETIME", new DateTimeType(cal)));
    testReceivingACommandAndVerify(itemConfigAndExpectedStates, message);
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) DateTimeType(org.openhab.core.library.types.DateTimeType) StringType(org.openhab.core.library.types.StringType) Calendar(java.util.Calendar) DecimalType(org.openhab.core.library.types.DecimalType) DateTimeItem(org.openhab.core.library.items.DateTimeItem) StringItem(org.openhab.core.library.items.StringItem) LinkedList(java.util.LinkedList) Date(java.util.Date) Test(org.junit.Test)

Example 64 with StringType

use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.

the class LightwaveRfBindingTest method testVersionMessageRecevied.

@Test
public void testVersionMessageRecevied() {
    when(mockVersionMessage.getState(LightwaveRfType.VERSION)).thenReturn(new StringType("2.91"));
    when(mockBindingProvider.getBindingItemsForType(LightwaveRfType.VERSION)).thenReturn(Arrays.asList("MyVersion"));
    when(mockBindingProvider.getTypeForItemName("MyVersion")).thenReturn(LightwaveRfType.VERSION);
    when(mockBindingProvider.getDirection("MyVersion")).thenReturn(LightwaveRfItemDirection.IN_AND_OUT);
    LightwaveRfBinding binding = new LightwaveRfBinding();
    binding.addBindingProvider(mockBindingProvider);
    binding.setEventPublisher(mockEventPublisher);
    binding.versionMessageReceived(mockVersionMessage);
    verify(mockEventPublisher).postUpdate("MyVersion", new StringType("2.91"));
}
Also used : StringType(org.openhab.core.library.types.StringType) Test(org.junit.Test)

Example 65 with StringType

use of org.openhab.core.library.types.StringType in project openhab1-addons by openhab.

the class LogicOpVisualize method visualizationLedsAndLogicOpsStatus.

/**
     * Visualization for {@link DecimalType} and {@link StringType}.
     * {@inheritDoc}
     */
@Override
public boolean visualizationLedsAndLogicOpsStatus(ModStatusLedsAndLogicOps pchkInput, Command cmd, Item item, EventPublisher eventPublisher) {
    if (pchkInput.getLogicalSourceAddr().equals(this.addr)) {
        if (item.getAcceptedDataTypes().contains(DecimalType.class)) {
            int n;
            switch(pchkInput.getLogicOpState(this.logicOpId)) {
                case NOT:
                    n = 0;
                    break;
                case OR:
                    n = 1;
                    break;
                case AND:
                    n = 2;
                    break;
                default:
                    throw new Error();
            }
            eventPublisher.postUpdate(item.getName(), new DecimalType(n));
            return true;
        } else if (item.getAcceptedDataTypes().contains(StringType.class)) {
            String s;
            switch(pchkInput.getLogicOpState(this.logicOpId)) {
                case NOT:
                    s = this.stateTexts[0];
                    break;
                case OR:
                    s = this.stateTexts[1];
                    break;
                case AND:
                    s = this.stateTexts[2];
                    break;
                default:
                    throw new Error();
            }
            eventPublisher.postUpdate(item.getName(), new StringType(s));
            return true;
        }
    }
    return false;
}
Also used : StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType)

Aggregations

StringType (org.openhab.core.library.types.StringType)90 DecimalType (org.openhab.core.library.types.DecimalType)69 State (org.openhab.core.types.State)30 DateTimeType (org.openhab.core.library.types.DateTimeType)28 PercentType (org.openhab.core.library.types.PercentType)27 NumberItem (org.openhab.core.library.items.NumberItem)25 Calendar (java.util.Calendar)23 StringItem (org.openhab.core.library.items.StringItem)18 OnOffType (org.openhab.core.library.types.OnOffType)15 SwitchItem (org.openhab.core.library.items.SwitchItem)12 ContactItem (org.openhab.core.library.items.ContactItem)10 DimmerItem (org.openhab.core.library.items.DimmerItem)10 RollershutterItem (org.openhab.core.library.items.RollershutterItem)10 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 DateTimeItem (org.openhab.core.library.items.DateTimeItem)8 HSBType (org.openhab.core.library.types.HSBType)8 ConfigurationException (org.osgi.service.cm.ConfigurationException)8 IOException (java.io.IOException)7 BigDecimal (java.math.BigDecimal)7