- some cleanup
- prelim work on TBR
This commit is contained in:
parent
a3f0bf41cd
commit
5bd41d9abd
|
@ -1,6 +1,8 @@
|
|||
package info.nightscout.androidaps.plugins.pump.common.sync
|
||||
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||
import info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.interfaces.PumpSync
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
||||
|
||||
|
||||
|
@ -21,6 +23,22 @@ data class PumpDbEntry constructor(var temporaryId: Long,
|
|||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,4 +58,7 @@ data class PumpDbEntryCarbs(var date: Long,
|
|||
creator.serialNumber())
|
||||
}
|
||||
|
||||
data class PumpDbEntryTBR(var temporaryId: Long)
|
||||
data class PumpDbEntryTBR(var rate: Double,
|
||||
var isAbsolute: Boolean,
|
||||
var durationInMinutes: Int,
|
||||
var tbrType: PumpSync.TemporaryBasalType)
|
|
@ -130,19 +130,24 @@ class PumpSyncStorage @Inject constructor(
|
|||
}
|
||||
|
||||
// TODO
|
||||
fun addTemporaryBasalRateWithTempId(temporaryBasal: TemporaryBasal, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator) : Boolean {
|
||||
// val temporaryId = generateTempId(temporaryBasal.date)
|
||||
// val response = pumpSync.addBolusWithTempId(temporaryBasal.timestamp, detailedBolusInfo.insulin,
|
||||
fun addTemporaryBasalRateWithTempId(temporaryBasal: PumpDbEntryTBR, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator) : Boolean {
|
||||
val timenow : Long = System.currentTimeMillis()
|
||||
|
||||
val temporaryId = creator.generateTempId(timenow)
|
||||
val response = false
|
||||
// pumpSync.addBolusWithTempId(temporaryBasal.timestamp, detailedBolusInfo.insulin,
|
||||
// generateTempId(detailedBolusInfo.timestamp), detailedBolusInfo.getBolusType(),
|
||||
// getPumpType(), serialNumber());
|
||||
//
|
||||
// if (response && writeToInternalHistory) {
|
||||
// driverHistory.put(temporaryId, new PumpDbEntry(temporaryId, model(), serialNumber(), detailedBolusInfo));
|
||||
// sp.putString(MedtronicConst.Statistics.InternalTemporaryDatabase, gson.toJson(driverHistory));
|
||||
// }
|
||||
//
|
||||
// return response;
|
||||
return false
|
||||
|
||||
if (response && writeToInternalHistory) {
|
||||
var innerList: MutableList<PumpDbEntry> = pumpSyncStorage[TBR]!!
|
||||
|
||||
innerList.add(PumpDbEntry(temporaryId, timenow, creator.model(), creator.serialNumber(), null, temporaryBasal))
|
||||
pumpSyncStorage[BOLUS] = innerList
|
||||
saveStorage()
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.Riley
|
|||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask
|
||||
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry
|
||||
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR
|
||||
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncEntriesCreator
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
|
||||
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage
|
||||
|
@ -354,7 +356,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
// execute
|
||||
val refreshTypesNeededToReschedule: MutableSet<MedtronicStatusRefreshType?> = HashSet()
|
||||
val refreshTypesNeededToReschedule: MutableSet<MedtronicStatusRefreshType?> = mutableSetOf()
|
||||
for ((key, value) in statusRefresh!!) {
|
||||
if (value!! > 0 && System.currentTimeMillis() > value) {
|
||||
when (key) {
|
||||
|
@ -635,13 +637,6 @@ class MedtronicPumpPlugin @Inject constructor(
|
|||
|
||||
pumpSyncStorage.addBolusWithTempId(detailedBolusInfo, true, this)
|
||||
|
||||
// // TODO fix
|
||||
// if (usePumpSync) {
|
||||
// pumpSyncStorage.addBolusWithTempId(detailedBolusInfo, true, this)
|
||||
// } else {
|
||||
// activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, true)
|
||||
// }
|
||||
|
||||
// we subtract insulin, exact amount will be visible with next remainingInsulin update.
|
||||
medtronicPumpStatus.reservoirRemainingUnits = medtronicPumpStatus.reservoirRemainingUnits - detailedBolusInfo.insulin
|
||||
incrementStatistics(if (detailedBolusInfo.bolusType === DetailedBolusInfo.BolusType.SMB) MedtronicConst.Statistics.SMBBoluses else MedtronicConst.Statistics.StandardBoluses)
|
||||
|
@ -771,12 +766,12 @@ class MedtronicPumpPlugin @Inject constructor(
|
|||
.absolute(absoluteRate) //
|
||||
.source(Source.USER)
|
||||
|
||||
// TODO fix
|
||||
if (usePumpSync) {
|
||||
pumpSyncStorage.addTemporaryBasalRateWithTempId(tempStart, true, this)
|
||||
} else {
|
||||
activePlugin.activeTreatments.addToHistoryTempBasal(tempStart)
|
||||
}
|
||||
activePlugin.activeTreatments.addToHistoryTempBasal(tempStart)
|
||||
|
||||
// val tempData = PumpDbEntryTBR(absoluteRate, true, durationInMinutes, tbrType)
|
||||
//
|
||||
// pumpSyncStorage.addTemporaryBasalRateWithTempId(tempData, true, this)
|
||||
|
||||
incrementStatistics(MedtronicConst.Statistics.TBRsSet)
|
||||
finishAction("TBR")
|
||||
PumpEnactResult(injector).success(true).enacted(true) //
|
||||
|
@ -1016,12 +1011,13 @@ class MedtronicPumpPlugin @Inject constructor(
|
|||
.duration(0) //
|
||||
.source(Source.USER)
|
||||
|
||||
// TODO fix
|
||||
if (usePumpSync) {
|
||||
pumpSyncStorage.addTemporaryBasalRateWithTempId(tempBasal, true, this)
|
||||
} else {
|
||||
activePlugin.activeTreatments.addToHistoryTempBasal(tempBasal)
|
||||
}
|
||||
activePlugin.activeTreatments.addToHistoryTempBasal(tempBasal)
|
||||
|
||||
// TODO need to find solution for this !?
|
||||
// val tempData = PumpDbEntryTBR(absoluteRate, true, durationInMinutes, tbrType)
|
||||
//
|
||||
// pumpSyncStorage.addTemporaryBasalRateWithTempId(tempData, true, this)
|
||||
|
||||
PumpEnactResult(injector).success(true).enacted(true) //
|
||||
.isTempCancel(true)
|
||||
} else {
|
||||
|
|
|
@ -42,6 +42,10 @@ import javax.inject.Singleton
|
|||
// needs to include not returning any records if TZ goes into -x area. To fully support this AAPS would need to take note of
|
||||
// all times that time changed (TZ, DST, etc.). Data needs to be returned in batches (time_changed batches, so that we can
|
||||
// handle it. It would help to assign sort_ids to items (from oldest (1) to newest (x)
|
||||
//
|
||||
// TODO New Database changes, we need to read 35 minutes from history on each read and then compare if items have the same
|
||||
// amounts, if not send them back to database changes. ALSO we need to remove and invalidate TBRs that are cancels from
|
||||
// PumpSyncStorage
|
||||
@Suppress("DEPRECATION")
|
||||
@Singleton
|
||||
class MedtronicHistoryData @Inject constructor(
|
||||
|
|
Loading…
Reference in a new issue