Search in sources :

Example 1 with StopMoveType

use of org.eclipse.smarthome.core.library.types.StopMoveType in project smarthome by eclipse.

the class DeviceHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    BridgeHandler dssBridgeHandler = getDssBridgeHandler();
    if (dssBridgeHandler == null) {
        logger.debug("BridgeHandler not found. Cannot handle command without bridge.");
        return;
    }
    if (device == null) {
        logger.debug("Device not known on StructureManager or DeviceStatusListener is not registerd. Cannot handle command.");
        return;
    }
    if (command instanceof RefreshType) {
        try {
            SensorEnum sensorType = SensorEnum.valueOf(channelUID.getId());
            dssBridgeHandler.sendComandsToDSS(device, new DeviceStateUpdateImpl(sensorType, 1));
        } catch (IllegalArgumentException e) {
            dssBridgeHandler.sendComandsToDSS(device, new DeviceStateUpdateImpl(DeviceStateUpdate.REFRESH_OUTPUT, 0));
        }
    } else if (!device.isShade()) {
        if (DsChannelTypeProvider.isOutputChannel(channelUID.getId())) {
            if (command instanceof PercentType) {
                device.setOutputValue((short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxOutputValue()));
            } else if (command instanceof OnOffType) {
                if (OnOffType.ON.equals(command)) {
                    device.setIsOn(true);
                } else {
                    device.setIsOn(false);
                }
            } else if (command instanceof IncreaseDecreaseType) {
                if (IncreaseDecreaseType.INCREASE.equals(command)) {
                    device.increase();
                } else {
                    device.decrease();
                }
            } else if (command instanceof StringType) {
                device.setOutputValue(Short.parseShort(((StringType) command).toString()));
            }
        } else {
            logger.debug("Command sent to an unknown channel id: {}", channelUID);
        }
    } else {
        if (channelUID.getId().contains(DsChannelTypeProvider.ANGLE)) {
            if (command instanceof PercentType) {
                device.setAnglePosition((short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxSlatAngle()));
            } else if (command instanceof OnOffType) {
                if (OnOffType.ON.equals(command)) {
                    device.setAnglePosition(device.getMaxSlatAngle());
                } else {
                    device.setAnglePosition(device.getMinSlatAngle());
                }
            } else if (command instanceof IncreaseDecreaseType) {
                if (IncreaseDecreaseType.INCREASE.equals(command)) {
                    device.increaseSlatAngle();
                } else {
                    device.decreaseSlatAngle();
                }
            }
        } else if (channelUID.getId().contains(DsChannelTypeProvider.SHADE)) {
            if (command instanceof PercentType) {
                int percent = ((PercentType) command).intValue();
                if (!device.getHWinfo().equals("GR-KL200")) {
                    percent = 100 - percent;
                }
                device.setSlatPosition(fromPercentToValue(percent, device.getMaxSlatPosition()));
                this.lastComand = command;
            } else if (command instanceof StopMoveType) {
                if (StopMoveType.MOVE.equals(command)) {
                    handleCommand(channelUID, this.lastComand);
                } else {
                    dssBridgeHandler.stopOutputValue(device);
                }
            } else if (command instanceof UpDownType) {
                if (UpDownType.UP.equals(command)) {
                    device.setIsOpen(true);
                    this.lastComand = command;
                } else {
                    device.setIsOpen(false);
                    this.lastComand = command;
                }
            }
        } else {
            logger.debug("Command sent to an unknown channel id: {}", channelUID);
        }
    }
}
Also used : SensorEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) StringType(org.eclipse.smarthome.core.library.types.StringType) DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) UpDownType(org.eclipse.smarthome.core.library.types.UpDownType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType) StopMoveType(org.eclipse.smarthome.core.library.types.StopMoveType)

Aggregations

SensorEnum (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum)1 DeviceStateUpdateImpl (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl)1 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)1 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)1 PercentType (org.eclipse.smarthome.core.library.types.PercentType)1 StopMoveType (org.eclipse.smarthome.core.library.types.StopMoveType)1 StringType (org.eclipse.smarthome.core.library.types.StringType)1 UpDownType (org.eclipse.smarthome.core.library.types.UpDownType)1 RefreshType (org.eclipse.smarthome.core.types.RefreshType)1