generic Constraint type

This commit is contained in:
Milos Kozak 2018-03-19 17:38:48 +01:00
parent 326229ebbb
commit 52ffcba047
23 changed files with 94 additions and 224 deletions

View file

@ -28,7 +28,7 @@ import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
@ -80,7 +80,6 @@ import info.nightscout.androidaps.receivers.KeepAliveReceiver;
import info.nightscout.androidaps.receivers.NSAlarmReceiver;
import info.nightscout.utils.FabricPrivacy;
import info.nightscout.utils.NSUpload;
import info.nightscout.utils.SP;
import io.fabric.sdk.android.Fabric;
@ -192,8 +191,6 @@ public class MainApp extends Application {
MainApp.getConfigBuilder().initialize();
}
NSUpload.uploadAppStart();
BooleanConstraint closedLoopEnabled = new BooleanConstraint(true);
MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled);
if (Config.NSCLIENT)
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-NSClient"));
@ -201,7 +198,7 @@ public class MainApp extends Application {
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-G5Uploader"));
else if (Config.PUMPCONTROL)
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-PumpControl"));
else if (closedLoopEnabled.get())
else if (MainApp.getConfigBuilder().limitClosedLoop(new Constraint<>(true)).get())
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-ClosedLoop"));
else
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-OpenLoop"));

View file

@ -1,15 +1,15 @@
package info.nightscout.androidaps.interfaces;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
/**
* Created by mike on 15.06.2016.
*/
public interface ConstraintsInterface {
void limitRunningLoop(BooleanConstraint value);
Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value);
void limitClosedLoop(BooleanConstraint value);
Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value);
boolean isAutosensModeEnabled();

View file

@ -1,29 +0,0 @@
package info.nightscout.androidaps.interfaces.constrains;
/**
* Created by mike on 19.03.2018.
*/
public class BooleanConstraint extends Constraint {
boolean value;
public BooleanConstraint(boolean value) {
this.value = value;
}
public boolean get() {
return value;
}
public BooleanConstraint set(boolean value) {
this.value = value;
return this;
}
public BooleanConstraint set(boolean value, String reason) {
this.value = value;
reason(reason);
return this;
}
}

View file

@ -7,9 +7,29 @@ import java.util.List;
* Created by mike on 19.03.2018.
*/
public class Constraint {
public class Constraint<T> {
T value;
List<String> reasons = new ArrayList<>();
public Constraint(T value) {
this.value = value;
}
public T get() {
return value;
}
public Constraint<T> set(T value) {
this.value = value;
return this;
}
public Constraint<T> set(T value, String reason) {
this.value = value;
reason(reason);
return this;
}
public Constraint reason(String reason) {
reasons.add(reason);
return this;

View file

@ -1,29 +0,0 @@
package info.nightscout.androidaps.interfaces.constrains;
/**
* Created by mike on 19.03.2018.
*/
public class DoubleConstraint extends Constraint{
double value;
public DoubleConstraint(double value) {
this.value = value;
}
public Double getDouble() {
return value;
}
public DoubleConstraint set(double value) {
this.value = value;
return this;
}
public DoubleConstraint set(double value, String reason) {
this.value = value;
reason(reason);
return this;
}
}

View file

@ -1,28 +0,0 @@
package info.nightscout.androidaps.interfaces.constrains;
/**
* Created by mike on 19.03.2018.
*/
public class IntegerConstraint extends Constraint {
int value;
public IntegerConstraint(int value) {
this.value = value;
}
public int getInteger() {
return value;
}
public IntegerConstraint set(int value) {
this.value = value;
return this;
}
public IntegerConstraint set(int value, String reason) {
this.value = value;
reason(reason);
return this;
}
}

View file

@ -31,7 +31,6 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppInitialized;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
@ -39,6 +38,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.SensitivityInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
@ -449,7 +449,7 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
* Constraints interface
**/
@Override
public void limitRunningLoop(BooleanConstraint value) {
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
@ -457,10 +457,11 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
constraint.limitRunningLoop(value);
}
return value;
}
@Override
public void limitClosedLoop(BooleanConstraint value) {
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
@ -468,6 +469,7 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
constraint.limitClosedLoop(value);
}
return value;
}
@Override

View file

@ -17,7 +17,7 @@ import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
@ -183,7 +183,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
case 2:
return new RequirementResult(true, "");
case 3:
BooleanConstraint closedLoopEnabled = new BooleanConstraint(true);
Constraint<Boolean> closedLoopEnabled = new Constraint<>(true);
SafetyPlugin.getPlugin().limitClosedLoop(closedLoopEnabled);
return new RequirementResult(closedLoopEnabled.get(), MainApp.sResources.getString(R.string.closedmodeenabled) + ": " + yesOrNo(closedLoopEnabled.get()));
case 4:
@ -295,15 +295,17 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
* Constraints interface
**/
@Override
public void limitRunningLoop(BooleanConstraint value) {
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
if (objectives.get(0).started.getTime() == 0)
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 1));
return value;
}
@Override
public void limitClosedLoop(BooleanConstraint value) {
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
if (objectives.get(3).started.getTime() == 0)
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 4));
return value;
}
@Override

