Only update basal from Notification when it has changed
This commit is contained in:
parent
3c8faa6723
commit
cd65639abb
3 changed files with 7 additions and 5 deletions
|
@ -151,8 +151,6 @@ import kotlin.math.round
|
||||||
override fun connect(reason: String) {
|
override fun connect(reason: String) {
|
||||||
if (medtrumPump.patchActivated) {
|
if (medtrumPump.patchActivated) {
|
||||||
aapsLogger.debug(LTag.PUMP, "Medtrum connect - reason:$reason")
|
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) {
|
if (medtrumService != null) {
|
||||||
aapsLogger.debug(LTag.PUMP, "Medtrum connect - Attempt connection!")
|
aapsLogger.debug(LTag.PUMP, "Medtrum connect - Attempt connection!")
|
||||||
val success = medtrumService?.connect(reason) ?: false
|
val success = medtrumService?.connect(reason) ?: false
|
||||||
|
|
|
@ -306,6 +306,7 @@ class MedtrumPump @Inject constructor(
|
||||||
LTag.PUMP,
|
LTag.PUMP,
|
||||||
"handleBasalStatusUpdate: basalType: $basalType basalValue: $basalRate basalSequence: $basalSequence basalPatchId: $basalPatchId basalStartTime: $basalStartTime " + "receivedTime: $receivedTime"
|
"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
|
val expectedTemporaryBasal = pumpSync.expectedPumpState()?.temporaryBasal
|
||||||
if (basalType.isTempBasal() && expectedTemporaryBasal?.pumpId != basalStartTime) {
|
if (basalType.isTempBasal() && expectedTemporaryBasal?.pumpId != basalStartTime) {
|
||||||
// Note: temporaryBasalInfo will be removed from temporaryBasalStorage after this call
|
// Note: temporaryBasalInfo will be removed from temporaryBasalStorage after this call
|
||||||
|
|
|
@ -114,15 +114,18 @@ class NotificationPacket(val injector: HasAndroidInjector) {
|
||||||
val basalType = enumValues<BasalType>()[data.copyOfRange(offset, offset + 1).toInt()]
|
val basalType = enumValues<BasalType>()[data.copyOfRange(offset, offset + 1).toInt()]
|
||||||
var basalSequence = data.copyOfRange(offset + 1, offset + 3).toInt()
|
var basalSequence = data.copyOfRange(offset + 1, offset + 3).toInt()
|
||||||
var basalPatchId = data.copyOfRange(offset + 3, offset + 5).toLong()
|
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 basalRateAndDelivery = data.copyOfRange(offset + 9, offset + 12).toInt()
|
||||||
var basalRate = (basalRateAndDelivery and 0xFFF) * 0.05
|
var basalRate = (basalRateAndDelivery and 0xFFF) * 0.05
|
||||||
var basalDelivery = (basalRateAndDelivery shr 12) * 0.05
|
var basalDelivery = (basalRateAndDelivery shr 12) * 0.05
|
||||||
aapsLogger.debug(
|
aapsLogger.debug(
|
||||||
LTag.PUMPCOMM,
|
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
|
offset += 12
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue