From b3a83a720daae36274077081788874453ac1eccb Mon Sep 17 00:00:00 2001
From: jbr7rr <>
Date: Sun, 9 Jul 2023 16:47:23 +0200
Subject: [PATCH] Only show reset alarms when it's needed
---
.../pump/medtrum/services/MedtrumService.kt | 31 ++++++-------------
.../ui/viewmodel/MedtrumOverviewViewModel.kt | 18 +++++------
.../res/layout/fragment_medtrum_overview.xml | 4 +++
3 files changed, 22 insertions(+), 31 deletions(-)
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 4e596e61b8..ec4f9e06bc 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
@@ -225,7 +225,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
if (needLoadHistory) {
if (result) result = loadEvents()
}
- if (result) medtrumPump.needCheckTimeUpdate = false
+ if (result) medtrumPump.needCheckTimeUpdate = false
return result
}
@@ -238,15 +238,18 @@ class MedtrumService : DaggerService(), BLECommCallback {
medtrumPump.lastConnection = System.currentTimeMillis()
} else {
aapsLogger.error(LTag.PUMPCOMM, "Failed to load events")
- // TODO: remove me before release
- fabricPrivacy.logMessage("Medtrum LoadEvents: Failed to load events")
}
return result
}
fun clearAlarms(): Boolean {
var result = true
- if (medtrumPump.activeAlarms.isNotEmpty()) {
+ if (medtrumPump.pumpState in listOf(
+ MedtrumPumpState.PAUSED,
+ MedtrumPumpState.HMAX_SUSPENDED,
+ MedtrumPumpState.DMAX_SUSPENDED
+ )
+ ) {
when (medtrumPump.pumpState) {
MedtrumPumpState.HMAX_SUSPENDED -> {
result = sendPacketAndGetResponse(ClearPumpAlarmPacket(injector, ALARM_HOURLY_MAX_CLEAR_CODE))
@@ -257,26 +260,12 @@ class MedtrumService : DaggerService(), BLECommCallback {
}
else -> {
- // TODO: Remove me before release!!!
- // Try to brute force the commands
- aapsLogger.warn(LTag.PUMPCOMM, "Trying to clear alarms brutus!")
- for (i in 0..100) {
- result = sendPacketAndGetResponse(ClearPumpAlarmPacket(injector, i))
- if (result) {
- aapsLogger.warn(LTag.PUMPCOMM, "Alarm cleared: $i")
- break
- }
- SystemClock.sleep(50)
- }
+ // Nothing to reset
}
}
- }
- // Resume suspended pump
- if (medtrumPump.pumpState in listOf(MedtrumPumpState.LOWBG_SUSPENDED, MedtrumPumpState.PAUSED)) {
+ // Resume suspended pump
if (result) result = sendPacketAndGetResponse(ResumePumpPacket(injector))
}
- if (result) result = sendPacketAndGetResponse(ResumePumpPacket(injector))
-
return result
}
@@ -695,7 +684,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
responseSuccess = true
// Check if we have a supported pump
if (medtrumPump.pumpType() == PumpType.MEDTRUM_UNTESTED) {
- // Throw error
+ // Throw error
aapsLogger.error(LTag.PUMPCOMM, "Unsupported pump type")
uiInteraction.addNotificationWithSound(
Notification.PUMP_ERROR,
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 4327f7c2ff..4eca101bda 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
@@ -107,11 +107,12 @@ class MedtrumOverviewViewModel @Inject constructor(
scope.launch {
medtrumPump.pumpStateFlow.collect { state ->
aapsLogger.debug(LTag.PUMP, "MedtrumViewModel pumpStateFlow: $state")
- if (medtrumPump.pumpState > MedtrumPumpState.EJECTED && medtrumPump.pumpState < MedtrumPumpState.STOPPED) {
- _canDoResetAlarms.postValue(true)
- } else {
- _canDoResetAlarms.postValue(false)
- }
+ _canDoResetAlarms.postValue(
+ medtrumPump.pumpState in listOf(
+ MedtrumPumpState.PAUSED, MedtrumPumpState.HMAX_SUSPENDED, MedtrumPumpState.DMAX_SUSPENDED
+ )
+ )
+
updateGUI()
}
}
@@ -161,13 +162,10 @@ class MedtrumOverviewViewModel @Inject constructor(
// max 6h back
_lastBolus.postValue(
dateUtil.timeString(medtrumPump.lastBolusTime) + " " + dateUtil.sinceString(medtrumPump.lastBolusTime, rh) + " " + rh.gs(
- info.nightscout.interfaces.R.string
- .format_insulin_units, medtrumPump
- .lastBolusAmount
+ info.nightscout.interfaces.R.string.format_insulin_units, medtrumPump.lastBolusAmount
)
)
- else
- _lastBolus.postValue("")
+ else _lastBolus.postValue("")
}
val activeAlarmStrings = medtrumPump.activeAlarms.map { medtrumPump.alarmStateToString(it) }
diff --git a/pump/medtrum/src/main/res/layout/fragment_medtrum_overview.xml b/pump/medtrum/src/main/res/layout/fragment_medtrum_overview.xml
index 70b0de5fee..0e4d866939 100644
--- a/pump/medtrum/src/main/res/layout/fragment_medtrum_overview.xml
+++ b/pump/medtrum/src/main/res/layout/fragment_medtrum_overview.xml
@@ -7,6 +7,9 @@
+
+
+