Search in sources :

Example 6 with SappAddressType

use of org.openhab.binding.sapp.internal.model.SappAddressType in project openhab1-addons by openhab.

the class SappBindingConfigNumberItem method parseSappAddressStatus.

private SappAddressDecimal parseSappAddressStatus(String bindingStringAddress) throws BindingConfigParseException {
    String pnmasId;
    SappAddressType addressType;
    int address;
    String subAddress;
    int minScale;
    int maxScale;
    String[] bindingAddress = bindingStringAddress.split(":");
    if (bindingAddress.length != 4 && bindingAddress.length != 6) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // pnmasId
    pnmasId = bindingAddress[0];
    if (pnmasId.length() == 0) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // addressType
    addressType = SappAddressType.fromString(bindingAddress[1].toUpperCase());
    if (!validAddresses.keySet().contains(addressType)) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // address
    try {
        address = Integer.parseInt(bindingAddress[2]);
        if (address < validAddresses.get(addressType).getLoRange() || address > validAddresses.get(addressType).getHiRange()) {
            throw new BindingConfigParseException(errorMessage(bindingStringAddress));
        }
    } catch (NumberFormatException e) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // subaddress
    subAddress = bindingAddress[3].toUpperCase();
    if (!ArrayUtils.contains(validSubAddresses, subAddress)) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    if (bindingAddress.length == 6) {
        try {
            minScale = Integer.parseInt(bindingAddress[4]);
            maxScale = Integer.parseInt(bindingAddress[5]);
        } catch (NumberFormatException e) {
            throw new BindingConfigParseException(errorMessage(bindingStringAddress));
        }
        return new SappAddressDecimal(pnmasId, addressType, address, subAddress, minScale, maxScale);
    } else {
        return new SappAddressDecimal(pnmasId, addressType, address, subAddress);
    }
}
Also used : SappAddressDecimal(org.openhab.binding.sapp.internal.model.SappAddressDecimal) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) SappAddressType(org.openhab.binding.sapp.internal.model.SappAddressType)

Example 7 with SappAddressType

use of org.openhab.binding.sapp.internal.model.SappAddressType in project openhab1-addons by openhab.

the class SappBindingConfigSwitchItem method parseSappAddressControl.

private SappAddressOnOffControl parseSappAddressControl(String bindingStringAddress) throws BindingConfigParseException {
    String pnmasId;
    SappAddressType addressType;
    int address;
    String subAddress;
    int onValue = 1;
    int offValue = 0;
    String[] bindingAddress = bindingStringAddress.split(":");
    if (bindingAddress.length != 4 && bindingAddress.length != 6) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // pnmasId
    pnmasId = bindingAddress[0];
    if (pnmasId.length() == 0) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // addressType
    addressType = SappAddressType.fromString(bindingAddress[1].toUpperCase());
    if (!validAddresses.keySet().contains(addressType)) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    if (addressType != SappAddressType.VIRTUAL) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // address
    try {
        address = Integer.parseInt(bindingAddress[2]);
        if (address < validAddresses.get(addressType).getLoRange() || address > validAddresses.get(addressType).getHiRange()) {
            throw new BindingConfigParseException(errorMessage(bindingStringAddress));
        }
    } catch (NumberFormatException e) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // subaddress
    subAddress = bindingAddress[3].toUpperCase();
    if (!ArrayUtils.contains(validSubAddresses, subAddress)) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // onvalue, offvalue
    if (bindingAddress.length == 6) {
        try {
            onValue = Integer.parseInt(bindingAddress[4]);
            offValue = Integer.parseInt(bindingAddress[5]);
        } catch (NumberFormatException e) {
            throw new BindingConfigParseException(errorMessage(bindingStringAddress));
        }
    }
    return new SappAddressOnOffControl(pnmasId, addressType, address, subAddress, onValue, offValue);
}
Also used : SappAddressOnOffControl(org.openhab.binding.sapp.internal.model.SappAddressOnOffControl) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) SappAddressType(org.openhab.binding.sapp.internal.model.SappAddressType)

Aggregations

SappAddressType (org.openhab.binding.sapp.internal.model.SappAddressType)7 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)7 SappAddressDecimal (org.openhab.binding.sapp.internal.model.SappAddressDecimal)1 SappAddressDimmer (org.openhab.binding.sapp.internal.model.SappAddressDimmer)1 SappAddressOnOffControl (org.openhab.binding.sapp.internal.model.SappAddressOnOffControl)1 SappAddressOnOffStatus (org.openhab.binding.sapp.internal.model.SappAddressOnOffStatus)1 SappAddressOpenClosedStatus (org.openhab.binding.sapp.internal.model.SappAddressOpenClosedStatus)1 SappAddressRollershutterControl (org.openhab.binding.sapp.internal.model.SappAddressRollershutterControl)1 SappAddressRollershutterStatus (org.openhab.binding.sapp.internal.model.SappAddressRollershutterStatus)1