From 0312eff327632a78c94fa466d5b8913619849080 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Mon, 4 Oct 2021 10:10:52 +0200 Subject: [PATCH] bugfix for 0 TBR --- .../pump/omnipod/dash/OmnipodDashPumpPlugin.kt | 7 ++++--- .../action/DashInsertCannulaViewModel.kt | 18 ++++++++++++------ .../pump/omnipod/dash/util/Constants.kt | 7 +++++++ 3 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/Constants.kt 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 4f49c6f4f1..90cdb75c7f 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 @@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRe import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusType import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.TempBasalRecord import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.OmnipodDashOverviewFragment +import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.Constants import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram import info.nightscout.androidaps.queue.commands.Command import info.nightscout.androidaps.queue.commands.CustomCommand @@ -127,8 +128,6 @@ class OmnipodDashPumpPlugin @Inject constructor( val tbr = expectedState.temporaryBasal if (tbr == null || tbr.rate != 0.0) { aapsLogger.info(LTag.PUMP, "createFakeTBRWhenNoActivePod") - // calling connectNewPump() here because pumpSerial could have changed(from 4241 to "n/a") - pumpSync.connectNewPump() pumpSync.syncTemporaryBasalWithPumpId( timestamp = System.currentTimeMillis(), rate = 0.0, @@ -137,7 +136,9 @@ class OmnipodDashPumpPlugin @Inject constructor( 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() + pumpSerial = Constants.PUMP_SERIAL_FOR_FAKE_TBR // switching the serialNumber here would need a + // call to connectNewPump. If we do that, then we will have a TBR started by the "n/a" pump and + // cancelled by "4241". This did not work ok. ) } } 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 a716d2b56b..4df51ae4f0 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 @@ -16,6 +16,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activati import info.nightscout.androidaps.plugins.pump.omnipod.dash.R import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager +import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.Constants import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -80,7 +81,17 @@ class DashInsertCannulaViewModel @Inject constructor( onComplete = { logger.debug("Pod activation part 2 completed") podStateManager.basalProgram = basalProgram + + pumpSync.syncStopTemporaryBasalWithPumpId( + timestamp = System.currentTimeMillis(), + endPumpId = System.currentTimeMillis(), + pumpType = PumpType.OMNIPOD_DASH, + pumpSerial = Constants.PUMP_SERIAL_FOR_FAKE_TBR // cancel the fake TBR with the same pump + // serial that it was created with + ) + pumpSync.connectNewPump() + pumpSync.insertTherapyEventIfNewWithTimestamp( timestamp = System.currentTimeMillis(), type = DetailedBolusInfo.EventType.CANNULA_CHANGE, @@ -93,12 +104,7 @@ 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" - ) + podStateManager.updateExpirationAlertSettings(expirationReminderEnabled, expirationHours) rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED)) source.onSuccess(PumpEnactResult(injector).success(true)) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/Constants.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/Constants.kt new file mode 100644 index 0000000000..89b4228eb8 --- /dev/null +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/util/Constants.kt @@ -0,0 +1,7 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.dash.util + +class Constants { + companion object { + val PUMP_SERIAL_FOR_FAKE_TBR = "4241" + } +} \ No newline at end of file