diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt index b2d0fe6b83..1ab98f1983 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt @@ -51,6 +51,7 @@ import java.util.* import javax.inject.Inject import javax.inject.Singleton import kotlin.math.ceil +import kotlin.math.exp import kotlin.random.Random @Singleton @@ -95,10 +96,31 @@ class OmnipodDashPumpPlugin @Inject constructor( statusChecker = Runnable { refreshStatusOnUnacknowledgedCommands() updatePodWarnings() + createFakeTBRWhenNoActivePod() 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() { if (System.currentTimeMillis() > nextPodWarningCheck) { if (!podStateManager.isPodRunning) { @@ -182,8 +204,6 @@ class OmnipodDashPumpPlugin @Inject constructor( // TODO } - - override fun getPumpStatus(reason: String) { aapsLogger.debug(LTag.PUMP, "getPumpStatus reason=$reason") if (reason != "REQUESTED BY USER" && !podStateManager.isActivationCompleted) { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt index 143fb8fb91..874ccbd4f1 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt @@ -71,6 +71,12 @@ class DashInsertCannulaViewModel @Inject constructor( pumpType = PumpType.OMNIPOD_DASH, 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)) } )