Medtrum: resetPatchParameters() on deactivation and new SN

This commit is contained in:
jbr7rr 2023-09-12 13:56:17 +02:00
parent 40d95c13d9
commit 67805382df
2 changed files with 12 additions and 0 deletions

View file

@ -115,6 +115,8 @@ class MedtrumPump @Inject constructor(
sp.putLong(R.string.key_session_token, value) sp.putLong(R.string.key_session_token, value)
} }
// Note: This is not always incremented by the pump, so it is not a reliable indicator for activation unless we reset it on deactivation
// see resetPatchParameters()
private var _patchId = 0L private var _patchId = 0L
var patchId: Long var patchId: Long
get() = _patchId get() = _patchId
@ -538,6 +540,12 @@ class MedtrumPump @Inject constructor(
return rh.gs(stringId) return rh.gs(stringId)
} }
fun resetPatchParameters() {
patchId = 0
syncedSequenceNumber = 1
currentSequenceNumber = 1
}
fun handleNewPatch(newPatchId: Long, sequenceNumber: Int, newStartTime: Long) { fun handleNewPatch(newPatchId: Long, sequenceNumber: Int, newStartTime: Long) {
patchId = newPatchId patchId = newPatchId
patchStartTime = newStartTime patchStartTime = newStartTime

View file

@ -112,6 +112,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
aapsLogger.debug(LTag.PUMPCOMM, "Serial number changed, reporting new pump!") aapsLogger.debug(LTag.PUMPCOMM, "Serial number changed, reporting new pump!")
medtrumPump.loadUserSettingsFromSP() medtrumPump.loadUserSettingsFromSP()
medtrumPump.deviceType = MedtrumSnUtil().getDeviceTypeFromSerial(medtrumPump.pumpSN) medtrumPump.deviceType = MedtrumSnUtil().getDeviceTypeFromSerial(medtrumPump.pumpSN)
medtrumPump.resetPatchParameters()
pumpSync.connectNewPump() pumpSync.connectNewPump()
medtrumPump.setFakeTBRIfNeeded() medtrumPump.setFakeTBRIfNeeded()
} }
@ -534,6 +535,9 @@ class MedtrumService : DaggerService(), BLECommCallback {
) )
medtrumPump.setFakeTBRIfNeeded() medtrumPump.setFakeTBRIfNeeded()
medtrumPump.clearAlarmState() medtrumPump.clearAlarmState()
// Reset sequence numbers, make sure AAPS history can be synced properly on next activation
medtrumPump.resetPatchParameters()
} }
MedtrumPumpState.IDLE, MedtrumPumpState.IDLE,