use of org.openhab.binding.pioneeravr.internal.ipcontrolprotocol.IpControlDisplayInformation in project openhab1-addons by openhab.
the class PioneerAvrBinding method convertDeviceValueToOpenHabState.
/**
* Convert receiver value to OpenHAB state.
*
* @param itemType
* @param data
*
* @return
*/
private State convertDeviceValueToOpenHabState(Class<? extends Item> itemType, String data, IpControlCommand cmdType) {
State state = UnDefType.UNDEF;
try {
int index;
// cut off the leading response identifier to get the payload string
String payloadSubstring = data.substring(cmdType.getResponse().length());
// the selected source will then be set to "ON"
if (payloadSubstring.length() == 0) {
payloadSubstring = "1";
}
// special case for display info query: convert to human readable string
if (cmdType.getCommandRef() == IpControlCommandRef.DISPLAY_INFO_QUERY) {
IpControlDisplayInformation displayInfo = new IpControlDisplayInformation(payloadSubstring);
payloadSubstring = displayInfo.getInfoText();
logger.debug("DisplayInfo: converted value '{}' to string '{}'", data, payloadSubstring);
}
if (itemType == SwitchItem.class) {
index = Integer.parseInt(payloadSubstring);
// according to Spec: 0=ON, 1=OFF!
state = (index == 0) ? OnOffType.ON : OnOffType.OFF;
} else if (itemType == DimmerItem.class) {
if (cmdType.getCommandRef().getCommand() == IpControlCommandRef.VOLUME_QUERY.getCommand() || cmdType.getCommandRef().getCommand() == IpControlCommandRef.VOLUME_SET.getCommand()) {
index = convertVolumeToPercent(Integer.parseInt(payloadSubstring));
} else {
index = Integer.parseInt(payloadSubstring);
}
state = new PercentType(index);
} else if (itemType == NumberItem.class) {
index = Integer.parseInt(payloadSubstring);
state = new DecimalType(index);
} else if (itemType == RollershutterItem.class) {
index = Integer.parseInt(payloadSubstring);
state = new PercentType(index);
} else if (itemType == StringItem.class) {
state = new StringType(payloadSubstring);
}
} catch (Exception e) {
logger.debug("Cannot convert value '{}' to data type {}", data, itemType);
}
return state;
}
Aggregations