/**
   * delete a channel from the database
   *
   * @param parent device which was deleted and who's channels should be deleted as well
   * @return if deleted
   */
  public static Boolean deleteChannel(long parent) {
    // get all channels
    Cursor cursor =
        homeMaticDatabase.query(
            DatabaseHelper.TABLE_CHANNEL,
            allColumnsChannel,
            DatabaseHelper.COLUMN_CHANNEL_PARENT_DEVICE + " = " + '"' + parent + '"',
            null,
            null,
            null,
            null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
      Channel channel = cursorToChannel(cursor);
      List<Position> positions = getAllPositions();
      for (int i = 0; i < positions.size(); i++) {
        if (positions.get(i).getChannel_id().equals(String.valueOf(channel.get_id()))) {
          // delete it's position entry
          deletePosition(positions.get(i));
        }
      }

      // delete channel from database
      homeMaticDatabase.delete(
          DatabaseHelper.TABLE_CHANNEL,
          DatabaseHelper.COLUMN_CHANNEL_ID + " = " + channel.get_id(),
          null);
      // delete its values
      deleteValue(channel.get_id());
      cursor.moveToNext();
    }
    return true;
  }
  /**
   * create a new position for a channel and edit that channel
   *
   * @param name new name of the channel
   * @param channel the channel as object
   * @param x_coord x coordinate of the new position
   * @param y_coord y coordinate
   * @param buffer
   * @param room
   * @param function
   */
  public static void createPosition(
      String name,
      Channel channel,
      String x_coord,
      String y_coord,
      int buffer,
      String room,
      String function) {
    ContentValues values = new ContentValues();
    values.put(DatabaseHelper.COLUMN_POSITION_CHANNEL_ID, channel.get_id());
    values.put(DatabaseHelper.COLUMN_POSITION_X_COORD, x_coord);
    values.put(DatabaseHelper.COLUMN_POSITION_Y_COORD, y_coord);
    values.put(DatabaseHelper.COLUMN_POSITION_SIZE, buffer);
    homeMaticDatabase.insert(DatabaseHelper.TABLE_POSITION, null, values);
    // NanoHTTPD.myOut.println("position: " + insertId);

    ContentValues contentValues = new ContentValues();
    contentValues.put(DatabaseHelper.COLUMN_CHANNEL_NAME, name);
    contentValues.put(DatabaseHelper.COLUMN_CHANNEL_FUNCTION_ID, function);
    contentValues.put(DatabaseHelper.COLUMN_CHANNEL_ROOM_ID, room);
    homeMaticDatabase.update(
        DatabaseHelper.TABLE_CHANNEL, contentValues, "_id=" + channel.get_id(), null);
  }
  /**
   * creates the value entries for the channel
   *
   * @param datapoints used as blueprint
   * @param channel used as link in channel_id
   */
  public static void createValue(List<DataPoint> datapoints, Channel channel) {
    // for each datapoint a value entry is created
    for (int i = 0; i < datapoints.size(); i++) {
      ContentValues values = new ContentValues();

      // values for the value entry
      values.put(DatabaseHelper.COLUMN_VALUE_NAME, datapoints.get(i).getName());
      values.put(DatabaseHelper.COLUMN_VALUE_VALUE_TYPE, "4");
      values.put(DatabaseHelper.COLUMN_VALUE_STATE, datapoints.get(i).getStdValue());
      values.put(DatabaseHelper.COLUMN_VALUE_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
      values.put(DatabaseHelper.COLUMN_VALUE_CHANNEL_ID, channel.get_id());
      values.put(DatabaseHelper.COLUMN_VALUE_DP_ID, datapoints.get(i).get_id());
      // insert into database
      homeMaticDatabase.insert(DatabaseHelper.TABLE_VALUE, null, values);
    }
  }
 /**
  * returns all entries of the table as List<type>
  *
  * @return List<type> of all database entries
  */
 public static List<Value> getMyValues(Channel channel) {
   List<Value> values = new ArrayList<Value>();
   Cursor cursor =
       homeMaticDatabase.query(
           DatabaseHelper.TABLE_VALUE,
           allColumnsValue,
           DatabaseHelper.COLUMN_VALUE_CHANNEL_ID + " = " + '"' + channel.get_id() + '"',
           null,
           null,
           null,
           null);
   cursor.moveToFirst();
   while (!cursor.isAfterLast()) {
     Value value = cursorToValue(cursor);
     values.add(value);
     cursor.moveToNext();
     // NanoHTTPD.myOut.println(value.getName());
   }
   return values;
 }