Merge pull request #513 from Philoul/Fix_NSClient_UseAbsolute

NSClient Fix Use Absolute
This commit is contained in:
Milos Kozak 2021-05-13 17:46:21 +02:00 committed by GitHub
commit b2281b83e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 8 deletions

View file

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

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)