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 e3934e0020..c0c9c569ad 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 @@ -158,11 +158,10 @@ class OmnipodDashPumpPlugin @Inject constructor( override fun setNewBasalProfile(profile: Profile): PumpEnactResult { return executeSimpleProgrammingCommand( - historyEntry = history.createRecord( - commandType = OmnipodCommandType.SET_BASAL_PROFILE - ), - command = omnipodManager.setBasalProgram(mapProfileToBasalProgram(profile)).ignoreElements(), pre = suspendDeliveryIfActive(), + historyEntry = history.createRecord(commandType = OmnipodCommandType.SET_BASAL_PROFILE), + command = omnipodManager.setBasalProgram(mapProfileToBasalProgram(profile)) + .ignoreElements(), ).toPumpEnactResult() } @@ -172,7 +171,17 @@ class OmnipodDashPumpPlugin @Inject constructor( else executeSimpleProgrammingCommand( history.createRecord(OmnipodCommandType.SUSPEND_DELIVERY), - omnipodManager.suspendDelivery().ignoreElements() + omnipodManager.suspendDelivery() + .filter { podEvent -> podEvent is PodEvent.CommandSent } + .map { + pumpSyncTempBasal( + it, + 0.0, + PodConstants.MAX_POD_LIFETIME.standardMinutes, + PumpSync.TemporaryBasalType.PUMP_SUSPEND + ) + } + .ignoreElements(), ) } @@ -528,10 +537,12 @@ class OmnipodDashPumpPlugin @Inject constructor( command = omnipodManager.suspendDelivery() .filter { podEvent -> podEvent is PodEvent.CommandSent } .map { - pumpSyncTempBasal(it, - 0.0, - PodConstants.MAX_POD_LIFETIME.standardMinutes, - PumpSync.TemporaryBasalType.PUMP_SUSPEND) + pumpSyncTempBasal( + it, + 0.0, + PodConstants.MAX_POD_LIFETIME.standardMinutes, + PumpSync.TemporaryBasalType.PUMP_SUSPEND + ) } .ignoreElements(), pre = observeDeliveryActive(), @@ -626,7 +637,7 @@ class OmnipodDashPumpPlugin @Inject constructor( private fun handleCommandConfirmation(confirmation: CommandConfirmed) { val historyEntry = history.getById(confirmation.historyId) - aapsLogger.debug(LTag.PUMPCOMM, "handling confirmation command: $confirmation") + aapsLogger.debug(LTag.PUMPCOMM, "handling command confirmation: $confirmation") when (historyEntry.commandType) { OmnipodCommandType.CANCEL_TEMPORARY_BASAL, OmnipodCommandType.SET_BASAL_PROFILE, diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/PodConstants.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/PodConstants.kt index 4c9a1175eb..f52cc8fb5f 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/PodConstants.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/definition/PodConstants.kt @@ -6,4 +6,4 @@ class PodConstants { companion object { val MAX_POD_LIFETIME = Duration.standardHours(80) } -} \ No newline at end of file +} diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt index f684f24d9f..2b9dc3dc7e 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt @@ -73,7 +73,7 @@ interface OmnipodDashPodStateManager { fun updateFromPairing(uniqueId: Id, pairResult: PairResult) fun reset() - fun createActiveCommand(historyId: String, basalProgram: BasalProgram?=null): Single + fun createActiveCommand(historyId: String, basalProgram: BasalProgram? = null): Single fun updateActiveCommand(): Maybe fun observeNoActiveCommand(): Observable fun getCommandConfirmationFromState(): CommandConfirmationFromState diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt index fd25212775..a1500c49ac 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt @@ -190,27 +190,27 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( @Synchronized override fun createActiveCommand(historyId: String, basalProgram: BasalProgram?): Single { - return Single.create { source -> - if (activeCommand == null) { - val command = OmnipodDashPodStateManager.ActiveCommand( - podState.messageSequenceNumber, - createdRealtime = SystemClock.elapsedRealtime(), - historyId = historyId, - sendError = null, - basalProgram = basalProgram, - ) - podState.activeCommand = command - source.onSuccess(command) - } else { - source.onError( - java.lang.IllegalStateException( - "Trying to send a command " + - "and the last command was not confirmed" + return Single.create { source -> + if (activeCommand == null) { + val command = OmnipodDashPodStateManager.ActiveCommand( + podState.messageSequenceNumber, + createdRealtime = SystemClock.elapsedRealtime(), + historyId = historyId, + sendError = null, + basalProgram = basalProgram, ) - ) + podState.activeCommand = command + source.onSuccess(command) + } else { + source.onError( + java.lang.IllegalStateException( + "Trying to send a command " + + "and the last command was not confirmed" + ) + ) + } } } - } @Synchronized override fun observeNoActiveCommand(): Observable { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt index fc623d01f3..f1e91651f7 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt @@ -55,29 +55,29 @@ class DashHistory @Inject constructor( bolusRecord: BolusRecord? = null, resolveResult: ResolvedResult? = null, resolvedAt: Long? = null - ): Single { + ): Single = Single.defer { val id = ULID.random() when { commandType == SET_BOLUS && bolusRecord == null -> - return Single.error(IllegalArgumentException("bolusRecord missing on SET_BOLUS")) + Single.error(IllegalArgumentException("bolusRecord missing on SET_BOLUS")) commandType == SET_TEMPORARY_BASAL && tempBasalRecord == null -> - return Single.error(IllegalArgumentException("tempBasalRecord missing on SET_TEMPORARY_BASAL")) + Single.error(IllegalArgumentException("tempBasalRecord missing on SET_TEMPORARY_BASAL")) + else -> + dao.save( + HistoryRecordEntity( + id = id, + date = date, + createdAt = currentTimeMillis(), + commandType = commandType, + tempBasalRecord = tempBasalRecord, + bolusRecord = bolusRecord, + initialResult = initialResult, + resolvedResult = resolveResult, + resolvedAt = resolvedAt + ) + ).toSingle { id } } - - return dao.save( - HistoryRecordEntity( - id = id, - date = date, - createdAt = currentTimeMillis(), - commandType = commandType, - tempBasalRecord = tempBasalRecord, - bolusRecord = bolusRecord, - initialResult = initialResult, - resolvedResult = resolveResult, - resolvedAt = resolvedAt - ) - ).toSingle { id } } fun getRecords(): Single> =