save tx after setting basal. save basal in pod state when the basal command is confirmed
This commit is contained in:
parent
d882428cc0
commit
efd3acbb2a
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue