Medtrum: Allow reset of all suspended states

This commit is contained in:
jbr7rr 2023-09-17 17:59:59 +02:00
parent 9dee913977
commit 7627fcce7d
3 changed files with 7 additions and 10 deletions

View file

@ -27,6 +27,10 @@ enum class MedtrumPumpState(val state: Byte) {
NO_CALIBRATION(103), NO_CALIBRATION(103),
STOPPED(128.toByte()); STOPPED(128.toByte());
fun isSuspendedByPump(): Boolean {
return this in LOW_BG_SUSPENDED..SUSPENDED
}
companion object { companion object {
fun fromByte(state: Byte) = values().find { it.state == state } fun fromByte(state: Byte) = values().find { it.state == state }

View file

@ -281,13 +281,8 @@ class MedtrumService : DaggerService(), BLECommCallback {
} }
fun clearAlarms(): Boolean { fun clearAlarms(): Boolean {
var result = true var result = loadEvents() // Make sure we have all events before clearing alarms
if (medtrumPump.pumpState in listOf( if (result && medtrumPump.pumpState.isSuspendedByPump()) {
MedtrumPumpState.PAUSED,
MedtrumPumpState.HOURLY_MAX_SUSPENDED,
MedtrumPumpState.DAILY_MAX_SUSPENDED
)
) {
when (medtrumPump.pumpState) { when (medtrumPump.pumpState) {
MedtrumPumpState.HOURLY_MAX_SUSPENDED -> { MedtrumPumpState.HOURLY_MAX_SUSPENDED -> {
result = sendPacketAndGetResponse(ClearPumpAlarmPacket(injector, ALARM_HOURLY_MAX_CLEAR_CODE)) result = sendPacketAndGetResponse(ClearPumpAlarmPacket(injector, ALARM_HOURLY_MAX_CLEAR_CODE))

View file

@ -119,9 +119,7 @@ class MedtrumOverviewViewModel @Inject constructor(
medtrumPump.pumpStateFlow.collect { state -> medtrumPump.pumpStateFlow.collect { state ->
aapsLogger.debug(LTag.PUMP, "MedtrumViewModel pumpStateFlow: $state") aapsLogger.debug(LTag.PUMP, "MedtrumViewModel pumpStateFlow: $state")
_canDoResetAlarms.postValue( _canDoResetAlarms.postValue(
medtrumPump.pumpState in listOf( medtrumPump.pumpState.isSuspendedByPump()
MedtrumPumpState.PAUSED, MedtrumPumpState.HOURLY_MAX_SUSPENDED, MedtrumPumpState.DAILY_MAX_SUSPENDED
)
) )
updateGUI() updateGUI()