save tx after setting basal. save basal in pod state when the basal command is confirmed

This commit is contained in:
Andrei Vereha 2021-06-25 20:52:32 +02:00
parent d882428cc0
commit efd3acbb2a
5 changed files with 13 additions and 19 deletions

View file

@ -173,8 +173,7 @@ class OmnipodDashManagerImpl @Inject constructor(
DefaultStatusResponse::class DefaultStatusResponse::class
) )
}.doOnComplete { }.doOnComplete {
// TODO: remove podStateManager.basalProgram? podStateManager.timeZone = TimeZone.getDefault()
podStateManager.basalProgram = basalProgram
} }
} }
@ -246,6 +245,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observeVerifyPrime.doOnComplete(ActivationProgressUpdater(ActivationProgress.PRIME_COMPLETED)) observeVerifyPrime.doOnComplete(ActivationProgressUpdater(ActivationProgress.PRIME_COMPLETED))
) )
} }
if (podStateManager.activationProgress.isBefore(ActivationProgress.PRIMING)) { if (podStateManager.activationProgress.isBefore(ActivationProgress.PRIMING)) {
observables.add(observeConnectToPod) // connection can time out while waiting observables.add(observeConnectToPod) // connection can time out while waiting
observables.add( observables.add(
@ -270,6 +270,7 @@ class OmnipodDashManagerImpl @Inject constructor(
}.doOnComplete(ActivationProgressUpdater(ActivationProgress.PRIMING)) }.doOnComplete(ActivationProgressUpdater(ActivationProgress.PRIMING))
) )
} }
if (podStateManager.activationProgress.isBefore(ActivationProgress.REPROGRAMMED_LUMP_OF_COAL_ALERT)) { if (podStateManager.activationProgress.isBefore(ActivationProgress.REPROGRAMMED_LUMP_OF_COAL_ALERT)) {
observables.add( observables.add(
observeSendProgramAlertsCommand( observeSendProgramAlertsCommand(
@ -304,6 +305,7 @@ class OmnipodDashManagerImpl @Inject constructor(
).doOnComplete(ActivationProgressUpdater(ActivationProgress.PROGRAMMED_LOW_RESERVOIR_ALERTS)) ).doOnComplete(ActivationProgressUpdater(ActivationProgress.PROGRAMMED_LOW_RESERVOIR_ALERTS))
) )
} }
if (podStateManager.activationProgress.isBefore(ActivationProgress.SET_UNIQUE_ID)) { if (podStateManager.activationProgress.isBefore(ActivationProgress.SET_UNIQUE_ID)) {
observables.add( observables.add(
observeSendSetUniqueIdCommand.doOnComplete(ActivationProgressUpdater(ActivationProgress.SET_UNIQUE_ID)) observeSendSetUniqueIdCommand.doOnComplete(ActivationProgressUpdater(ActivationProgress.SET_UNIQUE_ID))
@ -425,9 +427,6 @@ class OmnipodDashManagerImpl @Inject constructor(
observeConnectToPod, observeConnectToPod,
observeSendProgramBasalCommand(basalProgram, hasBasalBeepEnabled) observeSendProgramBasalCommand(basalProgram, hasBasalBeepEnabled)
) )
.doOnComplete {
podStateManager.timeZone = TimeZone.getDefault()
}
// TODO these would be common for any observable returned in a public function in this class // TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor()) .doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor()) .doOnError(ErrorInterceptor())

View file

@ -39,7 +39,7 @@ interface OmnipodDashPodStateManager {
val lastUpdatedSystem: Long // System.currentTimeMillis() val lastUpdatedSystem: Long // System.currentTimeMillis()
val lastStatusResponseReceived: Long val lastStatusResponseReceived: Long
val time: DateTime? val time: DateTime?
val timeBehind: Duration? val timeDrift: Duration?
val expiry: DateTime? val expiry: DateTime?
val messageSequenceNumber: Short val messageSequenceNumber: Short

View file

@ -194,13 +194,13 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
return null return null
} }
override val timeBehind: Duration? override val timeDrift: Duration?
get() { get() {
return Duration(DateTime.now(), time) return Duration(DateTime.now(), time)
} }
override val expiry: DateTime? 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() { get() {
val podLifeInHours = podLifeInHours val podLifeInHours = podLifeInHours
val activationTime = podState.activationTime val activationTime = podState.activationTime
@ -466,6 +466,9 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
podState.lastUpdatedSystem = System.currentTimeMillis() podState.lastUpdatedSystem = System.currentTimeMillis()
podState.lastStatusResponseReceived = SystemClock.elapsedRealtime() podState.lastStatusResponseReceived = SystemClock.elapsedRealtime()
updateLastBolusFromResponse(response.bolusPulsesRemaining) updateLastBolusFromResponse(response.bolusPulsesRemaining)
if (podState.activationTime == null) {
podState.activationTime = System.currentTimeMillis() - (response.minutesSinceActivation * 60000)
}
store() store()
rxBus.send(EventOmnipodDashPumpValuesChanged()) rxBus.send(EventOmnipodDashPumpValuesChanged())
@ -514,12 +517,6 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
podState.uniqueId = response.uniqueIdReceivedInCommand podState.uniqueId = response.uniqueIdReceivedInCommand
podState.lastUpdatedSystem = System.currentTimeMillis() 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() store()
rxBus.send(EventOmnipodDashPumpValuesChanged()) rxBus.send(EventOmnipodDashPumpValuesChanged())
} }

View file

@ -125,7 +125,7 @@ class DashPodManagementActivity : NoSplashAppCompatActivity() {
binding.buttonActivatePod.isEnabled = podStateManager.activationProgress.isBefore(ActivationProgress.COMPLETED) binding.buttonActivatePod.isEnabled = podStateManager.activationProgress.isBefore(ActivationProgress.COMPLETED)
binding.buttonDeactivatePod.isEnabled = binding.buttonDeactivatePod.isEnabled =
podStateManager.activationProgress.isAtLeast(ActivationProgress.SET_UNIQUE_ID) || podStateManager.ltk != null ||
podStateManager.podStatus == PodStatus.ALARM podStateManager.podStatus == PodStatus.ALARM
if (podStateManager.activationProgress.isAtLeast(ActivationProgress.PHASE_1_COMPLETED)) { if (podStateManager.activationProgress.isAtLeast(ActivationProgress.PHASE_1_COMPLETED)) {

View file

@ -45,7 +45,6 @@ import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign import io.reactivex.rxkotlin.plusAssign
import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.StringUtils
import org.joda.time.DateTime import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import org.joda.time.Duration import org.joda.time.Duration
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
@ -69,7 +68,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
private const val REFRESH_INTERVAL_MILLIS = 15 * 1000L // 15 seconds private const val REFRESH_INTERVAL_MILLIS = 15 * 1000L // 15 seconds
private const val PLACEHOLDER = "-" 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() private var disposables: CompositeDisposable = CompositeDisposable()
@ -274,7 +273,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
} ?: PLACEHOLDER } ?: PLACEHOLDER
podInfoBinding.timeOnPod.setTextColor( podInfoBinding.timeOnPod.setTextColor(
podStateManager.timeBehind?.let { podStateManager.timeDrift?.let {
if (it.abs().isLongerThan(Duration.standardMinutes(MAX_TIME_DEVIATION_MINUTES))) { if (it.abs().isLongerThan(Duration.standardMinutes(MAX_TIME_DEVIATION_MINUTES))) {
Color.RED Color.RED
} else { } else {
@ -526,7 +525,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
private fun updateRefreshStatusButton() { private fun updateRefreshStatusButton() {
buttonBinding.buttonRefreshStatus.isEnabled = buttonBinding.buttonRefreshStatus.isEnabled =
podStateManager.isUniqueIdSet && podStateManager.isUniqueIdSet &&
podStateManager.activationProgress.isAtLeast(ActivationProgress.PHASE_1_COMPLETED) &&
isQueueEmpty() isQueueEmpty()
} }