Use BeepConfigCommand as a workaround for strange beep behavior in CancelDeliveryCommand when cancelling multiple delivery types.

This commit is contained in:
Bart Sopers 2019-12-24 11:54:01 -05:00
parent 1e003ad188
commit 3cb58133dd

View file

@ -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<StatusResponse> {
private final PodSessionState podState;
private final EnumSet<DeliveryType> deliveryTypes;
private final BeepType beepType;
private final boolean acknowledgementBeep;
public CancelDeliveryAction(PodSessionState podState, EnumSet<DeliveryType> deliveryTypes,
boolean acknowledgementBeep) {
@ -25,11 +31,7 @@ public class CancelDeliveryAction implements OmnipodAction<StatusResponse> {
}
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<StatusResponse> {
@Override
public StatusResponse execute(OmnipodCommunicationService communicationService) {
return communicationService.sendCommand(StatusResponse.class, podState,
new CancelDeliveryCommand(podState.getCurrentNonce(), beepType, deliveryTypes));
List<MessageBlock> 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()));
}
}