- refactoring of PumpSyncStorage (two storeages entries instead of one), strongly typed objects

- changes on the code to accept that: MedtronicPumpPlugin, MedtronicHistoryData, MedtronicPumpStatus
This commit is contained in:
Andy Rozman 2021-10-09 22:57:22 +01:00
parent a8895668bd
commit 1391061f1c
5 changed files with 202 additions and 120 deletions

View file

@ -1006,24 +1006,23 @@ class MedtronicPumpPlugin @Inject constructor(
if (medtronicHistoryData.isTBRActive(runningTBR)) { if (medtronicHistoryData.isTBRActive(runningTBR)) {
val differenceTime = System.currentTimeMillis() - runningTBR.date val differenceTime = System.currentTimeMillis() - runningTBR.date
val tbrData = runningTBR.tbrData!! //val tbrData = runningTBR
val result = pumpSync.syncTemporaryBasalWithPumpId( val result = pumpSync.syncTemporaryBasalWithPumpId(
runningTBR.date, runningTBR.date,
tbrData.rate, runningTBR.rate,
differenceTime, differenceTime,
tbrData.isAbsolute, runningTBR.isAbsolute,
tbrData.tbrType, runningTBR.tbrType,
runningTBR.pumpId!!, runningTBR.pumpId!!,
runningTBR.pumpType, runningTBR.pumpType,
runningTBR.serialNumber) runningTBR.serialNumber)
val differenceTimeMin = Math.floor(differenceTime / (60.0 * 1000.0)) val differenceTimeMin = Math.floor(differenceTime / (60.0 * 1000.0))
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "canceling running TBR - syncTemporaryBasalWithPumpId [date=%d, pumpId=%d, rate=%.2f U, duration=%d, pumpSerial=%s] - Result: %b", aapsLogger.debug(LTag.PUMP, "canceling running TBR - syncTemporaryBasalWithPumpId [date=${runningTBR.date}, " +
runningTBR.date, runningTBR.pumpId, "pumpId=${runningTBR.pumpId}, rate=${runningTBR.rate} U, duration=${differenceTimeMin.toInt()}, " +
tbrData.rate, differenceTimeMin.toInt(), "pumpSerial=${medtronicPumpStatus.serialNumber}] - Result: $result")
medtronicPumpStatus.serialNumber, result))
} }
} }

View file

