isSMBModeEnabled reactor & tests

This commit is contained in:
Milos Kozak 2018-03-19 23:14:04 +01:00
parent 26ecc3dd60
commit c2cfe4e7ea
11 changed files with 48 additions and 21 deletions

View file

@ -37,6 +37,10 @@ public class ConstraintChecker implements ConstraintsInterface {
return isAMAModeEnabled(new Constraint<>(true));
}
public Constraint<Boolean> isSMBModeEnabled() {
return isSMBModeEnabled(new Constraint<>(true));
}
@Override
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
@ -86,16 +90,15 @@ public class ConstraintChecker implements ConstraintsInterface {
}
@Override
public boolean isSMBModeEnabled() {
boolean result = true; // TODO update for SMB // SP.getBoolean("openapsama_useautosens", false);
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
ConstraintsInterface constraint = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
result = result && constrain.isSMBModeEnabled();
constraint.isSMBModeEnabled(value);
}
return result;
return value;
}
@Override

View file

@ -13,7 +13,7 @@ public interface ConstraintsInterface {
Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value);
boolean isSMBModeEnabled();
Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value);
Double applyBasalConstraints(Double absoluteRate);

View file

@ -327,8 +327,10 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
}
@Override
public boolean isSMBModeEnabled() {
return objectives.get(7).started.getTime() > 0;
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
if (objectives.get(7).started.getTime() == 0)
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 8));
return value;
}
@Override

View file

@ -127,8 +127,11 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
}
@Override
public boolean isSMBModeEnabled() {
return true;
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
boolean enabled = SP.getBoolean(R.string.key_use_smb, false);
if (!enabled)
value.set(false, MainApp.gs(R.string.smbdisabledinpreferences));
return value;
}
@Override

View file

@ -216,8 +216,6 @@ public class DetermineBasalAdapterSMBJS {
String units = profile.getUnits();
Constraint<Boolean> closedLoopEnabled = MainApp.getConstraintChecker().isClosedLoopAllowed();
mProfile = new JSONObject();
mProfile.put("max_iob", maxIob);
@ -247,7 +245,7 @@ public class DetermineBasalAdapterSMBJS {
mProfile.put("remainingCarbsCap", SMBDefaults.remainingCarbsCap);
mProfile.put("enableUAM", SP.getBoolean(R.string.key_use_uam, false));
mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable);
boolean SMBEnabled = SP.getBoolean(R.string.key_use_smb, false) && closedLoopEnabled.get();
boolean SMBEnabled = MainApp.getConstraintChecker().isSMBModeEnabled().get() && MainApp.getConstraintChecker().isClosedLoopAllowed().get();
mProfile.put("enableSMB_with_COB", SMBEnabled && SP.getBoolean(R.string.key_enableSMB_with_COB, false));
mProfile.put("enableSMB_with_temptarget", SMBEnabled && SP.getBoolean(R.string.key_enableSMB_with_temptarget, false));
mProfile.put("allowSMB_with_high_temptarget", SMBEnabled && SP.getBoolean(R.string.key_allowSMB_with_high_temptarget, false));

View file

@ -1448,8 +1448,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
@Override
public boolean isSMBModeEnabled() {
return true;
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
return value;
}
@Override

View file

@ -454,8 +454,8 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
}
@Override
public boolean isSMBModeEnabled() {
return true;
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
return value;
}
@SuppressWarnings("PointlessBooleanExpression")

View file

@ -294,8 +294,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
}
@Override
public boolean isSMBModeEnabled() {
return true;
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
return value;
}
@Override

View file

@ -1100,8 +1100,8 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
}
@Override
public boolean isSMBModeEnabled() {
return true;
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
return value;
}
@Override

View file

@ -967,5 +967,6 @@
<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>
<string name="smbdisabledinpreferences">SMB disabled in preferences</string>
</resources>

View file

@ -136,6 +136,25 @@ public class ConstraintsCheckerTest {
Assert.assertEquals(Boolean.FALSE, c.get());
}
// isSMBModeEnabled tests
@Test
public void notEnabledSMBInPreferencesDisablesSMB() throws Exception {
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false);
Constraint<Boolean> c = constraintChecker.isSMBModeEnabled();
Assert.assertEquals(true, c.getReasons().contains("SMB disabled in preferences"));
Assert.assertEquals(Boolean.FALSE, c.get());
}
@Test
public void notStartedObjective8ShouldLimitSMBMode() throws Exception {
objectivesPlugin.objectives.get(7).setStarted(new Date(0));
Constraint<Boolean> c = constraintChecker.isSMBModeEnabled();
Assert.assertEquals(true, c.getReasons().contains("Objective 8 not started"));
Assert.assertEquals(Boolean.FALSE, c.get());
}
@Before
public void prepareMock() throws Exception {
PowerMockito.mockStatic(ConfigBuilderPlugin.class);
@ -157,6 +176,7 @@ public class ConstraintsCheckerTest {
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");
when(MainApp.gs(R.string.smbdisabledinpreferences)).thenReturn("SMB disabled in preferences");
safetyPlugin = SafetyPlugin.getPlugin();
objectivesPlugin = ObjectivesPlugin.getPlugin();