Only show reset alarms when it's needed

This commit is contained in:
jbr7rr 2023-07-09 16:47:23 +02:00
parent 592a45612c
commit b3a83a720d
3 changed files with 22 additions and 31 deletions

View file

@ -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)) {
if (result) result = sendPacketAndGetResponse(ResumePumpPacket(injector))
}
if (result) result = sendPacketAndGetResponse(ResumePumpPacket(injector))
return result
}

View file

@ -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) }

View file

@ -7,6 +7,9 @@
<variable
name="viewmodel"
type="info.nightscout.pump.medtrum.ui.viewmodel.MedtrumOverviewViewModel" />
<import type="android.view.View" />
</data>
<RelativeLayout
@ -645,6 +648,7 @@
android:enabled="@{viewmodel.canDoResetAlarms}"
android:maxLines="2"
android:text="@string/reset_alarms_label"
android:visibility="@{viewmodel.canDoResetAlarms ? View.VISIBLE : View.GONE}"
app:onSafeClick="@{() -> viewmodel.onClickResetAlarms()}" />
<!-- Change Patch button -->