From cd65639abb1e68b21908f2f24d0397959fcea83c Mon Sep 17 00:00:00 2001 From: jbr7rr <> Date: Mon, 29 May 2023 20:05:21 +0200 Subject: [PATCH] Only update basal from Notification when it has changed --- .../java/info/nightscout/pump/medtrum/MedtrumPlugin.kt | 2 -- .../java/info/nightscout/pump/medtrum/MedtrumPump.kt | 1 + .../pump/medtrum/comm/packets/NotificationPacket.kt | 9 ++++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt index 2d154856c5..80ba861529 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt @@ -151,8 +151,6 @@ import kotlin.math.round override fun connect(reason: String) { if (medtrumPump.patchActivated) { aapsLogger.debug(LTag.PUMP, "Medtrum connect - reason:$reason") - aapsLogger.debug(LTag.PUMP, "Medtrum connect - service::$medtrumService") - // aapsLogger.debug(LTag.PUMP, "Medtrum connect - mDeviceSN:$mDeviceSN") if (medtrumService != null) { aapsLogger.debug(LTag.PUMP, "Medtrum connect - Attempt connection!") val success = medtrumService?.connect(reason) ?: false diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPump.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPump.kt index 330bbdaaef..6c85391c21 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPump.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPump.kt @@ -306,6 +306,7 @@ class MedtrumPump @Inject constructor( LTag.PUMP, "handleBasalStatusUpdate: basalType: $basalType basalValue: $basalRate basalSequence: $basalSequence basalPatchId: $basalPatchId basalStartTime: $basalStartTime " + "receivedTime: $receivedTime" ) + @Suppress("UNNECESSARY_SAFE_CALL") // Safe call to allow mocks to retun null val expectedTemporaryBasal = pumpSync.expectedPumpState()?.temporaryBasal if (basalType.isTempBasal() && expectedTemporaryBasal?.pumpId != basalStartTime) { // Note: temporaryBasalInfo will be removed from temporaryBasalStorage after this call diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/NotificationPacket.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/NotificationPacket.kt index 6c9695f624..7b231ac4b8 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/NotificationPacket.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/NotificationPacket.kt @@ -114,15 +114,18 @@ class NotificationPacket(val injector: HasAndroidInjector) { val basalType = enumValues()[data.copyOfRange(offset, offset + 1).toInt()] var basalSequence = data.copyOfRange(offset + 1, offset + 3).toInt() var basalPatchId = data.copyOfRange(offset + 3, offset + 5).toLong() - var basalTime = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(offset + 5, offset + 9).toLong()) + var basalStartTime = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(offset + 5, offset + 9).toLong()) var basalRateAndDelivery = data.copyOfRange(offset + 9, offset + 12).toInt() var basalRate = (basalRateAndDelivery and 0xFFF) * 0.05 var basalDelivery = (basalRateAndDelivery shr 12) * 0.05 aapsLogger.debug( LTag.PUMPCOMM, - "Basal type: $basalType, basal sequence: $basalSequence, basal patch id: $basalPatchId, basal time: $basalTime, basal rate: $basalRate, basal delivery: $basalDelivery" + "Basal type: $basalType, basal sequence: $basalSequence, basal patch id: $basalPatchId, basal time: $basalStartTime, basal rate: $basalRate, basal delivery: $basalDelivery" ) - medtrumPump.handleBasalStatusUpdate(basalType, basalRate, basalSequence, basalPatchId, basalTime) + // Don't spam with basal updates here, only if the running basal rate has changed, or a new basal is set + if (medtrumPump.lastBasalRate != basalRate || medtrumPump.lastBasalStartTime != basalStartTime) { + medtrumPump.handleBasalStatusUpdate(basalType, basalRate, basalSequence, basalPatchId, basalStartTime) + } offset += 12 }