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