From efd3acbb2a8beb3fd65a67baa23876ea4ee7792b Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Fri, 25 Jun 2021 20:52:32 +0200 Subject: [PATCH] save tx after setting basal. save basal in pod state when the basal command is confirmed --- .../omnipod/dash/driver/OmnipodDashManagerImpl.kt | 9 ++++----- .../driver/pod/state/OmnipodDashPodStateManager.kt | 2 +- .../pod/state/OmnipodDashPodStateManagerImpl.kt | 13 +++++-------- .../omnipod/dash/ui/DashPodManagementActivity.kt | 2 +- .../omnipod/dash/ui/OmnipodDashOverviewFragment.kt | 6 ++---- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt index 63cfb403ae..487ecf2c6c 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt @@ -173,8 +173,7 @@ class OmnipodDashManagerImpl @Inject constructor( DefaultStatusResponse::class ) }.doOnComplete { - // TODO: remove podStateManager.basalProgram? - podStateManager.basalProgram = basalProgram + podStateManager.timeZone = TimeZone.getDefault() } } @@ -246,6 +245,7 @@ class OmnipodDashManagerImpl @Inject constructor( observeVerifyPrime.doOnComplete(ActivationProgressUpdater(ActivationProgress.PRIME_COMPLETED)) ) } + if (podStateManager.activationProgress.isBefore(ActivationProgress.PRIMING)) { observables.add(observeConnectToPod) // connection can time out while waiting observables.add( @@ -270,6 +270,7 @@ class OmnipodDashManagerImpl @Inject constructor( }.doOnComplete(ActivationProgressUpdater(ActivationProgress.PRIMING)) ) } + if (podStateManager.activationProgress.isBefore(ActivationProgress.REPROGRAMMED_LUMP_OF_COAL_ALERT)) { observables.add( observeSendProgramAlertsCommand( @@ -304,6 +305,7 @@ class OmnipodDashManagerImpl @Inject constructor( ).doOnComplete(ActivationProgressUpdater(ActivationProgress.PROGRAMMED_LOW_RESERVOIR_ALERTS)) ) } + if (podStateManager.activationProgress.isBefore(ActivationProgress.SET_UNIQUE_ID)) { observables.add( observeSendSetUniqueIdCommand.doOnComplete(ActivationProgressUpdater(ActivationProgress.SET_UNIQUE_ID)) @@ -425,9 +427,6 @@ class OmnipodDashManagerImpl @Inject constructor( observeConnectToPod, observeSendProgramBasalCommand(basalProgram, hasBasalBeepEnabled) ) - .doOnComplete { - podStateManager.timeZone = TimeZone.getDefault() - } // TODO these would be common for any observable returned in a public function in this class .doOnNext(PodEventInterceptor()) .doOnError(ErrorInterceptor()) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt index fce985edc2..3eeab834ad 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt @@ -39,7 +39,7 @@ interface OmnipodDashPodStateManager { val lastUpdatedSystem: Long // System.currentTimeMillis() val lastStatusResponseReceived: Long val time: DateTime? - val timeBehind: Duration? + val timeDrift: Duration? val expiry: DateTime? val messageSequenceNumber: Short diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt index 03bf7468e5..95df4367a7 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt @@ -194,13 +194,13 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( return null } - override val timeBehind: Duration? + override val timeDrift: Duration? get() { return Duration(DateTime.now(), time) } override val expiry: DateTime? - // TODO: Consider storing expiry datetime in pod state saving continuesly recalculating to the same value + // TODO: Consider storing expiry datetime in pod state saving continuously recalculating to the same value get() { val podLifeInHours = podLifeInHours val activationTime = podState.activationTime @@ -466,6 +466,9 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( podState.lastUpdatedSystem = System.currentTimeMillis() podState.lastStatusResponseReceived = SystemClock.elapsedRealtime() updateLastBolusFromResponse(response.bolusPulsesRemaining) + if (podState.activationTime == null) { + podState.activationTime = System.currentTimeMillis() - (response.minutesSinceActivation * 60000) + } store() rxBus.send(EventOmnipodDashPumpValuesChanged()) @@ -514,12 +517,6 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( podState.uniqueId = response.uniqueIdReceivedInCommand podState.lastUpdatedSystem = System.currentTimeMillis() - // TODO: what is considered to be the pod activation time? - // LTK negotiation ? - // setUniqueId? - // compute it from the number of "minutesOnPod"? - podState.activationTime = System.currentTimeMillis() - store() rxBus.send(EventOmnipodDashPumpValuesChanged()) } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt index e3f6f97138..3d89be5da8 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/DashPodManagementActivity.kt @@ -125,7 +125,7 @@ class DashPodManagementActivity : NoSplashAppCompatActivity() { binding.buttonActivatePod.isEnabled = podStateManager.activationProgress.isBefore(ActivationProgress.COMPLETED) binding.buttonDeactivatePod.isEnabled = - podStateManager.activationProgress.isAtLeast(ActivationProgress.SET_UNIQUE_ID) || + podStateManager.ltk != null || podStateManager.podStatus == PodStatus.ALARM if (podStateManager.activationProgress.isAtLeast(ActivationProgress.PHASE_1_COMPLETED)) { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt index e524444513..80b14e98b3 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt @@ -45,7 +45,6 @@ import io.reactivex.disposables.CompositeDisposable import io.reactivex.rxkotlin.plusAssign import org.apache.commons.lang3.StringUtils import org.joda.time.DateTime -import org.joda.time.DateTimeZone import org.joda.time.Duration import java.util.* import javax.inject.Inject @@ -69,7 +68,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() { private const val REFRESH_INTERVAL_MILLIS = 15 * 1000L // 15 seconds private const val PLACEHOLDER = "-" - private const val MAX_TIME_DEVIATION_MINUTES = 15L + private const val MAX_TIME_DEVIATION_MINUTES = 10L } private var disposables: CompositeDisposable = CompositeDisposable() @@ -274,7 +273,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() { } ?: PLACEHOLDER podInfoBinding.timeOnPod.setTextColor( - podStateManager.timeBehind?.let { + podStateManager.timeDrift?.let { if (it.abs().isLongerThan(Duration.standardMinutes(MAX_TIME_DEVIATION_MINUTES))) { Color.RED } else { @@ -526,7 +525,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() { private fun updateRefreshStatusButton() { buttonBinding.buttonRefreshStatus.isEnabled = podStateManager.isUniqueIdSet && - podStateManager.activationProgress.isAtLeast(ActivationProgress.PHASE_1_COMPLETED) && isQueueEmpty() }