@ -10,6 +10,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryBolus
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
@ -490,17 +491,17 @@ class MedtronicHistoryData @Inject constructor(
var temporaryId: Long? = null var temporaryId: Long? = null
if (!multiwave) { if (!multiwave) {
val entryWithTempId = findDbEntry(bolus, boluses) val entryWithTempId = findDbEntry(bolus, boluses as MutableList<PumpDbEntry>) as PumpDbEntryBolus?
aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId=$entryWithTempId") aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId=$entryWithTempId")
if (entryWithTempId != null) { if (entryWithTempId != null) {
aapsLogger.debug(LTag.PUMP, String.format("DD: entryWithTempId.bolusData=%s", if (entryWithTempId.bolusData == null) "null" else entryWithTempId.bolusData)) //aapsLogger.debug(LTag.PUMP, String.format("DD: entryWithTempId.bolusData=%s", if (entryWithTempId.bolusData == null) "null" else entryWithTempId.bolusData))
temporaryId = entryWithTempId.temporaryId temporaryId = entryWithTempId.temporaryId
pumpSyncStorage.removeBolusWithTemporaryId(temporaryId) pumpSyncStorage.removeBolusWithTemporaryId(temporaryId)
boluses.remove(entryWithTempId) boluses.remove(entryWithTempId)
type = entryWithTempId.bolusData!!.bolusType type = entryWithTempId.bolusType
} }
} }
@ -619,7 +620,7 @@ class MedtronicHistoryData @Inject constructor(
aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemOne: " + gson.toJson(tempBasalProcessDTO.itemOne)) aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemOne: " + gson.toJson(tempBasalProcessDTO.itemOne))
aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemTwo: " + (if (tempBasalProcessDTO.itemTwo == null) "null" else gson.toJson(tempBasalProcessDTO.itemTwo!!))) aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemTwo: " + (if (tempBasalProcessDTO.itemTwo == null) "null" else gson.toJson(tempBasalProcessDTO.itemTwo!!)))
val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords) val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords as MutableList<PumpDbEntry>) as PumpDbEntryTBR?
aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId: " + (if (entryWithTempId == null) "null" else entryWithTempId.toString())) aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId: " + (if (entryWithTempId == null) "null" else entryWithTempId.toString()))
@ -697,16 +698,16 @@ class MedtronicHistoryData @Inject constructor(
if (isTBRActive(startTimestamp = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), if (isTBRActive(startTimestamp = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
durationSeconds = tempBasalProcessDTO.durationAsSeconds)) { durationSeconds = tempBasalProcessDTO.durationAsSeconds)) {
if (medtronicPumpStatus.runningTBR == null) { if (medtronicPumpStatus.runningTBR == null) {
medtronicPumpStatus.runningTBR = info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry(0L, medtronicPumpStatus.runningTBR = PumpDbEntryTBR(
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), temporaryId = 0L,
medtronicPumpStatus.pumpType, date = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
medtronicPumpStatus.serialNumber, pumpType = medtronicPumpStatus.pumpType,
null, serialNumber = medtronicPumpStatus.serialNumber,
PumpDbEntryTBR(rate = tbrEntry.insulinRate, entry = PumpDbEntryTBR(rate = tbrEntry.insulinRate,
isAbsolute = !tbrEntry.isPercent, isAbsolute = !tbrEntry.isPercent,
durationInSeconds = tempBasalProcessDTO.durationAsSeconds, durationInSeconds = tempBasalProcessDTO.durationAsSeconds,
tbrType = PumpSync.TemporaryBasalType.NORMAL), tbrType = PumpSync.TemporaryBasalType.NORMAL),
tempBasalProcessDTO.pumpId) pumpId = tempBasalProcessDTO.pumpId)
} }
} }
} else { } else {
@ -717,10 +718,12 @@ class MedtronicHistoryData @Inject constructor(
} // collection } // collection
} }
fun isTBRActive(dbEntry: PumpDbEntry): Boolean {
fun isTBRActive(dbEntry: PumpDbEntryTBR): Boolean {
return isTBRActive( return isTBRActive(
startTimestamp = dbEntry.date, startTimestamp = dbEntry.date,
durationSeconds = dbEntry.tbrData!!.durationInSeconds) durationSeconds = dbEntry.durationInSeconds)
} }
fun isTBRActive(startTimestamp: Long, durationSeconds: Int): Boolean { fun isTBRActive(startTimestamp: Long, durationSeconds: Int): Boolean {

View file

@ -7,6 +7,7 @@ import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDevic
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BasalProfileStatus import info.nightscout.androidaps.plugins.pump.medtronic.defs.BasalProfileStatus
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType
@ -32,7 +33,7 @@ class MedtronicPumpStatus @Inject constructor(private val resourceHelper: Resour
var pumpFrequency: String? = null var pumpFrequency: String? = null
var maxBolus: Double? = null var maxBolus: Double? = null
var maxBasal: Double? = null var maxBasal: Double? = null
var runningTBR: info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry? = null var runningTBR: PumpDbEntryTBR? = null
// statuses // statuses
var pumpDeviceState = PumpDeviceState.NeverContacted var pumpDeviceState = PumpDeviceState.NeverContacted

View file

@ -4,45 +4,75 @@ import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
data class PumpDbEntry constructor(var temporaryId: Long, // data class PumpDbEntry constructor(var temporaryId: Long,
var date: Long, // var date: Long,
var pumpType: PumpType, // var pumpType: PumpType,
var serialNumber: String, // var serialNumber: String,
var bolusData: PumpDbEntryBolus? = null, // var bolusData: PumpDbEntryBolus? = null,
var tbrData: PumpDbEntryTBR? = null, // var tbrData: PumpDbEntryTBR? = null,
var pumpId: Long? = null) { // var pumpId: Long? = null) {
//
// constructor(temporaryId: Long,
// date: Long,
// pumpType: PumpType,
// serialNumber: String,
// detailedBolusInfo: DetailedBolusInfo) : this(temporaryId, date, pumpType, serialNumber) {
// this.bolusData = PumpDbEntryBolus(
// detailedBolusInfo.insulin,
// detailedBolusInfo.carbs,
// detailedBolusInfo.bolusType)
// }
//
// constructor(temporaryId: Long,
// date: Long,
// pumpType: PumpType,
// serialNumber: String,
// rate: Double,
// isAbsolute: Boolean,
// durationInMinutes: Int,
// tbrType: PumpSync.TemporaryBasalType) : this(temporaryId, date, pumpType, serialNumber) {
// this.tbrData = PumpDbEntryTBR(
// rate,
// isAbsolute,
// durationInMinutes,
// tbrType)
// }
//
// }
constructor(temporaryId: Long,
date: Long,
pumpType: PumpType,
serialNumber: String,
detailedBolusInfo: DetailedBolusInfo) : this(temporaryId, date, pumpType, serialNumber) {
this.bolusData = PumpDbEntryBolus(
detailedBolusInfo.insulin,
detailedBolusInfo.carbs,
detailedBolusInfo.bolusType)
}
constructor(temporaryId: Long,
date: Long,
pumpType: PumpType,
serialNumber: String,
rate: Double,
isAbsolute: Boolean,
durationInMinutes: Int,
tbrType: PumpSync.TemporaryBasalType) : this(temporaryId, date, pumpType, serialNumber) {
this.tbrData = PumpDbEntryTBR(
rate,
isAbsolute,
durationInMinutes,
tbrType)
}
interface PumpDbEntry {
var temporaryId: Long
var date: Long
var pumpType: PumpType
var serialNumber: String
var pumpId: Long?
} }
data class PumpDbEntryBolus(var insulin: Double,
data class PumpDbEntryBolus(override var temporaryId: Long,
override var date: Long,
override var pumpType: PumpType,
override var serialNumber: String,
override var pumpId: Long? = null,
var insulin: Double,
var carbs: Double, var carbs: Double,
var bolusType: DetailedBolusInfo.BolusType) var bolusType: DetailedBolusInfo.BolusType) : PumpDbEntry {
constructor(temporaryId: Long,
date: Long,
pumpType: PumpType,
serialNumber: String,
detailedBolusInfo: DetailedBolusInfo) : this(temporaryId, date, pumpType, serialNumber, null,
detailedBolusInfo.insulin,
detailedBolusInfo.carbs,
detailedBolusInfo.bolusType) {
}
}
data class PumpDbEntryCarbs(var date: Long, data class PumpDbEntryCarbs(var date: Long,
var carbs: Double, var carbs: Double,
@ -57,7 +87,29 @@ data class PumpDbEntryCarbs(var date: Long,
creator.serialNumber()) creator.serialNumber())
} }
data class PumpDbEntryTBR(var rate: Double, data class PumpDbEntryTBR(override var temporaryId: Long,
override var date: Long,
override var pumpType: PumpType,
override var serialNumber: String,
override var pumpId: Long? = null,
var rate: Double,
var isAbsolute: Boolean, var isAbsolute: Boolean,
var durationInSeconds: Int, var durationInSeconds: Int,
var tbrType: PumpSync.TemporaryBasalType) var tbrType: PumpSync.TemporaryBasalType) : PumpDbEntry {
constructor(rate: Double,
isAbsolute: Boolean,
durationInSeconds: Int,
tbrType: PumpSync.TemporaryBasalType) : this(0, 0, PumpType.GENERIC_AAPS, "", null,
rate, isAbsolute, durationInSeconds, tbrType)
constructor(temporaryId: Long,
date: Long,
pumpType: PumpType,
serialNumber: String,
entry: PumpDbEntryTBR,
pumpId: Long?
) : this(temporaryId, date, pumpType, serialNumber, pumpId,
entry.rate, entry.isAbsolute, entry.durationInSeconds, entry.tbrType)
}

View file

@ -22,13 +22,13 @@ class PumpSyncStorage @Inject constructor(
) { ) {
companion object { companion object {
const val pumpSyncStorageBolusKey: String = "pump_sync_storage_bolus"
const val pumpSyncStorageKey: String = "pump_sync_storage_xstream_v2" const val pumpSyncStorageTBRKey: String = "pump_sync_storage_tbr"
const val TBR: String = "TBR"
const val BOLUS: String = "BOLUS"
} }
var pumpSyncStorage: MutableMap<String, MutableList<PumpDbEntry>> = mutableMapOf() var pumpSyncStorageBolus: MutableList<PumpDbEntryBolus> = mutableListOf()
var pumpSyncStorageTBR: MutableList<PumpDbEntryTBR> = mutableListOf()
private var storageInitialized: Boolean = false private var storageInitialized: Boolean = false
private var xstream: XStream = XStream() private var xstream: XStream = XStream()
@ -41,38 +41,58 @@ class PumpSyncStorage @Inject constructor(
if (storageInitialized) if (storageInitialized)
return return
var loaded = false xstream.addPermission(AnyTypePermission.ANY)
if (sp.contains(pumpSyncStorageKey)) { if (sp.contains(pumpSyncStorageBolusKey)) {
val jsonData: String = sp.getString(pumpSyncStorageKey, "") val jsonData: String = sp.getString(pumpSyncStorageBolusKey, "")
if (jsonData.isNotBlank()) { if (jsonData.isNotBlank()) {
xstream.addPermission(AnyTypePermission.ANY)
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
pumpSyncStorage = xstream.fromXML(jsonData, MutableMap::class.java) as MutableMap<String, MutableList<PumpDbEntry>> pumpSyncStorageBolus = xstream.fromXML(jsonData, MutableList::class.java) as
MutableList<PumpDbEntryBolus>
aapsLogger.debug(LTag.PUMP, String.format("Loading Pump Sync Storage: boluses=%d, tbrs=%d.", pumpSyncStorage[BOLUS]!!.size, pumpSyncStorage[TBR]!!.size)) aapsLogger.debug(LTag.PUMP, "Loading Pump Sync Storage Bolus: boluses=${pumpSyncStorageBolus.size}")
aapsLogger.debug(LTag.PUMP, "DD: PumpSyncStorage=$pumpSyncStorage") aapsLogger.debug(LTag.PUMP, "DD: PumpSyncStorageBolus=$pumpSyncStorageBolus")
loaded = true
} }
} }
if (!loaded) { if (sp.contains(pumpSyncStorageTBRKey)) {
pumpSyncStorage[BOLUS] = mutableListOf() val jsonData: String = sp.getString(pumpSyncStorageTBRKey, "")
pumpSyncStorage[TBR] = mutableListOf()
if (jsonData.isNotBlank()) {
@Suppress("UNCHECKED_CAST")
pumpSyncStorageTBR = xstream.fromXML(jsonData, MutableList::class.java) as
MutableList<PumpDbEntryTBR>
aapsLogger.debug(LTag.PUMP, "Loading Pump Sync Storage: tbrs=${pumpSyncStorageTBR.size}.")
aapsLogger.debug(LTag.PUMP, "DD: PumpSyncStorageTBR=$pumpSyncStorageTBR")
}
}
}
fun saveStorageBolus() {
if (!pumpSyncStorageBolus.isEmpty()) {
sp.putString(pumpSyncStorageBolusKey, xstream.toXML(pumpSyncStorageBolus))
aapsLogger.debug(LTag.PUMP,"Saving Pump Sync Storage: boluses=${pumpSyncStorageBolus.size}")
} else {
if (sp.contains(pumpSyncStorageBolusKey))
sp.remove(pumpSyncStorageBolusKey)
} }
} }
fun saveStorage() { fun saveStorageTBR() {
if (!isStorageEmpty()) { if (!pumpSyncStorageTBR.isEmpty()) {
sp.putString(pumpSyncStorageKey, xstream.toXML(pumpSyncStorage)) sp.putString(pumpSyncStorageTBRKey, xstream.toXML(pumpSyncStorageTBR))
aapsLogger.debug(String.format("Saving Pump Sync Storage: boluses=%d, tbrs=%d.", pumpSyncStorage[BOLUS]!!.size, pumpSyncStorage[TBR]!!.size)) aapsLogger.debug(LTag.PUMP, "Saving Pump Sync Storage: tbr=${pumpSyncStorageTBR.size}")
} else {
if (sp.contains(pumpSyncStorageTBRKey))
sp.remove(pumpSyncStorageTBRKey)
} }
} }
private fun cleanOldStorage() { private fun cleanOldStorage() {
val oldSpKeys = setOf("pump_sync_storage", "pump_sync_storage_xstream") val oldSpKeys = setOf("pump_sync_storage", "pump_sync_storage_xstream", "pump_sync_storage_xstream_v2")
for (oldSpKey in oldSpKeys) { for (oldSpKey in oldSpKeys) {
if (sp.contains(oldSpKey)) if (sp.contains(oldSpKey))
@ -80,16 +100,12 @@ class PumpSyncStorage @Inject constructor(
} }
} }
private fun isStorageEmpty(): Boolean { fun getBoluses(): MutableList<PumpDbEntryBolus> {
return pumpSyncStorage[BOLUS]!!.isEmpty() && pumpSyncStorage[TBR]!!.isEmpty() return pumpSyncStorageBolus
} }
fun getBoluses(): MutableList<PumpDbEntry> { fun getTBRs(): MutableList<PumpDbEntryTBR> {
return pumpSyncStorage[BOLUS]!! return pumpSyncStorageTBR
}
fun getTBRs(): MutableList<PumpDbEntry> {
return pumpSyncStorage[TBR]!!
} }
fun addBolusWithTempId(detailedBolusInfo: DetailedBolusInfo, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator): Boolean { fun addBolusWithTempId(detailedBolusInfo: DetailedBolusInfo, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator): Boolean {
@ -102,24 +118,25 @@ class PumpSyncStorage @Inject constructor(
creator.model(), creator.model(),
creator.serialNumber()) creator.serialNumber())
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "addBolusWithTempId [date=%d, temporaryId=%d, insulin=%.2f, type=%s, pumpSerial=%s] - Result: %b", aapsLogger.debug(LTag.PUMP, "addBolusWithTempId [date=${detailedBolusInfo.timestamp}, temporaryId=$temporaryId, " +
detailedBolusInfo.timestamp, temporaryId, detailedBolusInfo.insulin, detailedBolusInfo.bolusType, "insulin=${detailedBolusInfo.insulin}, type=${detailedBolusInfo.bolusType}, pumpSerial=${creator.serialNumber()}] - " +
creator.serialNumber(), result)) "Result: $result")
if (detailedBolusInfo.carbs > 0.0) { if (detailedBolusInfo.carbs > 0.0) {
addCarbs(PumpDbEntryCarbs(detailedBolusInfo, creator)) addCarbs(PumpDbEntryCarbs(detailedBolusInfo, creator))
} }
if (result && writeToInternalHistory) { if (result && writeToInternalHistory) {
val innerList: MutableList<PumpDbEntry> = pumpSyncStorage[BOLUS]!! val dbEntry = PumpDbEntryBolus(temporaryId = temporaryId,
date = detailedBolusInfo.timestamp,
pumpType = creator.model(),
serialNumber = creator.serialNumber(),
detailedBolusInfo = detailedBolusInfo)
val dbEntry = PumpDbEntry(temporaryId, detailedBolusInfo.timestamp, creator.model(), creator.serialNumber(), detailedBolusInfo) aapsLogger.debug("PumpDbEntryBolus: $dbEntry")
aapsLogger.debug("PumpDbEntry: $dbEntry") pumpSyncStorageBolus.add(dbEntry)
saveStorageBolus()
innerList.add(dbEntry)
pumpSyncStorage[BOLUS] = innerList
saveStorage()
} }
return result return result
} }
@ -132,8 +149,8 @@ class PumpSyncStorage @Inject constructor(
carbsDto.pumpType, carbsDto.pumpType,
carbsDto.serialNumber) carbsDto.serialNumber)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncCarbsWithTimestamp [date=%d, carbs=%.2f, pumpSerial=%s] - Result: %b", aapsLogger.debug(LTag.PUMP, "syncCarbsWithTimestamp [date=${carbsDto.date}, " +
carbsDto.date, carbsDto.carbs, carbsDto.serialNumber, result)) "carbs=${carbsDto.carbs}, pumpSerial=${carbsDto.serialNumber}] - Result: $result")
} }
fun addTemporaryBasalRateWithTempId(temporaryBasal: PumpDbEntryTBR, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator): Boolean { fun addTemporaryBasalRateWithTempId(temporaryBasal: PumpDbEntryTBR, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator): Boolean {
@ -151,42 +168,52 @@ class PumpSyncStorage @Inject constructor(
creator.serialNumber()) creator.serialNumber())
if (response && writeToInternalHistory) { if (response && writeToInternalHistory) {
val innerList: MutableList<PumpDbEntry> = pumpSyncStorage[TBR]!! val dbEntry = PumpDbEntryTBR(temporaryId = temporaryId,
date = timeNow,
pumpType = creator.model(),
serialNumber = creator.serialNumber(),
entry = temporaryBasal,
pumpId=null)
innerList.add(PumpDbEntry(temporaryId, timeNow, creator.model(), creator.serialNumber(), null, temporaryBasal)) aapsLogger.debug("PumpDbEntryTBR: $dbEntry")
pumpSyncStorage[BOLUS] = innerList
saveStorage() pumpSyncStorageTBR.add(dbEntry)
saveStorageTBR()
} }
return response return response
} }
fun removeBolusWithTemporaryId(temporaryId: Long) { fun removeBolusWithTemporaryId(temporaryId: Long) {
val bolusList = removeTemporaryId(temporaryId, pumpSyncStorage[BOLUS]!!) var dbEntry: PumpDbEntryBolus? = null
pumpSyncStorage[BOLUS] = bolusList
saveStorage()
}
fun removeTemporaryBasalWithTemporaryId(temporaryId: Long) { for (pumpDbEntry in pumpSyncStorageBolus) {
val tbrList = removeTemporaryId(temporaryId, pumpSyncStorage[TBR]!!)
pumpSyncStorage[TBR] = tbrList
saveStorage()
}
private fun removeTemporaryId(temporaryId: Long, list: MutableList<PumpDbEntry>): MutableList<PumpDbEntry> {
var dbEntry: PumpDbEntry? = null
for (pumpDbEntry in list) {
if (pumpDbEntry.temporaryId == temporaryId) { if (pumpDbEntry.temporaryId == temporaryId) {
dbEntry = pumpDbEntry dbEntry = pumpDbEntry
} }
} }
if (dbEntry != null) { if (dbEntry != null) {
list.remove(dbEntry) pumpSyncStorageBolus.remove(dbEntry)
} }
return list saveStorageBolus()
}
fun removeTemporaryBasalWithTemporaryId(temporaryId: Long) {
var dbEntry: PumpDbEntryTBR? = null
for (pumpDbEntry in pumpSyncStorageTBR) {
if (pumpDbEntry.temporaryId == temporaryId) {
dbEntry = pumpDbEntry
}
}
if (dbEntry != null) {
pumpSyncStorageTBR.remove(dbEntry)
}
saveStorageTBR()
} }
} }