From 517b9a9fa7a64e0f2270271ff2e41860d678a392 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 7 Dec 2019 18:14:32 +0100 Subject: [PATCH] Handle NS TempTarget sync properly --- .../info/nightscout/androidaps/db/DatabaseHelper.java | 5 +++-- .../androidaps/plugins/general/nsclient/NSUpload.java | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index d8926fc4c1..92081c1872 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.db; import android.content.Context; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; + import androidx.annotation.Nullable; import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; @@ -772,8 +773,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TempTarget tempTarget = new TempTarget() .date(trJson.getLong("mills")) .duration(JsonHelper.safeGetInt(trJson, "duration")) - .low(Profile.toMgdl(trJson.getDouble("targetBottom"), units)) - .high(Profile.toMgdl(trJson.getDouble("targetTop"), units)) + .low(Profile.toMgdl(JsonHelper.safeGetDouble(trJson, "targetBottom"), units)) + .high(Profile.toMgdl(JsonHelper.safeGetDouble(trJson, "targetTop"), units)) .reason(JsonHelper.safeGetString(trJson, "reason", "")) ._id(trJson.getString("_id")) .source(Source.NIGHTSCOUT); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java index 582eedb0e7..49e33c8215 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java @@ -315,11 +315,13 @@ public class NSUpload { JSONObject data = new JSONObject(); data.put("eventType", CareportalEvent.TEMPORARYTARGET); data.put("duration", tempTarget.durationInMinutes); - data.put("reason", tempTarget.reason); - data.put("targetBottom", Profile.fromMgdlToUnits(tempTarget.low, ProfileFunctions.getSystemUnits())); - data.put("targetTop", Profile.fromMgdlToUnits(tempTarget.high, ProfileFunctions.getSystemUnits())); + if (tempTarget.low > 0) { + data.put("reason", tempTarget.reason); + data.put("targetBottom", Profile.fromMgdlToUnits(tempTarget.low, ProfileFunctions.getSystemUnits())); + data.put("targetTop", Profile.fromMgdlToUnits(tempTarget.high, ProfileFunctions.getSystemUnits())); + data.put("units", ProfileFunctions.getSystemUnits()); + } data.put("created_at", DateUtil.toISOString(tempTarget.date)); - data.put("units", ProfileFunctions.getSystemUnits()); data.put("enteredBy", MainApp.gs(R.string.app_name)); uploadCareportalEntryToNS(data); } catch (JSONException e) {