Prepare OmnipodManager and AapsOmnipodManager for configurable beeps

This commit is contained in:
Bart Sopers 2019-12-07 16:09:43 +01:00
parent 321f5eec3c
commit b186f01c11
3 changed files with 50 additions and 29 deletions

View file

@ -136,37 +136,37 @@ public class OmnipodManager {
executeAndVerify(() -> communicationService.executeAction(new AcknowledgeAlertsAction(podState, podState.getActiveAlerts()))); executeAndVerify(() -> communicationService.executeAction(new AcknowledgeAlertsAction(podState, podState.getActiveAlerts())));
} }
public synchronized void setBasalSchedule(BasalSchedule schedule) { public synchronized void setBasalSchedule(BasalSchedule schedule, boolean acknowledgementBeep) {
assertReadyForDelivery(); assertReadyForDelivery();
executeAndVerify(() -> communicationService.executeAction(new SetBasalScheduleAction(podState, schedule, executeAndVerify(() -> communicationService.executeAction(new SetBasalScheduleAction(podState, schedule,
false, podState.getScheduleOffset(), true))); false, podState.getScheduleOffset(), acknowledgementBeep)));
} }
public synchronized void setTemporaryBasal(TempBasalPair tempBasalPair) { public synchronized void setTemporaryBasal(TempBasalPair tempBasalPair, boolean acknowledgementBeep, boolean completionBeep) {
assertReadyForDelivery(); assertReadyForDelivery();
executeAndVerify(() -> communicationService.executeAction(new SetTempBasalAction(new SetTempBasalService(), executeAndVerify(() -> communicationService.executeAction(new SetTempBasalAction(new SetTempBasalService(),
podState, tempBasalPair.getInsulinRate(), Duration.standardMinutes(tempBasalPair.getDurationMinutes()), podState, tempBasalPair.getInsulinRate(), Duration.standardMinutes(tempBasalPair.getDurationMinutes()),
true, true))); acknowledgementBeep, completionBeep)));
} }
public synchronized void cancelTemporaryBasal() { public synchronized void cancelTemporaryBasal(boolean acknowledgementBeep) {
assertReadyForDelivery(); assertReadyForDelivery();
executeAndVerify(() -> communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.TEMP_BASAL, true))); executeAndVerify(() -> communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.TEMP_BASAL, acknowledgementBeep)));
} }
// Returns a SingleSubject that returns when the bolus has finished. // Returns a SingleSubject that returns when the bolus has finished.
// When a bolus is cancelled, it will return after cancellation and report the estimated units delivered // When a bolus is cancelled, it will return after cancellation and report the estimated units delivered
// Only throws OmnipodException[certainFailure=false] // Only throws OmnipodException[certainFailure=false]
public synchronized BolusCommandResult bolus(Double units, BolusProgressIndicationConsumer progressIndicationConsumer) { public synchronized BolusCommandResult bolus(Double units, boolean acknowledgementBeep, boolean completionBeep, BolusProgressIndicationConsumer progressIndicationConsumer) {
assertReadyForDelivery(); assertReadyForDelivery();
CommandDeliveryStatus commandDeliveryStatus = CommandDeliveryStatus.SUCCESS; CommandDeliveryStatus commandDeliveryStatus = CommandDeliveryStatus.SUCCESS;
try { try {
executeAndVerify(() -> communicationService.executeAction(new BolusAction(podState, units, true, true))); executeAndVerify(() -> communicationService.executeAction(new BolusAction(podState, units, acknowledgementBeep, completionBeep)));
} catch (OmnipodException ex) { } catch (OmnipodException ex) {
if (ex.isCertainFailure()) { if (ex.isCertainFailure()) {
throw ex; throw ex;
@ -236,7 +236,7 @@ public class OmnipodManager {
return new BolusCommandResult(commandDeliveryStatus, bolusCompletionSubject); return new BolusCommandResult(commandDeliveryStatus, bolusCompletionSubject);
} }
public synchronized void cancelBolus() { public synchronized void cancelBolus(boolean acknowledgementBeep) {
assertReadyForDelivery(); assertReadyForDelivery();
synchronized (bolusDataLock) { synchronized (bolusDataLock) {
@ -244,7 +244,7 @@ public class OmnipodManager {
throw new IllegalDeliveryStatusException(DeliveryStatus.BOLUS_IN_PROGRESS, podState.getLastDeliveryStatus()); throw new IllegalDeliveryStatusException(DeliveryStatus.BOLUS_IN_PROGRESS, podState.getLastDeliveryStatus());
} }
executeAndVerify(() -> communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.BOLUS, true))); executeAndVerify(() -> communicationService.executeAction(new CancelDeliveryAction(podState, DeliveryType.BOLUS, acknowledgementBeep)));
activeBolusData.getDisposables().dispose(); activeBolusData.getDisposables().dispose();
activeBolusData.getBolusCompletionSubject().onSuccess(new BolusDeliveryResult(activeBolusData.estimateUnitsDelivered())); activeBolusData.getBolusCompletionSubject().onSuccess(new BolusDeliveryResult(activeBolusData.estimateUnitsDelivered()));
@ -253,40 +253,40 @@ public class OmnipodManager {
} }
// CAUTION: cancels TBR and bolus // CAUTION: cancels TBR and bolus
public synchronized void suspendDelivery() { public synchronized void suspendDelivery(boolean acknowledgementBeep) {
assertReadyForDelivery(); assertReadyForDelivery();
executeAndVerify(() -> communicationService.executeAction(new CancelDeliveryAction(podState, EnumSet.allOf(DeliveryType.class), true))); executeAndVerify(() -> communicationService.executeAction(new CancelDeliveryAction(podState, EnumSet.allOf(DeliveryType.class), acknowledgementBeep)));
} }
public synchronized void resumeDelivery() { public synchronized void resumeDelivery(boolean acknowledgementBeep) {
assertReadyForDelivery(); assertReadyForDelivery();
executeAndVerify(() -> communicationService.executeAction(new SetBasalScheduleAction(podState, podState.getBasalSchedule(), executeAndVerify(() -> communicationService.executeAction(new SetBasalScheduleAction(podState, podState.getBasalSchedule(),
true, podState.getScheduleOffset(), true))); true, podState.getScheduleOffset(), acknowledgementBeep)));
} }
// CAUTION: cancels TBR and bolus // CAUTION: cancels TBR and bolus
// CAUTION: suspends and then resumes delivery. // CAUTION: suspends and then resumes delivery.
// If any error occurs during the command sequence, delivery could be suspended // If any error occurs during the command sequence, delivery could be suspended
public synchronized void setTime() { public synchronized void setTime(boolean acknowledgementBeeps) {
assertReadyForDelivery(); assertReadyForDelivery();
suspendDelivery(); suspendDelivery(acknowledgementBeeps);
// Joda seems to cache the default time zone, so we use the JVM's // Joda seems to cache the default time zone, so we use the JVM's
DateTimeZone.setDefault(DateTimeZone.forTimeZone(TimeZone.getDefault())); DateTimeZone.setDefault(DateTimeZone.forTimeZone(TimeZone.getDefault()));
podState.setTimeZone(DateTimeZone.getDefault()); podState.setTimeZone(DateTimeZone.getDefault());
resumeDelivery(); resumeDelivery(acknowledgementBeeps);
} }
public synchronized void deactivatePod() { public synchronized void deactivatePod(boolean acknowledgementBeep) {
if (podState == null) { if (podState == null) {
throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, null); throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, null);
} }
executeAndVerify(() -> communicationService.executeAction(new DeactivatePodAction(podState, true))); executeAndVerify(() -> communicationService.executeAction(new DeactivatePodAction(podState, acknowledgementBeep)));
resetPodState(); resetPodState();
} }

View file

@ -110,7 +110,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) { public PumpEnactResult deactivatePod(PodInitReceiver podInitReceiver) {
try { try {
delegate.deactivatePod(); delegate.deactivatePod(true);
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, false, comment); podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, false, comment);
@ -127,7 +127,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult setBasalProfile(Profile basalProfile) { public PumpEnactResult setBasalProfile(Profile basalProfile) {
try { try {
delegate.setBasalSchedule(mapProfileToBasalSchedule(basalProfile)); delegate.setBasalSchedule(mapProfileToBasalSchedule(basalProfile), isBasalBeepsEnabled());
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
@ -151,8 +151,11 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult setBolus(Double units/*, boolean isSmb*/) { public PumpEnactResult setBolus(Double units/*, boolean isSmb*/) {
OmnipodManager.BolusCommandResult bolusCommandResult; OmnipodManager.BolusCommandResult bolusCommandResult;
boolean beepsEnabled = /* isSmb ? isSmbBeepsEnabled() : */ isBolusBeepsEnabled();
try { try {
bolusCommandResult = delegate.bolus(units, /* isSmb ? null : */ bolusCommandResult = delegate.bolus(units, beepsEnabled, beepsEnabled, /* isSmb ? null : */
(estimatedUnitsDelivered, percentage) -> { (estimatedUnitsDelivered, percentage) -> {
EventOverviewBolusProgress progressUpdateEvent = EventOverviewBolusProgress.INSTANCE; EventOverviewBolusProgress progressUpdateEvent = EventOverviewBolusProgress.INSTANCE;
progressUpdateEvent.setStatus(getStringResource(R.string.bolusdelivering, units)); progressUpdateEvent.setStatus(getStringResource(R.string.bolusdelivering, units));
@ -188,7 +191,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult cancelBolus() { public PumpEnactResult cancelBolus() {
try { try {
delegate.cancelBolus(); delegate.cancelBolus(isBolusBeepsEnabled());
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
@ -199,8 +202,9 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) { public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) {
boolean beepsEnabled = isBasalBeepsEnabled();
try { try {
delegate.setTemporaryBasal(tempBasalPair); delegate.setTemporaryBasal(tempBasalPair, beepsEnabled, beepsEnabled);
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
@ -212,7 +216,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public PumpEnactResult cancelTemporaryBasal() { public PumpEnactResult cancelTemporaryBasal() {
try { try {
delegate.cancelTemporaryBasal(); delegate.cancelTemporaryBasal(isBasalBeepsEnabled());
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
@ -255,7 +259,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
public PumpEnactResult suspendDelivery() { public PumpEnactResult suspendDelivery() {
try { try {
delegate.suspendDelivery(); delegate.suspendDelivery(isBasalBeepsEnabled());
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
@ -266,7 +270,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
public PumpEnactResult resumeDelivery() { public PumpEnactResult resumeDelivery() {
try { try {
delegate.resumeDelivery(); delegate.resumeDelivery(isBasalBeepsEnabled());
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
@ -278,8 +282,10 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
// TODO should we add this to the OmnipodCommunicationManager interface? // TODO should we add this to the OmnipodCommunicationManager interface?
public PumpEnactResult setTime() { public PumpEnactResult setTime() {
try { try {
delegate.setTime(); // CAUTION cancels TBR
delegate.setTime(isBasalBeepsEnabled());
} catch (Exception ex) { } catch (Exception ex) {
// CAUTION pod could be suspended
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
return new PumpEnactResult().success(false).enacted(false).comment(comment); return new PumpEnactResult().success(false).enacted(false).comment(comment);
} }
@ -378,6 +384,21 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
return comment; return comment;
} }
private boolean isBolusBeepsEnabled() {
// TODO
return true;
}
private boolean isSmbBeepsEnabled() {
// TODO
return true;
}
private boolean isBasalBeepsEnabled() {
// TODO
return true;
}
private String getStringResource(int id, Object... args) { private String getStringResource(int id, Object... args) {
return MainApp.gs(id, args); return MainApp.gs(id, args);
} }

View file

@ -8,7 +8,7 @@ buildscript {
maven { url 'https://maven.fabric.io/public' } maven { url 'https://maven.fabric.io/public' }
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.5.2' classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms:google-services:4.3.3' classpath 'com.google.gms:google-services:4.3.3'
classpath 'io.fabric.tools:gradle:1.31.2' classpath 'io.fabric.tools:gradle:1.31.2'