More WIP on Omnipod Dash Pod activation

This commit is contained in:
Bart Sopers 2021-03-15 01:34:02 +01:00
parent 6d4521ca6b
commit ebdc2aebe0

View file

@ -105,19 +105,16 @@ class OmnipodDashManagerImpl @Inject constructor(
} }
private val observeVerifyCannulaInsertion: Observable<PodEvent> private val observeVerifyCannulaInsertion: Observable<PodEvent>
get() = Observable.defer { get() = Observable.concat(
observeSendGetPodStatusCommand() observeSendGetPodStatusCommand(),
.ignoreElements() // Observable.defer {
.andThen( if (podStateManager.podStatus == PodStatus.RUNNING_ABOVE_MIN_VOLUME) {
Observable.defer { Observable.empty()
if (podStateManager.podStatus == PodStatus.RUNNING_ABOVE_MIN_VOLUME) { } else {
Observable.empty() Observable.error(IllegalStateException("Unexpected Pod status"))
} else { }
Observable.error(IllegalStateException("Unexpected Pod status")) }
} )
}
)
}
private fun observeSendProgramAlertsCommand( private fun observeSendProgramAlertsCommand(
alertConfigurations: List<AlertConfiguration>, alertConfigurations: List<AlertConfiguration>,
@ -153,19 +150,16 @@ class OmnipodDashManagerImpl @Inject constructor(
} }
private val observeVerifyPrime: Observable<PodEvent> private val observeVerifyPrime: Observable<PodEvent>
get() = Observable.defer { get() = Observable.concat(
observeSendGetPodStatusCommand() observeSendGetPodStatusCommand(ResponseType.StatusResponseType.DEFAULT_STATUS_RESPONSE),
.ignoreElements() // Observable.defer {
.andThen( if (podStateManager.podStatus == PodStatus.CLUTCH_DRIVE_ENGAGED) {
Observable.defer { Observable.empty()
if (podStateManager.podStatus == PodStatus.CLUTCH_DRIVE_ENGAGED) { } else {
Observable.empty() Observable.error(IllegalStateException("Unexpected Pod status: got ${podStateManager.podStatus}, expected CLUTCH_DRIVE_ENGAGED"))
} else { }
Observable.error(IllegalStateException("Unexpected Pod status: got ${podStateManager.podStatus}, expected CLUTCH_DRIVE_ENGAGED")) }
} )
}
)
}
private val observeSendSetUniqueIdCommand: Observable<PodEvent> private val observeSendSetUniqueIdCommand: Observable<PodEvent>
get() = Observable.defer { get() = Observable.defer {
@ -196,6 +190,7 @@ class OmnipodDashManagerImpl @Inject constructor(
return Observable.concat( return Observable.concat(
observePodReadyForActivationPart1, observePodReadyForActivationPart1,
observePairNewPod, observePairNewPod,
observeConnectToPod, // FIXME needed after disconnect; observePairNewPod does not connect in that case.
observeActivationPart1Commands(lowReservoirAlertTrigger) observeActivationPart1Commands(lowReservoirAlertTrigger)
).doOnComplete(ActivationProgressUpdater(ActivationProgress.PHASE_1_COMPLETED)) ).doOnComplete(ActivationProgressUpdater(ActivationProgress.PHASE_1_COMPLETED))
// 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