diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/DataSyncSelectorImplementation.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/DataSyncSelectorImplementation.kt index e726c41d01..697192f485 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/DataSyncSelectorImplementation.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/DataSyncSelectorImplementation.kt @@ -374,6 +374,7 @@ class DataSyncSelectorImplementation @Inject constructor( private var lastTbrId = -1L private var lastTbrTime = -1L override fun processChangedTemporaryBasalsCompat(): Boolean { + val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false) val startId = sp.getLong(R.string.key_ns_temporary_basal_last_synced_id, 0) if (startId == lastTbrId && dateUtil.now() - lastTbrTime < 5000) return false lastTbrId = startId @@ -384,10 +385,10 @@ class DataSyncSelectorImplementation @Inject constructor( when { // without nsId = create new tb.first.interfaceIDs.nightscoutId == null -> - nsClientPlugin.nsClientService?.dbAdd("treatments", tb.first.toJson(profile, dateUtil), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second)) + nsClientPlugin.nsClientService?.dbAdd("treatments", tb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second)) // with nsId = update tb.first.interfaceIDs.nightscoutId != null -> - nsClientPlugin.nsClientService?.dbUpdate("treatments", tb.first.interfaceIDs.nightscoutId, tb.first.toJson(profile, dateUtil), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second)) + nsClientPlugin.nsClientService?.dbUpdate("treatments", tb.first.interfaceIDs.nightscoutId, tb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second)) } return true } ?: confirmLastTemporaryBasalIdIfGreater(tb.second) @@ -413,6 +414,7 @@ class DataSyncSelectorImplementation @Inject constructor( private var lastEbId = -1L private var lastEbTime = -1L override fun processChangedExtendedBolusesCompat(): Boolean { + val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false) val startId = sp.getLong(R.string.key_ns_extended_bolus_last_synced_id, 0) if (startId == lastEbId && dateUtil.now() - lastEbTime < 5000) return false lastEbId = startId @@ -423,10 +425,10 @@ class DataSyncSelectorImplementation @Inject constructor( when { // without nsId = create new eb.first.interfaceIDs.nightscoutId == null -> - nsClientPlugin.nsClientService?.dbAdd("treatments", eb.first.toJson(profile, dateUtil), DataSyncSelector.PairExtendedBolus(eb.first, eb.second)) + nsClientPlugin.nsClientService?.dbAdd("treatments", eb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second)) // with nsId = update eb.first.interfaceIDs.nightscoutId != null -> - nsClientPlugin.nsClientService?.dbUpdate("treatments", eb.first.interfaceIDs.nightscoutId, eb.first.toJson(profile, dateUtil), DataSyncSelector.PairExtendedBolus(eb.first, eb.second)) + nsClientPlugin.nsClientService?.dbUpdate("treatments", eb.first.interfaceIDs.nightscoutId, eb.first.toJson(profile, dateUtil, useAbsolute), DataSyncSelector.PairExtendedBolus(eb.first, eb.second)) } return true } ?: confirmLastExtendedBolusIdIfGreater(eb.second) diff --git a/core/src/main/java/info/nightscout/androidaps/extensions/ExtendedBolusExtension.kt b/core/src/main/java/info/nightscout/androidaps/extensions/ExtendedBolusExtension.kt index df0802ed19..09f5c9d9a5 100644 --- a/core/src/main/java/info/nightscout/androidaps/extensions/ExtendedBolusExtension.kt +++ b/core/src/main/java/info/nightscout/androidaps/extensions/ExtendedBolusExtension.kt @@ -50,10 +50,10 @@ fun ExtendedBolus.toTemporaryBasal(profile: Profile): TemporaryBasal = type = TemporaryBasal.Type.FAKE_EXTENDED ) -fun ExtendedBolus.toJson(profile: Profile, dateUtil: DateUtil): JSONObject = +fun ExtendedBolus.toJson(profile: Profile, dateUtil: DateUtil, useAbsolute: Boolean): JSONObject = if (isEmulatingTempBasal) toTemporaryBasal(profile) - .toJson(profile, dateUtil) + .toJson(profile, dateUtil, useAbsolute) .put("extendedEmulated", toRealJson(dateUtil)) else toRealJson(dateUtil) diff --git a/core/src/main/java/info/nightscout/androidaps/extensions/TemporaryBasalExtension.kt b/core/src/main/java/info/nightscout/androidaps/extensions/TemporaryBasalExtension.kt index e25a6284d1..2522f930b4 100644 --- a/core/src/main/java/info/nightscout/androidaps/extensions/TemporaryBasalExtension.kt +++ b/core/src/main/java/info/nightscout/androidaps/extensions/TemporaryBasalExtension.kt @@ -62,7 +62,7 @@ fun TemporaryBasal.toStringFull(profile: Profile, dateUtil: DateUtil): String { } } -fun TemporaryBasal.toJson(profile: Profile, dateUtil: DateUtil): JSONObject = +fun TemporaryBasal.toJson(profile: Profile, dateUtil: DateUtil, useAbsolute: Boolean): JSONObject = JSONObject() .put("created_at", dateUtil.toISOString(timestamp)) .put("enteredBy", "openaps://" + "AndroidAPS") @@ -71,7 +71,7 @@ fun TemporaryBasal.toJson(profile: Profile, dateUtil: DateUtil): JSONObject = .put("rate", rate) .put("type", type.name) .also { - if (isAbsolute) it.put("absolute", rate) + if (useAbsolute) it.put("absolute", convertedToAbsolute(timestamp, profile)) else it.put("percent", convertedToPercent(timestamp, profile) - 100) if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId) if (interfaceIDs.endId != null) it.put("endId", interfaceIDs.endId)