isAMAModeEnabled reactor & tests
This commit is contained in:
parent
f8a3b7aee7
commit
26ecc3dd60
|
@ -33,6 +33,10 @@ public class ConstraintChecker implements ConstraintsInterface {
|
|||
return isAutosensModeEnabled(new Constraint<>(true));
|
||||
}
|
||||
|
||||
public Constraint<Boolean> isAMAModeEnabled() {
|
||||
return isAMAModeEnabled(new Constraint<>(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
|
||||
|
||||
|
@ -70,16 +74,15 @@ public class ConstraintChecker implements ConstraintsInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isAMAModeEnabled() {
|
||||
boolean result = SP.getBoolean("openapsama_useautosens", false);
|
||||
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||
|
||||
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||
for (PluginBase p : constraintsPlugins) {
|
||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
||||
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
|
||||
result = result && constrain.isAMAModeEnabled();
|
||||
constrain.isAMAModeEnabled(value);
|
||||
}
|
||||
return result;
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,7 +11,7 @@ public interface ConstraintsInterface {
|
|||
|
||||
Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value);
|
||||
|
||||
boolean isAMAModeEnabled();
|
||||
Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value);
|
||||
|
||||
boolean isSMBModeEnabled();
|
||||
|
||||
|
|
|
@ -320,8 +320,10 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isAMAModeEnabled() {
|
||||
return objectives.get(6).started.getTime() > 0;
|
||||
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||
if (objectives.get(6).started.getTime() == 0)
|
||||
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 7));
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -119,8 +119,11 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isAMAModeEnabled() {
|
||||
return true;
|
||||
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||
boolean enabled = SP.getBoolean("openapsama_useautosens", false);
|
||||
if (!enabled)
|
||||
value.set(false, MainApp.gs(R.string.amadisabledinpreferences));
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -250,7 +250,7 @@ public class DetermineBasalAdapterAMAJS {
|
|||
mMealData.put("boluses", mealData.boluses);
|
||||
mMealData.put("mealCOB", mealData.mealCOB);
|
||||
|
||||
if (MainApp.getConstraintChecker().isAMAModeEnabled()) {
|
||||
if (MainApp.getConstraintChecker().isAMAModeEnabled().get()) {
|
||||
mAutosensData = new JSONObject();
|
||||
mAutosensData.put("ratio", autosensDataRatio);
|
||||
} else {
|
||||
|
|
|
@ -223,7 +223,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
|||
return;
|
||||
|
||||
startPart = new Date();
|
||||
if (MainApp.getConstraintChecker().isAMAModeEnabled()) {
|
||||
if (MainApp.getConstraintChecker().isAMAModeEnabled().get()) {
|
||||
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis());
|
||||
} else {
|
||||
lastAutosensResult = new AutosensResult();
|
||||
|
|
|
@ -303,7 +303,7 @@ public class DetermineBasalAdapterSMBJS {
|
|||
mMealData.put("lastCarbTime", mealData.lastCarbTime);
|
||||
|
||||
|
||||
if (MainApp.getConstraintChecker().isAMAModeEnabled()) {
|
||||
if (MainApp.getConstraintChecker().isAMAModeEnabled().get()) {
|
||||
mAutosensData = new JSONObject();
|
||||
mAutosensData.put("ratio", autosensDataRatio);
|
||||
} else {
|
||||
|
|
|
@ -225,7 +225,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
|
|||
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal())) return;
|
||||
|
||||
startPart = new Date();
|
||||
if (MainApp.getConstraintChecker().isAMAModeEnabled()) {
|
||||
if (MainApp.getConstraintChecker().isAMAModeEnabled().get()) {
|
||||
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis());
|
||||
} else {
|
||||
lastAutosensResult = new AutosensResult();
|
||||
|
|
|
@ -1443,8 +1443,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isAMAModeEnabled() {
|
||||
return true;
|
||||
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -449,8 +449,8 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isAMAModeEnabled() {
|
||||
return true;
|
||||
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -289,8 +289,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isAMAModeEnabled() {
|
||||
return true;
|
||||
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1095,8 +1095,8 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isAMAModeEnabled() {
|
||||
return true;
|
||||
public Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -966,5 +966,6 @@
|
|||
<string name="pumpisnottempbasalcapable">Pump is not temp basal capable</string>
|
||||
<string name="novalidbasalrate">No valid basal rate read from pump</string>
|
||||
<string name="closedmodedisabledinpreferences">Closed loop mode disabled in preferences</string>
|
||||
<string name="amadisabledinpreferences">AMA disabled in preferences</string>
|
||||
</resources>
|
||||
|
||||
|
|
|
@ -117,6 +117,25 @@ public class ConstraintsCheckerTest {
|
|||
Assert.assertEquals(Boolean.FALSE, c.get());
|
||||
}
|
||||
|
||||
// isAMAModeEnabled tests
|
||||
@Test
|
||||
public void notEnabledAMAInPreferencesDisablesAMA() throws Exception {
|
||||
when(SP.getBoolean("openapsama_useautosens", false)).thenReturn(false);
|
||||
|
||||
Constraint<Boolean> c = constraintChecker.isAMAModeEnabled();
|
||||
Assert.assertEquals(true, c.getReasons().contains("AMA disabled in preferences"));
|
||||
Assert.assertEquals(Boolean.FALSE, c.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notStartedObjective7ShouldLimitAMAMode() throws Exception {
|
||||
objectivesPlugin.objectives.get(6).setStarted(new Date(0));
|
||||
|
||||
Constraint<Boolean> c = constraintChecker.isAMAModeEnabled();
|
||||
Assert.assertEquals(true, c.getReasons().contains("Objective 7 not started"));
|
||||
Assert.assertEquals(Boolean.FALSE, c.get());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepareMock() throws Exception {
|
||||
PowerMockito.mockStatic(ConfigBuilderPlugin.class);
|
||||
|
@ -137,6 +156,7 @@ public class ConstraintsCheckerTest {
|
|||
when(MainApp.gs(R.string.closedmodedisabledinpreferences)).thenReturn("Closed loop mode disabled in preferences");
|
||||
when(MainApp.gs(R.string.objectivenotstarted)).thenReturn("Objective %d not started");
|
||||
when(MainApp.gs(R.string.novalidbasalrate)).thenReturn("No valid basal rate read from pump");
|
||||
when(MainApp.gs(R.string.amadisabledinpreferences)).thenReturn("AMA disabled in preferences");
|
||||
|
||||
safetyPlugin = SafetyPlugin.getPlugin();
|
||||
objectivesPlugin = ObjectivesPlugin.getPlugin();
|
||||
|
|
Loading…
Reference in a new issue