NSClient Fix Use Absolute

This commit is contained in:
Philoul 2021-05-12 18:28:52 +02:00
parent bcd74897d4
commit 9d87dec574
3 changed files with 10 additions and 8 deletions

View file

@ -368,6 +368,7 @@ class DataSyncSelectorImplementation @Inject constructor(
override fun processChangedTemporaryBasalsCompat(): Boolean {
val startId = sp.getLong(R.string.key_ns_temporary_basal_last_synced_id, 0)
val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false)
appRepository.getNextSyncElementTemporaryBasal(startId).blockingGet()?.let { tb ->
aapsLogger.info(LTag.DATABASE, "Loading TemporaryBasal data Start: $startId ID: ${tb.first.id} HistoryID: ${tb.second} ")
profileFunction.getProfile(tb.first.timestamp)?.let { profile ->
@ -379,10 +380,10 @@ class DataSyncSelectorImplementation @Inject constructor(
nsClientPlugin.nsClientService?.dbRemove("treatments", tb.first.interfaceIDs.nightscoutId, DataSyncSelector.PairTemporaryBasal(tb.first, tb.second))
// existing without nsId = create new
tb.first.isValid && 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))
// existing with nsId = update
tb.first.isValid && 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)
@ -407,6 +408,7 @@ class DataSyncSelectorImplementation @Inject constructor(
override fun processChangedExtendedBolusesCompat(): Boolean {
val startId = sp.getLong(R.string.key_ns_extended_bolus_last_synced_id, 0)
val useAbsolute = sp.getBoolean(R.string.key_ns_sync_use_absolute, false)
appRepository.getNextSyncElementExtendedBolus(startId).blockingGet()?.let { eb ->
aapsLogger.info(LTag.DATABASE, "Loading ExtendedBolus data Start: $startId ID: ${eb.first.id} HistoryID: ${eb.second} ")
profileFunction.getProfile(eb.first.timestamp)?.let { profile ->
@ -418,10 +420,10 @@ class DataSyncSelectorImplementation @Inject constructor(
nsClientPlugin.nsClientService?.dbRemove("treatments", eb.first.interfaceIDs.nightscoutId, DataSyncSelector.PairExtendedBolus(eb.first, eb.second))
// existing without nsId = create new
eb.first.isValid && 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))
// existing with nsId = update
eb.first.isValid && 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)

View file

@ -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)

View file

@ -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)