Merge branch 'dash' into avereha/basal

This commit is contained in:
Andrei Vereha 2021-06-06 21:28:23 +02:00
commit 697e646854

View file

@ -302,7 +302,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
.filter { podEvent -> podEvent is PodEvent.CommandSent } .filter { podEvent -> podEvent is PodEvent.CommandSent }
.map { pumpSyncTempBasal(it, absoluteRate, durationInMinutes.toLong(), tbrType) } .map { pumpSyncTempBasal(it, absoluteRate, durationInMinutes.toLong(), tbrType) }
.ignoreElements(), .ignoreElements(),
pre = observeNoActiveTempBasal(enforceNew) pre = observeNoActiveTempBasal()
).toPumpEnactResult() ).toPumpEnactResult()
} }
@ -336,31 +336,19 @@ class OmnipodDashPumpPlugin @Inject constructor(
return ret return ret
} }
private fun observeNoActiveTempBasal(enforceNew: Boolean): Completable { private fun observeNoActiveTempBasal(): Completable {
return Completable.defer { return Completable.defer {
when { val expectedState = pumpSync.expectedPumpState()
podStateManager.deliveryStatus !in if (expectedState.temporaryBasal == null) {
arrayOf(DeliveryStatus.TEMP_BASAL_ACTIVE, DeliveryStatus.BOLUS_AND_TEMP_BASAL_ACTIVE) -> { aapsLogger.info(LTag.PUMP, "No temporary basal to cancel")
// TODO: what happens if we try to cancel inexistent temp basal? Completable.complete()
aapsLogger.info(LTag.PUMP, "No temporary basal to cancel") } else {
Completable.complete() // enforceNew == true
} aapsLogger.info(LTag.PUMP, "Canceling existing temp basal")
executeSimpleProgrammingCommand(
!enforceNew -> history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL),
Completable.error( omnipodManager.stopTempBasal().ignoreElements()
IllegalStateException( )
"Temporary basal already active and enforeNew is not set."
)
)
else -> {
// enforceNew == true
aapsLogger.info(LTag.PUMP, "Canceling existing temp basal")
executeSimpleProgrammingCommand(
history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL),
omnipodManager.stopTempBasal().ignoreElements()
)
}
} }
} }
} }