diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/enums/MedtrumPumpState.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/enums/MedtrumPumpState.kt index c17caa6ad9..99451d4cc1 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/enums/MedtrumPumpState.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/enums/MedtrumPumpState.kt @@ -27,6 +27,10 @@ enum class MedtrumPumpState(val state: Byte) { NO_CALIBRATION(103), STOPPED(128.toByte()); + fun isSuspendedByPump(): Boolean { + return this in LOW_BG_SUSPENDED..SUSPENDED + } + companion object { fun fromByte(state: Byte) = values().find { it.state == state } diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt index 7581b8fa9c..569ed1b587 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt @@ -281,13 +281,8 @@ class MedtrumService : DaggerService(), BLECommCallback { } fun clearAlarms(): Boolean { - var result = true - if (medtrumPump.pumpState in listOf( - MedtrumPumpState.PAUSED, - MedtrumPumpState.HOURLY_MAX_SUSPENDED, - MedtrumPumpState.DAILY_MAX_SUSPENDED - ) - ) { + var result = loadEvents() // Make sure we have all events before clearing alarms + if (result && medtrumPump.pumpState.isSuspendedByPump()) { when (medtrumPump.pumpState) { MedtrumPumpState.HOURLY_MAX_SUSPENDED -> { result = sendPacketAndGetResponse(ClearPumpAlarmPacket(injector, ALARM_HOURLY_MAX_CLEAR_CODE)) diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt index a3c6e15620..13392125bf 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt @@ -119,9 +119,7 @@ class MedtrumOverviewViewModel @Inject constructor( medtrumPump.pumpStateFlow.collect { state -> aapsLogger.debug(LTag.PUMP, "MedtrumViewModel pumpStateFlow: $state") _canDoResetAlarms.postValue( - medtrumPump.pumpState in listOf( - MedtrumPumpState.PAUSED, MedtrumPumpState.HOURLY_MAX_SUSPENDED, MedtrumPumpState.DAILY_MAX_SUSPENDED - ) + medtrumPump.pumpState.isSuspendedByPump() ) updateGUI()