View file

@ -10,9 +10,9 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.utils.HardLimits;
import info.nightscout.utils.Round;
@ -92,23 +92,25 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
return R.xml.pref_safety;
}
@Override
public void limitRunningLoop(BooleanConstraint value) {
if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable)
value.set(false, MainApp.gs(R.string.pumpisnottempbasalcapable));
}
/**
* Constraints interface
**/
@Override
public void limitClosedLoop(BooleanConstraint value) {
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable)
value.set(false, MainApp.gs(R.string.pumpisnottempbasalcapable));
return value;
}
@Override
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
if (!MainApp.isEngineeringModeOrRelease())
value.set(false, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch));
String mode = SP.getString("aps_mode", "open");
if (!mode.equals("closed"))
value.set(false, MainApp.gs(R.string.closedmodedisabledinpreferences));
return value;
}
@Override

View file

@ -28,7 +28,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
@ -259,7 +259,7 @@ public class LoopPlugin implements PluginBase {
try {
if (Config.logFunctionCalls)
log.debug("invoke from " + initiator);
BooleanConstraint loopEnabled = new BooleanConstraint(true);
Constraint<Boolean> loopEnabled = new Constraint<>(true);
MainApp.getConfigBuilder().limitRunningLoop(loopEnabled);
if (!loopEnabled.get()) {
@ -331,7 +331,7 @@ public class LoopPlugin implements PluginBase {
return;
}
BooleanConstraint closedLoopEnabled = new BooleanConstraint(true);
Constraint<Boolean> closedLoopEnabled = new Constraint<>(true);
MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled);
if (closedLoopEnabled.get()) {

View file

@ -19,7 +19,7 @@ import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
@ -249,12 +249,10 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
if (determineBasalResultAMA.rate == 0d && determineBasalResultAMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress())
determineBasalResultAMA.tempBasalReqested = false;
// limit requests on openloop mode
BooleanConstraint closedLoopEnabled = new BooleanConstraint(true);
MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled);
if (!closedLoopEnabled.get()) {
if (!MainApp.getConfigBuilder().limitClosedLoop(new Constraint<>(true)).get()) {
long now = System.currentTimeMillis();
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (activeTemp != null && determineBasalResultAMA.rate == 0 && determineBasalResultAMA.duration == 0) {
if (activeTemp != null && determineBasalResultAMA.rate == 0 && determineBasalResultAMA.duration == 0) {
// going to cancel
} else if (activeTemp != null && Math.abs(determineBasalResultAMA.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) {
determineBasalResultAMA.tempBasalReqested = false;

View file

@ -19,7 +19,7 @@ import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
@ -238,9 +238,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress())
determineBasalResultMA.tempBasalReqested = false;
// limit requests on openloop mode
BooleanConstraint closedLoopEnabled = new BooleanConstraint(true);
MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled);
if (!closedLoopEnabled.get()) {
if (!MainApp.getConfigBuilder().limitClosedLoop(new Constraint<>(true)).get()) {
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (activeTemp != null && determineBasalResultMA.rate == 0 && determineBasalResultMA.duration == 0) {
// going to cancel

View file

@ -27,7 +27,7 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
@ -216,7 +216,7 @@ public class DetermineBasalAdapterSMBJS {
String units = profile.getUnits();
BooleanConstraint closedLoopEnabled = new BooleanConstraint(true);
Constraint<Boolean> closedLoopEnabled = new Constraint<>(true);
MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled);
mProfile = new JSONObject();

View file

@ -19,7 +19,7 @@ import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
@ -254,9 +254,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
if (determineBasalResultSMB.rate == 0d && determineBasalResultSMB.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress())
determineBasalResultSMB.tempBasalReqested = false;
// limit requests on openloop mode
BooleanConstraint closedLoopEnabled = new BooleanConstraint(true);
MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled);
if (!closedLoopEnabled.get()) {
if (!MainApp.getConfigBuilder().limitClosedLoop(new Constraint<>(true)).get()) {
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now);
if (activeTemp != null && determineBasalResultSMB.rate == 0 && determineBasalResultSMB.duration == 0) {
// going to cancel

View file

@ -87,7 +87,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
@ -1017,7 +1017,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
}
BooleanConstraint closedLoopEnabled = new BooleanConstraint(true);
Constraint<Boolean> closedLoopEnabled = new Constraint<>(true);
MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled);
// open loop mode

View file

@ -28,11 +28,11 @@ import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
@ -1422,13 +1422,15 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
private boolean validBasalRateProfileSelectedOnPump = true;
@Override
public void limitRunningLoop(BooleanConstraint value) {
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
if (!validBasalRateProfileSelectedOnPump)
value.set(false, MainApp.gs(R.string.novalidbasalrate));
return value;
}
@Override
public void limitClosedLoop(BooleanConstraint value) {
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
return value;
}
@Override

View file

@ -19,13 +19,13 @@ import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.DanaRInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
@ -437,11 +437,13 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
*/
@Override
public void limitRunningLoop(BooleanConstraint value) {
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
return value;
}
@Override
public void limitClosedLoop(BooleanConstraint value) {
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
return value;
}
@Override

View file

@ -30,18 +30,18 @@ import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.DanaRInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
@ -275,11 +275,13 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
// Constraints interface
@Override
public void limitRunningLoop(BooleanConstraint value) {
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
return value;
}
@Override
public void limitClosedLoop(BooleanConstraint value) {
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
return value;
}
@Override

View file

@ -22,11 +22,11 @@ import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
@ -1080,11 +1080,13 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
// Constraints
@Override
public void limitRunningLoop(BooleanConstraint value){
public Constraint<Boolean> limitRunningLoop(Constraint<Boolean> value) {
return value;
}
@Override
public void limitClosedLoop(BooleanConstraint value) {
public Constraint<Boolean> limitClosedLoop(Constraint<Boolean> value) {
return value;
}
@Override

View file

@ -27,7 +27,7 @@ import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
@ -435,9 +435,7 @@ public class ActionStringHandler {
// decide if enabled/disabled closed/open; what Plugin as APS?
final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
if (activeloop != null && activeloop.isEnabled(activeloop.getType())) {
BooleanConstraint closedLoopEnabled = new BooleanConstraint(true);
MainApp.getConfigBuilder().limitClosedLoop(closedLoopEnabled);
if (closedLoopEnabled.get()) {
if (MainApp.getConfigBuilder().limitClosedLoop(new Constraint<>(true)).get()) {
ret += "CLOSED LOOP\n";
} else {
ret += "OPEN LOOP\n";

View file

@ -6,27 +6,30 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.constrains.Constraint;
/**
* Created by mike on 19.03.2018.
*/
@RunWith(PowerMockRunner.class)
public class BooleanConstraintTest {
public class ConstraintTest {
@Test
public void doTests() throws Exception {
BooleanConstraint c;
Constraint<Boolean> c;
c = new BooleanConstraint(true);
Assert.assertEquals(true, c.get());
c = new Constraint<Boolean>(true);
Assert.assertEquals(Boolean.TRUE, c.get());
Assert.assertEquals("", c.getReasons());
c.set(false);
Assert.assertEquals(false, c.get());
Assert.assertEquals(Boolean.FALSE, c.get());
Assert.assertEquals("", c.getReasons());
c.set(true, "Set true");
Assert.assertEquals(true, c.get());
Assert.assertEquals(Boolean.TRUE, c.get());
Assert.assertEquals("Set true", c.getReasons());
c.set(false, "Set false");
Assert.assertEquals(Boolean.FALSE, c.get());
Assert.assertEquals("Set true\nSet false", c.getReasons());
}
}

View file

@ -1,36 +0,0 @@
package info.nightscout.androidaps.interfaces.contraints;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import info.nightscout.androidaps.interfaces.constrains.DoubleConstraint;
/**
* Created by mike on 19.03.2018.
*/
@RunWith(PowerMockRunner.class)
public class DoubleConstraintTest {
@Test
public void doTests() throws Exception {
DoubleConstraint c;
c = new DoubleConstraint(10d);
Assert.assertEquals(10d, c.getDouble());
Assert.assertEquals("", c.getReasons());
c.set(11d);
Assert.assertEquals(11d, c.getDouble());
Assert.assertEquals("", c.getReasons());
c.set(9d, "Set 9d");
Assert.assertEquals(9d, c.getDouble());
Assert.assertEquals("Set 9d", c.getReasons());
c.set(8d, "Set 8d");
Assert.assertEquals(8d, c.getDouble());
Assert.assertEquals("Set 9d\nSet 8d", c.getReasons());
}
}

View file

@ -1,34 +0,0 @@
package info.nightscout.androidaps.interfaces.contraints;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import info.nightscout.androidaps.interfaces.constrains.BooleanConstraint;
import info.nightscout.androidaps.interfaces.constrains.IntegerConstraint;
/**
* Created by mike on 19.03.2018.
*/
@RunWith(PowerMockRunner.class)
public class IntegerConstraintTest {
@Test
public void doTests() throws Exception {
IntegerConstraint c;
c = new IntegerConstraint(10);
Assert.assertEquals(10, c.getInteger());
Assert.assertEquals("", c.getReasons());
c.set(11);
Assert.assertEquals(11, c.getInteger());
Assert.assertEquals("", c.getReasons());
c.set(9, "Set 9");
Assert.assertEquals(9, c.getInteger());
Assert.assertEquals("Set 9", c.getReasons());
}
}