log updated TBR records
This commit is contained in:
parent
15a6d27349
commit
d131ceb4bd
|
@ -271,7 +271,7 @@ class PumpSyncImplementation @Inject constructor(
|
|||
.blockingGet()
|
||||
.also { result ->
|
||||
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted TemporaryBasal $it") }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated ${it.first} TemporaryBasal ${it.second}") }
|
||||
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated TemporaryBasal \n${it.first}\n${it.second}") }
|
||||
return result.inserted.size > 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,20 +24,22 @@ class SyncPumpTemporaryBasalTransaction(
|
|||
existing.duration != temporaryBasal.duration && existing.interfaceIDs.endId == null ||
|
||||
existing.type != type ?: existing.type
|
||||
) {
|
||||
val old = existing.copy()
|
||||
existing.timestamp = temporaryBasal.timestamp
|
||||
existing.rate = temporaryBasal.rate
|
||||
existing.duration = temporaryBasal.duration
|
||||
existing.type = type ?: existing.type
|
||||
database.temporaryBasalDao.updateExistingEntry(existing)
|
||||
result.updated.add(Pair(Reason.EXISTING_ID, existing))
|
||||
result.updated.add(Pair(old, existing))
|
||||
}
|
||||
} else {
|
||||
val running = database.temporaryBasalDao.getTemporaryBasalActiveAt(temporaryBasal.timestamp).blockingGet()
|
||||
if (running != null) {
|
||||
val old = running.copy()
|
||||
running.end = temporaryBasal.timestamp
|
||||
running.interfaceIDs.endId = temporaryBasal.interfaceIDs.pumpId
|
||||
database.temporaryBasalDao.updateExistingEntry(running)
|
||||
result.updated.add(Pair(Reason.ACTIVE, running))
|
||||
result.updated.add(Pair(old, running))
|
||||
}
|
||||
database.temporaryBasalDao.insertNewEntry(temporaryBasal)
|
||||
result.inserted.add(temporaryBasal)
|
||||
|
@ -45,12 +47,9 @@ class SyncPumpTemporaryBasalTransaction(
|
|||
return result
|
||||
}
|
||||
|
||||
enum class Reason {
|
||||
EXISTING_ID, ACTIVE
|
||||
}
|
||||
class TransactionResult {
|
||||
|
||||
val inserted = mutableListOf<TemporaryBasal>()
|
||||
val updated = mutableListOf<Pair<Reason,TemporaryBasal>>()
|
||||
val updated = mutableListOf<Pair<TemporaryBasal,TemporaryBasal>>()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue