Search in sources :

Example 1 with OceanicValueSelector

use of org.openhab.binding.oceanic.OceanicValueSelector in project openhab1-addons by openhab.

the class OceanicBinding method internalReceiveCommand.

@Override
protected void internalReceiveCommand(String itemName, Command command) {
    OceanicBindingProvider provider = findFirstMatchingBindingProvider(itemName);
    String serialPort = provider.getSerialPort(itemName);
    OceanicValueSelector valueSelector = OceanicValueSelector.getValueSelector(provider.getValueSelector(itemName), ValueSelectorType.SET);
    SerialDevice serialDevice = serialDevices.get(serialPort);
    if (valueSelector.name().contains("set")) {
        String commandAsString = command.toString();
        switch(valueSelector) {
            case setSV1:
                commandAsString = valueSelector.name() + commandAsString;
            default:
                commandAsString = valueSelector.name();
                break;
        }
        String response = serialDevice.requestResponse(commandAsString);
        if (response.equals("ERR")) {
            logger.error("An error occurred while setting '{}' to {}", valueSelector.toString(), command.toString());
        }
    } else {
        // can not set the value of a read-only "get" variable
        logger.warn("An error occurred while trying to set the read-only variable '{}' to {}", valueSelector.toString(), command.toString());
    }
}
Also used : OceanicValueSelector(org.openhab.binding.oceanic.OceanicValueSelector) OceanicBindingProvider(org.openhab.binding.oceanic.OceanicBindingProvider)

Aggregations

OceanicBindingProvider (org.openhab.binding.oceanic.OceanicBindingProvider)1 OceanicValueSelector (org.openhab.binding.oceanic.OceanicValueSelector)1