Validate basal duration, fixes AAPS-Omnipod / AndroidAPS#13

Basal rate durations must be non-zero, and in the case of the Omnipod Pump or multiple of 30 minutes.

- Introduce OmnipodConstants.BASAL_STEP_DURATION
- throw IllegalArgumentException on validation failure in RateEntry.createEntries
- return failed PumpEnactResult and explanatory comments on validation failure in OmnipodPumpPlugin.setTempBasalAbsolute
This commit is contained in:
Sam Spycher 2020-10-07 22:02:28 +02:00
parent 3a6d1f286c
commit 8b3a32bb57
3 changed files with 16 additions and 0 deletions

View file

@ -97,6 +97,8 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import static info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.OmnipodConstants.BASAL_STEP_DURATION;
/**
* Created by andy on 23.04.18.
*
@ -537,6 +539,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
durationInMinutes, Profile profile, boolean enforceNew) {
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes);
if (durationInMinutes <= 0 || durationInMinutes % BASAL_STEP_DURATION.getStandardMinutes() != 0) {
return new PumpEnactResult(getInjector()).success(false).comment("TBR duration must be greater than zero and a multiple of " + BASAL_STEP_DURATION.getStandardMinutes() + " minutes.");
}
// read current TBR
TemporaryBasal tbrCurrent = readTBR();

View file

@ -14,6 +14,7 @@ public class OmnipodConstants {
public static final double MAX_RESERVOIR_READING = 50.0;
public static final double MAX_BOLUS = 30.0;
public static final double MAX_BASAL_RATE = 30.0;
public static final Duration BASAL_STEP_DURATION = Duration.standardMinutes(30);
public static final Duration MAX_TEMP_BASAL_DURATION = Duration.standardHours(12);
public static final int DEFAULT_ADDRESS = 0xffffffff;

View file

@ -9,6 +9,8 @@ import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.IRawRepresentable;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.OmnipodConstants;
import static info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.OmnipodConstants.BASAL_STEP_DURATION;
public class RateEntry implements IRawRepresentable {
private final double totalPulses;
@ -21,6 +23,13 @@ public class RateEntry implements IRawRepresentable {
}
public static List<RateEntry> createEntries(double rate, Duration duration) {
if (Duration.ZERO.equals(duration)) {
throw new IllegalArgumentException("Duration may not be 0 minutes.");
}
if (duration.getStandardMinutes() % BASAL_STEP_DURATION.getStandardMinutes() != 0) {
throw new IllegalArgumentException("Duration must be a multiple of " + BASAL_STEP_DURATION.getStandardMinutes() + " minutes.");
}
List<RateEntry> entries = new ArrayList<>();
int remainingSegments = (int) Math.round(duration.getStandardSeconds() / 1800.0);
double pulsesPerSegment = (int) Math.round(rate / OmnipodConstants.POD_PULSE_SIZE) / 2.0;