Move verifyPumpState to its own function, cleanup

This commit is contained in:
jbr7rr 2023-05-19 16:48:07 +02:00
parent 77feeedf35
commit cd3869ea07
3 changed files with 21 additions and 20 deletions

View file

@ -324,10 +324,11 @@ class OmnipodDashPumpPlugin @Inject constructor(
omnipodManager omnipodManager
.getStatus(ResponseType.StatusResponseType.DEFAULT_STATUS_RESPONSE) .getStatus(ResponseType.StatusResponseType.DEFAULT_STATUS_RESPONSE)
.ignoreElements(), .ignoreElements(),
updateFromState(), history.updateFromState(podStateManager),
podStateManager.updateActiveCommand() podStateManager.updateActiveCommand()
.map { handleCommandConfirmation(it) } .map { handleCommandConfirmation(it) }
.ignoreElement(), .ignoreElement(),
verifyPumpState(),
checkPodKaput(), checkPodKaput(),
) )
) )
@ -572,9 +573,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
.bolusDelivered(0.0) .bolusDelivered(0.0)
.comment(rh.gs(R.string.omnipod_dash_not_enough_insulin)) .comment(rh.gs(R.string.omnipod_dash_not_enough_insulin))
} }
if (podStateManager.deliveryStatus == DeliveryStatus.BOLUS_AND_BASAL_ACTIVE || if (podStateManager.deliveryStatus?.bolusDeliveringActive() == true) {
podStateManager.deliveryStatus == DeliveryStatus.BOLUS_AND_TEMP_BASAL_ACTIVE
) {
return PumpEnactResult(injector) return PumpEnactResult(injector)
.success(false) .success(false)
.enacted(false) .enacted(false)
@ -890,9 +889,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
private fun observeNoActiveTempBasal(): Completable { private fun observeNoActiveTempBasal(): Completable {
return Completable.defer { return Completable.defer {
if (podStateManager.deliveryStatus !in if (podStateManager.deliveryStatus?.tempBasalActive() == false) {
arrayOf(DeliveryStatus.TEMP_BASAL_ACTIVE, DeliveryStatus.BOLUS_AND_TEMP_BASAL_ACTIVE)
) {
// TODO: what happens if we try to cancel nonexistent temp basal? // TODO: what happens if we try to cancel nonexistent temp basal?
aapsLogger.info(LTag.PUMP, "No temporary basal to cancel") aapsLogger.info(LTag.PUMP, "No temporary basal to cancel")
Completable.complete() Completable.complete()
@ -1319,10 +1316,11 @@ class OmnipodDashPumpPlugin @Inject constructor(
podStateManager.activeCommand?.sendError = it podStateManager.activeCommand?.sendError = it
aapsLogger.error(LTag.PUMP, "Error executing command", it) aapsLogger.error(LTag.PUMP, "Error executing command", it)
}.onErrorComplete(), }.onErrorComplete(),
updateFromState(), history.updateFromState(podStateManager),
podStateManager.updateActiveCommand() podStateManager.updateActiveCommand()
.map { handleCommandConfirmation(it) } .map { handleCommandConfirmation(it) }
.ignoreElement(), .ignoreElement(),
verifyPumpState(),
checkPodKaput(), checkPodKaput(),
refreshOverview(), refreshOverview(),
post, post,
@ -1488,12 +1486,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
} }
} }
private fun updateFromState(): Completable = Completable.defer { private fun verifyPumpState(): Completable = Completable.defer {
aapsLogger.debug(LTag.PUMP, "verifyPumpState, AAPS: ${pumpSync.expectedPumpState().temporaryBasal} Pump: ${podStateManager.deliveryStatus}")
val tbr = pumpSync.expectedPumpState().temporaryBasal val tbr = pumpSync.expectedPumpState().temporaryBasal
if (tbr != null && podStateManager.deliveryStatus?.tempBasalActive() == false && pumpSync.expectedPumpState().temporaryBasal?.pumpSerial != Constants if (tbr != null && podStateManager.deliveryStatus?.basalActive() == true) {
.PUMP_SERIAL_FOR_FAKE_TBR
) {
// AAPS thinks there is a TBR running but pump has no TBR running
aapsLogger.error(LTag.PUMP, "AAPS expected a TBR running but pump has no TBR running! AAPS: ${pumpSync.expectedPumpState().temporaryBasal} Pump: ${podStateManager.deliveryStatus}") aapsLogger.error(LTag.PUMP, "AAPS expected a TBR running but pump has no TBR running! AAPS: ${pumpSync.expectedPumpState().temporaryBasal} Pump: ${podStateManager.deliveryStatus}")
// Alert user // Alert user
val sound = if (hasBolusErrorBeepEnabled()) info.nightscout.core.ui.R.raw.boluserror else 0 val sound = if (hasBolusErrorBeepEnabled()) info.nightscout.core.ui.R.raw.boluserror else 0
@ -1507,20 +1503,21 @@ class OmnipodDashPumpPlugin @Inject constructor(
) )
aapsLogger.info(LTag.PUMP, "syncStopTemporaryBasalWithPumpId ret=$ret pumpId=${tbr.id}") aapsLogger.info(LTag.PUMP, "syncStopTemporaryBasalWithPumpId ret=$ret pumpId=${tbr.id}")
podStateManager.tempBasal = null podStateManager.tempBasal = null
} } else if (tbr == null && podStateManager.deliveryStatus?.tempBasalActive() == true) {
if (tbr == null && podStateManager.deliveryStatus?.tempBasalActive() == true) {
// AAPS thinks there is no TBR running but pump has a TBR running
aapsLogger.error(LTag.PUMP, "AAPS expected no TBR running but pump has a TBR running! AAPS: ${pumpSync.expectedPumpState().temporaryBasal} Pump: ${podStateManager.deliveryStatus}") aapsLogger.error(LTag.PUMP, "AAPS expected no TBR running but pump has a TBR running! AAPS: ${pumpSync.expectedPumpState().temporaryBasal} Pump: ${podStateManager.deliveryStatus}")
// Alert user // Alert user
val sound = if (hasBolusErrorBeepEnabled()) info.nightscout.core.ui.R.raw.boluserror else 0 val sound = if (hasBolusErrorBeepEnabled()) info.nightscout.core.ui.R.raw.boluserror else 0
showErrorDialog(rh.gs(R.string.temp_basal_out_of_sync), sound) showErrorDialog(rh.gs(R.string.temp_basal_out_of_sync), sound)
// If this is reached is reached there is probably a something wrong with the time (maybe it has changed?). // If this is reached is reached there is probably a something wrong with the time (maybe it has changed?).
// No way to calculate the TBR end time and update pumpSync properly. // No way to calculate the TBR end time and update pumpSync properly.
// Cancel TBR running on Pump, pod history will be updated by observeNoActiveTempBasal() // Cancel TBR running on Pump
return@defer observeNoActiveTempBasal() return@defer observeNoActiveTempBasal()
.concatWith(podStateManager.updateActiveCommand()
.map { handleCommandConfirmation(it) }
.ignoreElement())
} }
// Update pod history:
history.updateFromState(podStateManager) return@defer Completable.complete()
} }
private fun showErrorDialog(message: String, sound: Int) { private fun showErrorDialog(message: String, sound: Int) {

View file

@ -16,6 +16,10 @@ enum class DeliveryStatus(override val value: Byte) : HasValue {
return value in arrayOf(BOLUS_AND_BASAL_ACTIVE.value, BOLUS_AND_TEMP_BASAL_ACTIVE.value) return value in arrayOf(BOLUS_AND_BASAL_ACTIVE.value, BOLUS_AND_TEMP_BASAL_ACTIVE.value)
} }
fun basalActive(): Boolean {
return value in arrayOf(BOLUS_AND_BASAL_ACTIVE.value, BASAL_ACTIVE.value)
}
fun tempBasalActive(): Boolean { fun tempBasalActive(): Boolean {
return value in arrayOf(BOLUS_AND_TEMP_BASAL_ACTIVE.value, TEMP_BASAL_ACTIVE.value) return value in arrayOf(BOLUS_AND_TEMP_BASAL_ACTIVE.value, TEMP_BASAL_ACTIVE.value)
} }

View file

@ -299,7 +299,7 @@ class DashPodHistoryActivity : TranslatedDaggerAppCompatActivity() {
} }
private fun setAmount(historyEntry: HistoryRecord, amountView: TextView) { private fun setAmount(historyEntry: HistoryRecord, amountView: TextView) {
amountView.text = historyEntry.totalAmountDelivered?.let { rh.gs(R.string.omnipod_common_history_total_delivered, it) ?: "" } amountView.text = historyEntry.totalAmountDelivered?.let { rh.gs(R.string.omnipod_common_history_total_delivered, it) }
// Set some color // Set some color
setTextViewColor(check_result = false, amountView, historyEntry) setTextViewColor(check_result = false, amountView, historyEntry)
} }