From d392caa6e95e665342b7083fa554ac1dacb481fe Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Tue, 1 Jun 2021 22:00:16 +0200 Subject: [PATCH] move private fun at the end --- .../omnipod/dash/OmnipodDashPumpPlugin.kt | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt index d6d128a7cb..fcb9d88a0e 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt @@ -315,12 +315,14 @@ class OmnipodDashPumpPlugin @Inject constructor( aapsLogger.info(LTag.PUMP, "No temporary basal to cancel") Completable.complete() } + !enforeNew -> Completable.error( IllegalStateException( "Temporary basal already active and enforeNew is not set." ) ) + else -> { // enforceNew == true aapsLogger.info(LTag.PUMP, "Canceling existing temp basal") @@ -378,35 +380,6 @@ class OmnipodDashPumpPlugin @Inject constructor( .blockingGet() } - private fun handleCommandConfirmation(confirmation: CommandConfirmed) { - val historyEntry = history.getById(confirmation.historyId) - when (historyEntry.commandType) { - OmnipodCommandType.CANCEL_TEMPORARY_BASAL -> - // We can't invalidate this command, - // and this is why it is pumpSync-ed at this point - if (confirmation.success) { - pumpSync.syncStopTemporaryBasalWithPumpId( - historyEntry.createdAt, - historyEntry.pumpId(), - PumpType.OMNIPOD_DASH, - serialNumber() - ) - } - OmnipodCommandType.SET_TEMPORARY_BASAL -> - // This treatment was synced before sending the command - if (!confirmation.success) { - pumpSync.invalidateTemporaryBasal(historyEntry.pumpId()) - } - - else -> - aapsLogger.warn( - LTag.PUMP, - "Will not sync confirmed command of type: $historyEntry and " + - "succes: ${confirmation.success}" - ) - } - } - override fun cancelExtendedBolus(): PumpEnactResult { // TODO i18n return PumpEnactResult(injector).success(false).enacted(false) @@ -605,4 +578,33 @@ class OmnipodDashPumpPlugin @Inject constructor( ) ) } + + private fun handleCommandConfirmation(confirmation: CommandConfirmed) { + val historyEntry = history.getById(confirmation.historyId) + when (historyEntry.commandType) { + OmnipodCommandType.CANCEL_TEMPORARY_BASAL -> + // We can't invalidate this command, + // and this is why it is pumpSync-ed at this point + if (confirmation.success) { + pumpSync.syncStopTemporaryBasalWithPumpId( + historyEntry.createdAt, + historyEntry.pumpId(), + PumpType.OMNIPOD_DASH, + serialNumber() + ) + } + OmnipodCommandType.SET_TEMPORARY_BASAL -> + // This treatment was synced before sending the command + if (!confirmation.success) { + pumpSync.invalidateTemporaryBasal(historyEntry.pumpId()) + } + + else -> + aapsLogger.warn( + LTag.PUMP, + "Will not sync confirmed command of type: $historyEntry and " + + "succes: ${confirmation.success}" + ) + } + } }