From 3cb58133dd264931a0782bc4763d0b083ba61f68 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Tue, 24 Dec 2019 11:54:01 -0500 Subject: [PATCH] Use BeepConfigCommand as a workaround for strange beep behavior in CancelDeliveryCommand when cancelling multiple delivery types. --- .../comm/action/CancelDeliveryAction.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/CancelDeliveryAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/CancelDeliveryAction.java index 929928cd2b..edff5b48dd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/CancelDeliveryAction.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/CancelDeliveryAction.java @@ -1,10 +1,16 @@ package info.nightscout.androidaps.plugins.pump.omnipod.comm.action; +import java.util.ArrayList; import java.util.EnumSet; +import java.util.List; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.MessageBlock; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage; +import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.BeepConfigCommand; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.CancelDeliveryCommand; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.BeepConfigType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.BeepType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; @@ -13,7 +19,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.exception.ActionInitializ public class CancelDeliveryAction implements OmnipodAction { private final PodSessionState podState; private final EnumSet deliveryTypes; - private final BeepType beepType; + private final boolean acknowledgementBeep; public CancelDeliveryAction(PodSessionState podState, EnumSet deliveryTypes, boolean acknowledgementBeep) { @@ -25,11 +31,7 @@ public class CancelDeliveryAction implements OmnipodAction { } this.podState = podState; this.deliveryTypes = deliveryTypes; - if (acknowledgementBeep) { - beepType = BeepType.BIP_BIP; - } else { - beepType = BeepType.NO_BEEP; - } + this.acknowledgementBeep = acknowledgementBeep; } public CancelDeliveryAction(PodSessionState podState, DeliveryType deliveryType, @@ -39,7 +41,23 @@ public class CancelDeliveryAction implements OmnipodAction { @Override public StatusResponse execute(OmnipodCommunicationService communicationService) { - return communicationService.sendCommand(StatusResponse.class, podState, - new CancelDeliveryCommand(podState.getCurrentNonce(), beepType, deliveryTypes)); + List messageBlocks = new ArrayList<>(); + + messageBlocks.add(new CancelDeliveryCommand(podState.getCurrentNonce(), + acknowledgementBeep && deliveryTypes.size() == 1 ? BeepType.BIP_BIP : BeepType.NO_BEEP, deliveryTypes)); + + if (acknowledgementBeep && deliveryTypes.size() > 1) { + // Workaround for strange beep behaviour when cancelling multiple delivery types at the same time + + // FIXME we should use other constructor with all beep configs. + // Theoretically, if we would cancel multiple delivery types but not all, + // we should keep the beep config for delivery types that we're not cancelling. + // We currently have no use case that though, + // as we either cancel 1 type or all types, + messageBlocks.add(new BeepConfigCommand(BeepConfigType.BIP_BIP)); + } + + return communicationService.exchangeMessages(StatusResponse.class, podState, + new OmnipodMessage(podState.getAddress(), messageBlocks, podState.getMessageNumber())); } }