Added sleep function to delay until device status change before returning result