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,24 +336,13 @@ 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) -> {
// TODO: what happens if we try to cancel inexistent temp basal?
aapsLogger.info(LTag.PUMP, "No temporary basal to cancel") aapsLogger.info(LTag.PUMP, "No temporary basal to cancel")
Completable.complete() Completable.complete()
} } else {
!enforceNew ->
Completable.error(
IllegalStateException(
"Temporary basal already active and enforeNew is not set."
)
)
else -> {
// enforceNew == true // enforceNew == true
aapsLogger.info(LTag.PUMP, "Canceling existing temp basal") aapsLogger.info(LTag.PUMP, "Canceling existing temp basal")
executeSimpleProgrammingCommand( executeSimpleProgrammingCommand(
@ -363,7 +352,6 @@ class OmnipodDashPumpPlugin @Inject constructor(
} }
} }
} }
}
private fun observeActiveTempBasal(): Completable { private fun observeActiveTempBasal(): Completable {