Search in sources :

Example 1 with IntegraStateEvent

use of org.openhab.binding.satel.internal.event.IntegraStateEvent in project openhab1-addons by openhab.

the class IntegraStateBindingConfig method convertEventToState.

/**
     * {@inheritDoc}
     */
@Override
public State convertEventToState(Item item, SatelEvent event) {
    if (!(event instanceof IntegraStateEvent) || hasOptionEnabled(Options.COMMANDS_ONLY)) {
        return null;
    }
    IntegraStateEvent stateEvent = (IntegraStateEvent) event;
    if (stateEvent.getStateType() != this.stateType) {
        return null;
    }
    if (this.objectNumbers.length == 1) {
        int bitNbr = this.objectNumbers[0] - 1;
        boolean invertState = hasOptionEnabled(Options.INVERT_STATE) && (this.stateType.getObjectType() == ObjectType.ZONE || this.stateType.getObjectType() == ObjectType.OUTPUT);
        return booleanToState(item, stateEvent.isSet(bitNbr) ^ invertState);
    } else if (this.objectNumbers.length == 0) {
        int statesSet = stateEvent.statesSet();
        if (item instanceof NumberItem) {
            return new DecimalType(statesSet);
        } else {
            return booleanToState(item, statesSet > 0);
        }
    } else if (this.objectNumbers.length == 2 && item instanceof RollershutterItem) {
        // roller shutter support
        int upBitNbr = this.objectNumbers[0] - 1;
        int downBitNbr = this.objectNumbers[1] - 1;
        if (stateEvent.isSet(upBitNbr)) {
            if (!stateEvent.isSet(downBitNbr)) {
                return UpDownType.UP;
            }
        } else if (stateEvent.isSet(downBitNbr)) {
            return UpDownType.DOWN;
        }
    }
    return null;
}
Also used : IntegraStateEvent(org.openhab.binding.satel.internal.event.IntegraStateEvent) NumberItem(org.openhab.core.library.items.NumberItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DecimalType(org.openhab.core.library.types.DecimalType)

Aggregations

IntegraStateEvent (org.openhab.binding.satel.internal.event.IntegraStateEvent)1 NumberItem (org.openhab.core.library.items.NumberItem)1 RollershutterItem (org.openhab.core.library.items.RollershutterItem)1 DecimalType (org.openhab.core.library.types.DecimalType)1