recover pod activation status when lost during activation

This commit is contained in:
Andrei Vereha 2021-06-24 22:37:29 +02:00
parent a3cacc75fe
commit 22d78f356b
4 changed files with 48 additions and 10 deletions

View file

@ -130,7 +130,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
}
override fun getPumpStatus(reason: String) {
if (reason != "REQUESTED BY USER" && !podStateManager.isActivationCompleted) {
if (reason != "REQUESTED BY USER" && !podStateManager.isActivationCompleted) {
// prevent races on BLE when the pod is not activated
return
}
@ -140,6 +140,13 @@ class OmnipodDashPumpPlugin @Inject constructor(
aapsLogger.error(LTag.PUMP, "Error in getPumpStatus", throwable)
} else {
aapsLogger.info(LTag.PUMP, "getPumpStatus executed with success")
if (!podStateManager.isActivationCompleted) {
val msg = podStateManager.recoverActivationFromPodStatus()
msg?.let {
// TODO: show dialog with "try again, the pod is busy now"
aapsLogger.info(LTag.PUMP, "recoverActivationFromPodStatus msg=$msg")
}
}
}
}

View file

@ -96,6 +96,12 @@ interface OmnipodDashPodStateManager {
fun createLastBolus(requestedUnits: Double, historyId: String, bolusType: DetailedBolusInfo.BolusType)
fun markLastBolusComplete(): LastBolus?
fun onStart()
/*
This is called only:. It overwrites activationStatus
- when activation was interrupted(application crash, killed, etc)
- after getPodStatus was successful(we have an up-to-date podStatus)
*/
fun recoverActivationFromPodStatus(): String?
data class ActiveCommand(
val sequence: Short,

View file

@ -312,6 +312,29 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
}
}
override fun recoverActivationFromPodStatus(): String? {
val newActivationProgress = when (podState.podStatus) {
PodStatus.FILLED ->
ActivationProgress.NOT_STARTED
PodStatus.UID_SET ->
ActivationProgress.SET_UNIQUE_ID
PodStatus.ENGAGING_CLUTCH_DRIVE, PodStatus.PRIMING ->
return "Busy"
PodStatus.CLUTCH_DRIVE_ENGAGED ->
ActivationProgress.PRIME_COMPLETED
PodStatus.BASAL_PROGRAM_SET ->
ActivationProgress.PROGRAMMED_BASAL
PodStatus.RUNNING_ABOVE_MIN_VOLUME, PodStatus.RUNNING_BELOW_MIN_VOLUME ->
ActivationProgress.CANNULA_INSERTED
else ->
null
}
newActivationProgress?.let {
podState.activationProgress = it
}
return null
}
@Synchronized
override fun updateActiveCommand() = Maybe.create<CommandConfirmed> { source ->
val activeCommand = podState.activeCommand
@ -402,6 +425,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
podState.lastStatusResponseReceived = now + 2
podState.activeCommand = newCommand
}
CommandSendingNotConfirmed -> {
val now = System.currentTimeMillis()
val newCommand = podState.activeCommand?.copy(
@ -410,10 +434,10 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
)
podState.lastStatusResponseReceived = 0
}
CommandSendingFailure, NoActiveCommand ->
podState.activeCommand = null
}
}
override fun updateFromDefaultStatusResponse(response: DefaultStatusResponse) {

View file

@ -296,7 +296,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
// Update time on Pod
// TODO: For now: derive from podStateManager.minutesSinceActivation
val timeOnPod = getTimeOnPod()
podInfoBinding.timeOnPod.text = podStateManager.time?.let{
podInfoBinding.timeOnPod.text = podStateManager.time?.let {
readableZonedTime(it)
} ?: PLACEHOLDER
@ -304,13 +304,12 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
podStateManager.timeBehind?.let {
if (it.abs().isLongerThan(Duration.standardMinutes(MAX_TIME_DEVIATION_MINUTES))) {
Color.RED
}else {
} else {
Color.WHITE
}
} ?: Color.WHITE
)
// Update Pod expiry time
val expiresAt = getExpiryAt()
if (expiresAt == null) {
@ -318,11 +317,13 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
podInfoBinding.podExpiryDate.setTextColor(Color.WHITE)
} else {
podInfoBinding.podExpiryDate.text = readableZonedTime(expiresAt)
podInfoBinding.podExpiryDate.setTextColor(if (DateTime.now().isAfter(expiresAt)) {
Color.RED
} else {
Color.WHITE
})
podInfoBinding.podExpiryDate.setTextColor(
if (DateTime.now().isAfter(expiresAt)) {
Color.RED
} else {
Color.WHITE
}
)
}
podStateManager.alarmType?.let {