private void filterCommand(DeviceStateUpdate deviceStateUpdate, Device device) {
   String stateUpdateType = deviceStateUpdate.getType();
   short newAngle = 0;
   if (stateUpdateType.equals(DeviceStateUpdate.UPDATE_SLAT_ANGLE_INCREASE)
       || stateUpdateType.equals(DeviceStateUpdate.UPDATE_SLAT_ANGLE_DECREASE)) {
     newAngle = device.getAnglePosition();
   }
   DeviceStateUpdate nextDeviceStateUpdate = device.getNextDeviceUpdateState();
   while (nextDeviceStateUpdate != null
       && nextDeviceStateUpdate.getType().equals(stateUpdateType)) {
     switch (stateUpdateType) {
       case DeviceStateUpdate.UPDATE_BRIGHTNESS:
         deviceStateUpdate = nextDeviceStateUpdate;
         nextDeviceStateUpdate = device.getNextDeviceUpdateState();
         break;
       case DeviceStateUpdate.UPDATE_SLAT_ANGLE_INCREASE:
         if (deviceStateUpdate.getValue() == 1) {
           newAngle = (short) (newAngle + DeviceConstants.ANGLE_STEP_SLAT);
         }
         break;
       case DeviceStateUpdate.UPDATE_SLAT_ANGLE_DECREASE:
         if (deviceStateUpdate.getValue() == 1) {
           newAngle = (short) (newAngle - DeviceConstants.ANGLE_STEP_SLAT);
         }
         break;
     }
   }
   if (stateUpdateType.equals(DeviceStateUpdate.UPDATE_SLAT_ANGLE_INCREASE)
       || stateUpdateType.equals(DeviceStateUpdate.UPDATE_SLAT_ANGLE_DECREASE)) {
     if (newAngle > device.getMaxSlatAngle()) {
       newAngle = (short) device.getMaxSlatAngle();
     }
     if (newAngle < device.getMinSlatAngle()) {
       newAngle = (short) device.getMinSlatAngle();
     }
     if (!(stateUpdateType.equals(DeviceStateUpdate.UPDATE_SLAT_ANGLE_INCREASE)
             && checkAngleIsMinMax(device) == 1)
         || !(stateUpdateType.equals(DeviceStateUpdate.UPDATE_SLAT_ANGLE_DECREASE)
             && checkAngleIsMinMax(device) == 0)) {
       deviceStateUpdate =
           new DeviceStateUpdateImpl(DeviceStateUpdate.UPDATE_SLAT_ANGLE, newAngle);
     }
   }
   sendComandsToDSS(device, deviceStateUpdate);
   if (nextDeviceStateUpdate != null) {
     if (deviceStateUpdate.getType() == DeviceStateUpdate.UPDATE_SCENE_CONFIG
         || deviceStateUpdate.getType() == DeviceStateUpdate.UPDATE_SCENE_OUTPUT) {
       updateSceneData(device, deviceStateUpdate);
     } else {
       sendComandsToDSS(device, deviceStateUpdate);
     }
   }
 }
 /**
  * Checks the output value of a {@link Device} and return 0, if the output value or slat position
  * is min and 1, if the output value or slat position is max, otherwise it returns -1.
  *
  * @param device
  * @return 0 = output value is min, 1 device value is min, otherwise -1
  */
 private short checkIsAllreadyMinMax(Device device) {
   if (device.isShade()) {
     if (device.getSlatPosition() == device.getMaxSlatPosition()) {
       if (device.isBlind()) {
         if (device.getAnglePosition() == device.getMaxSlatAngle()) {
           return 1;
         } else {
           return -1;
         }
       }
       return 1;
     }
     if (device.getSlatPosition() == device.getMinSlatPosition()) {
       if (device.isBlind()) {
         if (device.getAnglePosition() == device.getMinSlatAngle()) {
           return 0;
         } else {
           return -1;
         }
       }
       return 0;
     }
   } else {
     if (device.getOutputValue() == device.getMaxOutputValue()) {
       return 1;
     }
     if (device.getOutputValue() == device.getMinOutputValue() || device.getOutputValue() <= 0) {
       return 0;
     }
   }
   return -1;
 }
 /**
  * Checks the angle value of a {@link Device} and return 0, if the angle value is min and 1, if
  * the angle value is max, otherwise it returns -1.
  *
  * @param device
  * @return 0 = angle value is min, 1 angle value is min, otherwise -1
  */
 private short checkAngleIsMinMax(Device device) {
   if (device.getAnglePosition() == device.getMaxSlatAngle()) {
     return 1;
   }
   if (device.getAnglePosition() == device.getMinSlatAngle()) {
     return 1;
   }
   return -1;
 }