Search in sources :

Example 1 with IpControlDisplayInformation

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;
}
Also used : IpControlDisplayInformation(org.openhab.binding.pioneeravr.internal.ipcontrolprotocol.IpControlDisplayInformation) StringType(org.openhab.core.library.types.StringType) State(org.openhab.core.types.State) DimmerItem(org.openhab.core.library.items.DimmerItem) 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)

Aggregations

IpControlDisplayInformation (org.openhab.binding.pioneeravr.internal.ipcontrolprotocol.IpControlDisplayInformation)1 DimmerItem (org.openhab.core.library.items.DimmerItem)1 RollershutterItem (org.openhab.core.library.items.RollershutterItem)1 DecimalType (org.openhab.core.library.types.DecimalType)1 PercentType (org.openhab.core.library.types.PercentType)1 StringType (org.openhab.core.library.types.StringType)1 State (org.openhab.core.types.State)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1