- fixed events from history

- added some additional logging for TBR handling
- changed PumpSyncStorage to use xstream instead json
This commit is contained in:
Andy Rozman 2021-05-15 20:24:23 +01:00
parent a4be23d5ad
commit f37b954ae6
3 changed files with 15 additions and 10 deletions

View file

@ -18,5 +18,9 @@ android {
dependencies {
implementation project(':database')
implementation ('com.thoughtworks.xstream:xstream:1.4.7') {
exclude group: 'xmlpull', module: 'xmlpull'
}
}

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.common.sync
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import com.thoughtworks.xstream.XStream
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.logging.AAPSLogger
@ -23,12 +24,13 @@ class PumpSyncStorage @Inject constructor(
val aapsLogger: AAPSLogger
) {
val pumpSyncStorageKey: String = "pump_sync_storage"
val pumpSyncStorageKey: String = "pump_sync_storage_xstream"
var pumpSyncStorage: MutableMap<String,MutableList<PumpDbEntry>> = mutableMapOf()
var TBR: String = "TBR"
var BOLUS: String = "BOLUS"
var storageInitialized: Boolean = false
var gson: Gson = GsonBuilder().create()
var xstream: XStream = XStream()
init {
@ -43,15 +45,10 @@ class PumpSyncStorage @Inject constructor(
var loaded = false
if (sp.contains(pumpSyncStorageKey)) {
val jsonData: String = sp.getString("pump_sync_storage", "");
val jsonData: String = sp.getString(pumpSyncStorageKey, "");
if (!jsonData.isBlank()) {
val pumpSyncStorageType: Type = object : TypeToken<MutableMap<String, MutableList<PumpDbEntry>>>() {}.getType()
val baseMap: MutableMap<String, MutableList<PumpDbEntry>> = gson.fromJson(jsonData, pumpSyncStorageType) //as MutableMap<String, MutableList<PumpDbEntry>>
pumpSyncStorage = baseMap
pumpSyncStorage = xstream.fromXML(jsonData, MutableMap::class.java) as MutableMap<String, MutableList<PumpDbEntry>>
aapsLogger.debug(String.format("Loading Pump Sync Storage: boluses=%d, tbrs=%d.", pumpSyncStorage[BOLUS]!!.size, pumpSyncStorage[TBR]!!.size))
loaded = true
@ -67,7 +64,7 @@ class PumpSyncStorage @Inject constructor(
fun saveStorage() {
if (!isStorageEmpty()) {
sp.putString(pumpSyncStorageKey, gson.toJson(pumpSyncStorage))
sp.putString(pumpSyncStorageKey, xstream.toXML(pumpSyncStorage))
aapsLogger.debug(String.format("Saving Pump Sync Storage: boluses=%d, tbrs=%d.", pumpSyncStorage[BOLUS]!!.size, pumpSyncStorage[TBR]!!.size))
}
}

View file

@ -458,7 +458,7 @@ class MedtronicHistoryData @Inject constructor(
medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber!!)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "insertTherapyEventIfNewWithTimestamp [date=%d, eventType=%d, pumpId=%d, pumpSerial=%s] - Result: %b",
aapsLogger.debug(LTag.PUMP, String.format(Locale.ROOT, "insertTherapyEventIfNewWithTimestamp [date=%d, eventType=%s, pumpId=%d, pumpSerial=%s] - Result: %b",
historyRecord.atechDateTime!!, eventType, historyRecord.pumpId,
medtronicPumpStatus.serialNumber!!, result))
@ -646,8 +646,12 @@ class MedtronicHistoryData @Inject constructor(
val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords)
aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId: " + (if (entryWithTempId==null) "null" else entryWithTempId.toString()))
val tbrEntry = tempBasalProcessDTO.itemOne!!.getDecodedDataEntry("Object") as TempBasalPair
aapsLogger.debug(LTag.PUMP, String.format("DD: tbrEntry=%s, tempBasalProcessDTO=%s", gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO)))
if (entryWithTempId!=null) {
aapsLogger.debug(LTag.PUMP, String.format("DD: tempIdEntry=%s, tbrEntry=%s, tempBasalProcessDTO=%s, pumpType=%s, serial=%s",