Search in sources :

Example 1 with ControlObjectCommand

use of org.openhab.binding.satel.command.ControlObjectCommand in project openhab1-addons by openhab.

the class IntegraStateBindingConfig method convertCommand.

/**
     * {@inheritDoc}
     */
@Override
public SatelCommand convertCommand(Command command, IntegraType integraType, String userCode) {
    if (command instanceof OnOffType && this.objectNumbers.length == 1) {
        boolean switchOn = ((OnOffType) command == OnOffType.ON);
        boolean force_arm = hasOptionEnabled(Options.FORCE_ARM);
        switch(this.stateType.getObjectType()) {
            case OUTPUT:
                byte[] outputs = getObjectBitset((integraType == IntegraType.I256_PLUS) ? 32 : 16);
                boolean invertState = hasOptionEnabled(Options.INVERT_STATE);
                return new ControlObjectCommand(switchOn ^ invertState ? OutputControl.ON : OutputControl.OFF, outputs, userCode);
            case DOORS:
                // for doors you can also control outputs of type 101, but we do not support this feature
                // anyway we need to send list of outputs, so we have 'dummy' array for this purpose
                byte[] doors = getObjectBitset(8);
                byte[] dummy = new byte[(integraType == IntegraType.I256_PLUS) ? 32 : 16];
                if (switchOn) {
                    return new ControlObjectCommand(DoorsControl.OPEN, ArrayUtils.addAll(dummy, doors), userCode);
                } else {
                    return null;
                }
            case ZONE:
                byte[] zones = getObjectBitset((integraType == IntegraType.I256_PLUS) ? 32 : 16);
                switch((ZoneState) this.stateType) {
                    case BYPASS:
                        return new ControlObjectCommand(switchOn ? ZoneControl.BYPASS : ZoneControl.UNBYPASS, zones, userCode);
                    case ISOLATE:
                        if (switchOn) {
                            return new ControlObjectCommand(ZoneControl.ISOLATE, zones, userCode);
                        } else {
                            return null;
                        }
                    default:
                        // do nothing for other types of state
                        break;
                }
                break;
            case PARTITION:
                byte[] partitions = getObjectBitset(4);
                switch((PartitionState) this.stateType) {
                    // clear alarms on OFF command
                    case ALARM:
                    case ALARM_MEMORY:
                    case FIRE_ALARM:
                    case FIRE_ALARM_MEMORY:
                    case VERIFIED_ALARMS:
                    case WARNING_ALARMS:
                        if (switchOn) {
                            return null;
                        } else {
                            return new ControlObjectCommand(PartitionControl.CLEAR_ALARM, partitions, userCode);
                        }
                    // arm or disarm, depending on command
                    case ARMED:
                    case REALLY_ARMED:
                        return new ControlObjectCommand(switchOn ? (force_arm ? PartitionControl.FORCE_ARM_MODE_0 : PartitionControl.ARM_MODE_0) : PartitionControl.DISARM, partitions, userCode);
                    case ARMED_MODE_1:
                        return new ControlObjectCommand(switchOn ? (force_arm ? PartitionControl.FORCE_ARM_MODE_1 : PartitionControl.ARM_MODE_1) : PartitionControl.DISARM, partitions, userCode);
                    case ARMED_MODE_2:
                        return new ControlObjectCommand(switchOn ? (force_arm ? PartitionControl.FORCE_ARM_MODE_2 : PartitionControl.ARM_MODE_2) : PartitionControl.DISARM, partitions, userCode);
                    case ARMED_MODE_3:
                        return new ControlObjectCommand(switchOn ? (force_arm ? PartitionControl.FORCE_ARM_MODE_3 : PartitionControl.ARM_MODE_3) : PartitionControl.DISARM, partitions, userCode);
                    default:
                        // do nothing for other types of state
                        break;
                }
        }
    } else if (this.stateType.getObjectType() == ObjectType.OUTPUT && this.objectNumbers.length == 2) {
        // roller shutter support
        if (command == UpDownType.UP) {
            byte[] outputs = getObjectBitset((integraType == IntegraType.I256_PLUS) ? 32 : 16, 0);
            return new ControlObjectCommand(OutputControl.ON, outputs, userCode);
        } else if (command == UpDownType.DOWN) {
            byte[] outputs = getObjectBitset((integraType == IntegraType.I256_PLUS) ? 32 : 16, 1);
            return new ControlObjectCommand(OutputControl.ON, outputs, userCode);
        } else if (command == StopMoveType.STOP) {
            byte[] outputs = getObjectBitset((integraType == IntegraType.I256_PLUS) ? 32 : 16);
            return new ControlObjectCommand(OutputControl.OFF, outputs, userCode);
        }
    }
    return null;
}
Also used : OnOffType(org.openhab.core.library.types.OnOffType) ZoneState(org.openhab.binding.satel.internal.types.ZoneState) PartitionState(org.openhab.binding.satel.internal.types.PartitionState) ControlObjectCommand(org.openhab.binding.satel.command.ControlObjectCommand)

Aggregations

ControlObjectCommand (org.openhab.binding.satel.command.ControlObjectCommand)1 PartitionState (org.openhab.binding.satel.internal.types.PartitionState)1 ZoneState (org.openhab.binding.satel.internal.types.ZoneState)1 OnOffType (org.openhab.core.library.types.OnOffType)1