fake tbr when the pod is not active

This commit is contained in:
Andrei Vereha 2021-06-28 23:02:16 +02:00
parent 2133a90ac5
commit 131c187bb1
2 changed files with 28 additions and 2 deletions

View file

@ -51,6 +51,7 @@ import java.util.*
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
import kotlin.math.ceil import kotlin.math.ceil
import kotlin.math.exp
import kotlin.random.Random import kotlin.random.Random
@Singleton @Singleton
@ -95,10 +96,31 @@ class OmnipodDashPumpPlugin @Inject constructor(
statusChecker = Runnable { statusChecker = Runnable {
refreshStatusOnUnacknowledgedCommands() refreshStatusOnUnacknowledgedCommands()
updatePodWarnings() updatePodWarnings()
createFakeTBRWhenNoActivePod()
handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS) handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS)
} }
} }
private fun createFakeTBRWhenNoActivePod() {
if (!podStateManager.isPodRunning) {
val expectedState = pumpSync.expectedPumpState()
val tbr = expectedState.temporaryBasal
if (tbr == null || tbr.rate!=0.0) {
aapsLogger.info(LTag.PUMP, "createFakeTBRWhenNoActivePod")
pumpSync.syncTemporaryBasalWithPumpId(
timestamp = System.currentTimeMillis(),
rate = 0.0,
duration = T.mins(PodConstants.MAX_POD_LIFETIME.standardMinutes).msecs(),
isAbsolute = true,
type = PumpSync.TemporaryBasalType.PUMP_SUSPEND,
pumpId = Random.Default.nextLong(), // we don't use this, just make sure it's unique
pumpType = PumpType.OMNIPOD_DASH,
pumpSerial = serialNumber()
)
}
}
}
private fun updatePodWarnings() { private fun updatePodWarnings() {
if (System.currentTimeMillis() > nextPodWarningCheck) { if (System.currentTimeMillis() > nextPodWarningCheck) {
if (!podStateManager.isPodRunning) { if (!podStateManager.isPodRunning) {
@ -182,8 +204,6 @@ class OmnipodDashPumpPlugin @Inject constructor(
// TODO // TODO
} }
override fun getPumpStatus(reason: String) { override fun getPumpStatus(reason: String) {
aapsLogger.debug(LTag.PUMP, "getPumpStatus reason=$reason") aapsLogger.debug(LTag.PUMP, "getPumpStatus reason=$reason")
if (reason != "REQUESTED BY USER" && !podStateManager.isActivationCompleted) { if (reason != "REQUESTED BY USER" && !podStateManager.isActivationCompleted) {

View file

@ -71,6 +71,12 @@ class DashInsertCannulaViewModel @Inject constructor(
pumpType = PumpType.OMNIPOD_DASH, pumpType = PumpType.OMNIPOD_DASH,
pumpSerial = podStateManager.uniqueId?.toString() ?: "n/a" pumpSerial = podStateManager.uniqueId?.toString() ?: "n/a"
) )
pumpSync.syncStopTemporaryBasalWithPumpId(
timestamp = System.currentTimeMillis(),
endPumpId = System.currentTimeMillis(),
pumpType = PumpType.OMNIPOD_DASH,
pumpSerial = podStateManager.uniqueId?.toString() ?: "n/a"
)
source.onSuccess(PumpEnactResult(injector).success(true)) source.onSuccess(PumpEnactResult(injector).success(true))
} }
) )