isSMBModeEnabled reactor & tests
This commit is contained in:
parent
26ecc3dd60
commit
c2cfe4e7ea
11 changed files with 48 additions and 21 deletions
|
@ -37,6 +37,10 @@ public class ConstraintChecker implements ConstraintsInterface {
|
||||||
return isAMAModeEnabled(new Constraint<>(true));
|
return isAMAModeEnabled(new Constraint<>(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Constraint<Boolean> isSMBModeEnabled() {
|
||||||
|
return isSMBModeEnabled(new Constraint<>(true));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
|
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
|
||||||
|
|
||||||
|
@ -86,16 +90,15 @@ public class ConstraintChecker implements ConstraintsInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSMBModeEnabled() {
|
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
|
||||||
boolean result = true; // TODO update for SMB // SP.getBoolean("openapsama_useautosens", false);
|
|
||||||
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||||
for (PluginBase p : constraintsPlugins) {
|
for (PluginBase p : constraintsPlugins) {
|
||||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
||||||
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
|
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
|
||||||
result = result && constrain.isSMBModeEnabled();
|
constraint.isSMBModeEnabled(value);
|
||||||
}
|
}
|
||||||
return result;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,7 +13,7 @@ public interface ConstraintsInterface {
|
||||||
|
|
||||||
Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value);
|
Constraint<Boolean> isAMAModeEnabled(Constraint<Boolean> value);
|
||||||
|
|
||||||
boolean isSMBModeEnabled();
|
Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value);
|
||||||
|
|
||||||
Double applyBasalConstraints(Double absoluteRate);
|
Double applyBasalConstraints(Double absoluteRate);
|
||||||
|
|
||||||
|
|
|
@ -327,8 +327,10 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSMBModeEnabled() {
|
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
|
||||||
return objectives.get(7).started.getTime() > 0;
|
if (objectives.get(7).started.getTime() == 0)
|
||||||
|
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 8));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -127,8 +127,11 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSMBModeEnabled() {
|
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
|
||||||
return true;
|
boolean enabled = SP.getBoolean(R.string.key_use_smb, false);
|
||||||
|
if (!enabled)
|
||||||
|
value.set(false, MainApp.gs(R.string.smbdisabledinpreferences));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -216,8 +216,6 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
|
|
||||||
String units = profile.getUnits();
|
String units = profile.getUnits();
|
||||||
|
|
||||||
Constraint<Boolean> closedLoopEnabled = MainApp.getConstraintChecker().isClosedLoopAllowed();
|
|
||||||
|
|
||||||
mProfile = new JSONObject();
|
mProfile = new JSONObject();
|
||||||
|
|
||||||
mProfile.put("max_iob", maxIob);
|
mProfile.put("max_iob", maxIob);
|
||||||
|
@ -247,7 +245,7 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
mProfile.put("remainingCarbsCap", SMBDefaults.remainingCarbsCap);
|
mProfile.put("remainingCarbsCap", SMBDefaults.remainingCarbsCap);
|
||||||
mProfile.put("enableUAM", SP.getBoolean(R.string.key_use_uam, false));
|
mProfile.put("enableUAM", SP.getBoolean(R.string.key_use_uam, false));
|
||||||
mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable);
|
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_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("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));
|
mProfile.put("allowSMB_with_high_temptarget", SMBEnabled && SP.getBoolean(R.string.key_allowSMB_with_high_temptarget, false));
|
||||||
|
|
|
@ -1448,8 +1448,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSMBModeEnabled() {
|
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
|
||||||
return true;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -454,8 +454,8 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSMBModeEnabled() {
|
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
|
||||||
return true;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("PointlessBooleanExpression")
|
@SuppressWarnings("PointlessBooleanExpression")
|
||||||
|
|
|
@ -294,8 +294,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSMBModeEnabled() {
|
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
|
||||||
return true;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1100,8 +1100,8 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSMBModeEnabled() {
|
public Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value) {
|
||||||
return true;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -967,5 +967,6 @@
|
||||||
<string name="novalidbasalrate">No valid basal rate read from pump</string>
|
<string name="novalidbasalrate">No valid basal rate read from pump</string>
|
||||||
<string name="closedmodedisabledinpreferences">Closed loop mode disabled in preferences</string>
|
<string name="closedmodedisabledinpreferences">Closed loop mode disabled in preferences</string>
|
||||||
<string name="amadisabledinpreferences">AMA disabled in preferences</string>
|
<string name="amadisabledinpreferences">AMA disabled in preferences</string>
|
||||||
|
<string name="smbdisabledinpreferences">SMB disabled in preferences</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,25 @@ public class ConstraintsCheckerTest {
|
||||||
Assert.assertEquals(Boolean.FALSE, c.get());
|
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
|
@Before
|
||||||
public void prepareMock() throws Exception {
|
public void prepareMock() throws Exception {
|
||||||
PowerMockito.mockStatic(ConfigBuilderPlugin.class);
|
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.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.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.amadisabledinpreferences)).thenReturn("AMA disabled in preferences");
|
||||||
|
when(MainApp.gs(R.string.smbdisabledinpreferences)).thenReturn("SMB disabled in preferences");
|
||||||
|
|
||||||
safetyPlugin = SafetyPlugin.getPlugin();
|
safetyPlugin = SafetyPlugin.getPlugin();
|
||||||
objectivesPlugin = ObjectivesPlugin.getPlugin();
|
objectivesPlugin = ObjectivesPlugin.getPlugin();
|
||||||
|
|
Loading…
Reference in a new issue