NSClient Fix Use Absolute
This commit is contained in:
parent
bcd74897d4
commit
9d87dec574
3 changed files with 10 additions and 8 deletions
|
@ -368,6 +368,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
|
|
||||||
override fun processChangedTemporaryBasalsCompat(): Boolean {
|
override fun processChangedTemporaryBasalsCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_temporary_basal_last_synced_id, 0)
|
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 ->
|
appRepository.getNextSyncElementTemporaryBasal(startId).blockingGet()?.let { tb ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading TemporaryBasal data Start: $startId ID: ${tb.first.id} HistoryID: ${tb.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading TemporaryBasal data Start: $startId ID: ${tb.first.id} HistoryID: ${tb.second} ")
|
||||||
profileFunction.getProfile(tb.first.timestamp)?.let { profile ->
|
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))
|
nsClientPlugin.nsClientService?.dbRemove("treatments", tb.first.interfaceIDs.nightscoutId, DataSyncSelector.PairTemporaryBasal(tb.first, tb.second))
|
||||||
// existing without nsId = create new
|
// existing without nsId = create new
|
||||||
tb.first.isValid && tb.first.interfaceIDs.nightscoutId == null ->
|
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
|
// existing with nsId = update
|
||||||
tb.first.isValid && tb.first.interfaceIDs.nightscoutId != null ->
|
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
|
return true
|
||||||
} ?: confirmLastTemporaryBasalIdIfGreater(tb.second)
|
} ?: confirmLastTemporaryBasalIdIfGreater(tb.second)
|
||||||
|
@ -407,6 +408,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
||||||
|
|
||||||
override fun processChangedExtendedBolusesCompat(): Boolean {
|
override fun processChangedExtendedBolusesCompat(): Boolean {
|
||||||
val startId = sp.getLong(R.string.key_ns_extended_bolus_last_synced_id, 0)
|
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 ->
|
appRepository.getNextSyncElementExtendedBolus(startId).blockingGet()?.let { eb ->
|
||||||
aapsLogger.info(LTag.DATABASE, "Loading ExtendedBolus data Start: $startId ID: ${eb.first.id} HistoryID: ${eb.second} ")
|
aapsLogger.info(LTag.DATABASE, "Loading ExtendedBolus data Start: $startId ID: ${eb.first.id} HistoryID: ${eb.second} ")
|
||||||
profileFunction.getProfile(eb.first.timestamp)?.let { profile ->
|
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))
|
nsClientPlugin.nsClientService?.dbRemove("treatments", eb.first.interfaceIDs.nightscoutId, DataSyncSelector.PairExtendedBolus(eb.first, eb.second))
|
||||||
// existing without nsId = create new
|
// existing without nsId = create new
|
||||||
eb.first.isValid && eb.first.interfaceIDs.nightscoutId == null ->
|
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
|
// existing with nsId = update
|
||||||
eb.first.isValid && eb.first.interfaceIDs.nightscoutId != null ->
|
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
|
return true
|
||||||
} ?: confirmLastExtendedBolusIdIfGreater(eb.second)
|
} ?: confirmLastExtendedBolusIdIfGreater(eb.second)
|
||||||
|
|
|
@ -50,10 +50,10 @@ fun ExtendedBolus.toTemporaryBasal(profile: Profile): TemporaryBasal =
|
||||||
type = TemporaryBasal.Type.FAKE_EXTENDED
|
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)
|
if (isEmulatingTempBasal)
|
||||||
toTemporaryBasal(profile)
|
toTemporaryBasal(profile)
|
||||||
.toJson(profile, dateUtil)
|
.toJson(profile, dateUtil, useAbsolute)
|
||||||
.put("extendedEmulated", toRealJson(dateUtil))
|
.put("extendedEmulated", toRealJson(dateUtil))
|
||||||
else toRealJson(dateUtil)
|
else toRealJson(dateUtil)
|
||||||
|
|
||||||
|
|
|
@ -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()
|
JSONObject()
|
||||||
.put("created_at", dateUtil.toISOString(timestamp))
|
.put("created_at", dateUtil.toISOString(timestamp))
|
||||||
.put("enteredBy", "openaps://" + "AndroidAPS")
|
.put("enteredBy", "openaps://" + "AndroidAPS")
|
||||||
|
@ -71,7 +71,7 @@ fun TemporaryBasal.toJson(profile: Profile, dateUtil: DateUtil): JSONObject =
|
||||||
.put("rate", rate)
|
.put("rate", rate)
|
||||||
.put("type", type.name)
|
.put("type", type.name)
|
||||||
.also {
|
.also {
|
||||||
if (isAbsolute) it.put("absolute", rate)
|
if (useAbsolute) it.put("absolute", convertedToAbsolute(timestamp, profile))
|
||||||
else it.put("percent", convertedToPercent(timestamp, profile) - 100)
|
else it.put("percent", convertedToPercent(timestamp, profile) - 100)
|
||||||
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
|
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
|
||||||
if (interfaceIDs.endId != null) it.put("endId", interfaceIDs.endId)
|
if (interfaceIDs.endId != null) it.put("endId", interfaceIDs.endId)
|
||||||
|
|
Loading…
Reference in a new issue