recover pod activation status when lost during activation
This commit is contained in:
parent
a3cacc75fe
commit
22d78f356b
|
@ -130,7 +130,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPumpStatus(reason: String) {
|
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
|
// prevent races on BLE when the pod is not activated
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -140,6 +140,13 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
aapsLogger.error(LTag.PUMP, "Error in getPumpStatus", throwable)
|
aapsLogger.error(LTag.PUMP, "Error in getPumpStatus", throwable)
|
||||||
} else {
|
} else {
|
||||||
aapsLogger.info(LTag.PUMP, "getPumpStatus executed with success")
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,12 @@ interface OmnipodDashPodStateManager {
|
||||||
fun createLastBolus(requestedUnits: Double, historyId: String, bolusType: DetailedBolusInfo.BolusType)
|
fun createLastBolus(requestedUnits: Double, historyId: String, bolusType: DetailedBolusInfo.BolusType)
|
||||||
fun markLastBolusComplete(): LastBolus?
|
fun markLastBolusComplete(): LastBolus?
|
||||||
fun onStart()
|
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(
|
data class ActiveCommand(
|
||||||
val sequence: Short,
|
val sequence: Short,
|
||||||
|
|
|
@ -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
|
@Synchronized
|
||||||
override fun updateActiveCommand() = Maybe.create<CommandConfirmed> { source ->
|
override fun updateActiveCommand() = Maybe.create<CommandConfirmed> { source ->
|
||||||
val activeCommand = podState.activeCommand
|
val activeCommand = podState.activeCommand
|
||||||
|
@ -402,6 +425,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
podState.lastStatusResponseReceived = now + 2
|
podState.lastStatusResponseReceived = now + 2
|
||||||
podState.activeCommand = newCommand
|
podState.activeCommand = newCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandSendingNotConfirmed -> {
|
CommandSendingNotConfirmed -> {
|
||||||
val now = System.currentTimeMillis()
|
val now = System.currentTimeMillis()
|
||||||
val newCommand = podState.activeCommand?.copy(
|
val newCommand = podState.activeCommand?.copy(
|
||||||
|
@ -410,10 +434,10 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
)
|
)
|
||||||
podState.lastStatusResponseReceived = 0
|
podState.lastStatusResponseReceived = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandSendingFailure, NoActiveCommand ->
|
CommandSendingFailure, NoActiveCommand ->
|
||||||
podState.activeCommand = null
|
podState.activeCommand = null
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateFromDefaultStatusResponse(response: DefaultStatusResponse) {
|
override fun updateFromDefaultStatusResponse(response: DefaultStatusResponse) {
|
||||||
|
|
|
@ -296,7 +296,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
// Update time on Pod
|
// Update time on Pod
|
||||||
// TODO: For now: derive from podStateManager.minutesSinceActivation
|
// TODO: For now: derive from podStateManager.minutesSinceActivation
|
||||||
val timeOnPod = getTimeOnPod()
|
val timeOnPod = getTimeOnPod()
|
||||||
podInfoBinding.timeOnPod.text = podStateManager.time?.let{
|
podInfoBinding.timeOnPod.text = podStateManager.time?.let {
|
||||||
readableZonedTime(it)
|
readableZonedTime(it)
|
||||||
} ?: PLACEHOLDER
|
} ?: PLACEHOLDER
|
||||||
|
|
||||||
|
@ -304,13 +304,12 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
podStateManager.timeBehind?.let {
|
podStateManager.timeBehind?.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 {
|
||||||
Color.WHITE
|
Color.WHITE
|
||||||
}
|
}
|
||||||
} ?: Color.WHITE
|
} ?: Color.WHITE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// Update Pod expiry time
|
// Update Pod expiry time
|
||||||
val expiresAt = getExpiryAt()
|
val expiresAt = getExpiryAt()
|
||||||
if (expiresAt == null) {
|
if (expiresAt == null) {
|
||||||
|
@ -318,11 +317,13 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
podInfoBinding.podExpiryDate.setTextColor(Color.WHITE)
|
podInfoBinding.podExpiryDate.setTextColor(Color.WHITE)
|
||||||
} else {
|
} else {
|
||||||
podInfoBinding.podExpiryDate.text = readableZonedTime(expiresAt)
|
podInfoBinding.podExpiryDate.text = readableZonedTime(expiresAt)
|
||||||
podInfoBinding.podExpiryDate.setTextColor(if (DateTime.now().isAfter(expiresAt)) {
|
podInfoBinding.podExpiryDate.setTextColor(
|
||||||
Color.RED
|
if (DateTime.now().isAfter(expiresAt)) {
|
||||||
} else {
|
Color.RED
|
||||||
Color.WHITE
|
} else {
|
||||||
})
|
Color.WHITE
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
podStateManager.alarmType?.let {
|
podStateManager.alarmType?.let {
|
||||||
|
|
Loading…
Reference in a new issue