ActionLoopDisableTest
This commit is contained in:
parent
72ba6815d8
commit
f19e782c7c
39 changed files with 263 additions and 254 deletions
|
@ -5,6 +5,7 @@ import org.json.JSONObject;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
|
@ -12,8 +13,8 @@ import info.nightscout.androidaps.utils.Round;
|
|||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||
|
||||
public class PumpEnactResult {
|
||||
@Inject AAPSLogger aapsLogger;
|
||||
@Inject ResourceHelper resourceHelper;
|
||||
@Inject public AAPSLogger aapsLogger;
|
||||
@Inject public ResourceHelper resourceHelper;
|
||||
|
||||
public boolean success = false; // request was processed successfully (but possible no change was needed)
|
||||
public boolean enacted = false; // request was processed successfully and change has been made
|
||||
|
@ -31,6 +32,10 @@ public class PumpEnactResult {
|
|||
|
||||
public boolean queued = false;
|
||||
|
||||
public PumpEnactResult(HasAndroidInjector injector) {
|
||||
injector.androidInjector().inject(this);
|
||||
}
|
||||
|
||||
public PumpEnactResult success(boolean success) {
|
||||
this.success = success;
|
||||
return this;
|
||||
|
@ -192,8 +197,4 @@ public class PumpEnactResult {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static PumpEnactResult error(String message) {
|
||||
return new PumpEnactResult().enacted(false).success(false).comment(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -408,7 +408,7 @@ public class LoopPlugin extends PluginBase {
|
|||
if (resultAfterConstraints.isChangeRequested()
|
||||
&& !commandQueue.bolusInQueue()
|
||||
&& !commandQueue.isRunning(Command.CommandType.BOLUS)) {
|
||||
final PumpEnactResult waiting = new PumpEnactResult();
|
||||
final PumpEnactResult waiting = new PumpEnactResult(getInjector());
|
||||
waiting.queued = true;
|
||||
if (resultAfterConstraints.tempBasalRequested)
|
||||
lastRun.tbrSetByPump = waiting;
|
||||
|
@ -532,7 +532,7 @@ public class LoopPlugin extends PluginBase {
|
|||
|
||||
if (!request.tempBasalRequested) {
|
||||
if (callback != null) {
|
||||
callback.result(new PumpEnactResult().enacted(false).success(true).comment(resourceHelper.gs(R.string.nochangerequested))).run();
|
||||
callback.result(new PumpEnactResult(getInjector()).enacted(false).success(true).comment(resourceHelper.gs(R.string.nochangerequested))).run();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -540,14 +540,14 @@ public class LoopPlugin extends PluginBase {
|
|||
PumpInterface pump = configBuilderPlugin.getActivePumpPlugin();
|
||||
if (pump == null) {
|
||||
if (callback != null)
|
||||
callback.result(new PumpEnactResult().enacted(false).success(false).comment(resourceHelper.gs(R.string.nopumpselected))).run();
|
||||
callback.result(new PumpEnactResult(getInjector()).enacted(false).success(false).comment(resourceHelper.gs(R.string.nopumpselected))).run();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pump.isInitialized()) {
|
||||
getAapsLogger().debug(LTag.APS, "applyAPSRequest: " + resourceHelper.gs(R.string.pumpNotInitialized));
|
||||
if (callback != null) {
|
||||
callback.result(new PumpEnactResult().comment(resourceHelper.gs(R.string.pumpNotInitialized)).enacted(false).success(false)).run();
|
||||
callback.result(new PumpEnactResult(getInjector()).comment(resourceHelper.gs(R.string.pumpNotInitialized)).enacted(false).success(false)).run();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -555,7 +555,7 @@ public class LoopPlugin extends PluginBase {
|
|||
if (pump.isSuspended()) {
|
||||
getAapsLogger().debug(LTag.APS, "applyAPSRequest: " + resourceHelper.gs(R.string.pumpsuspended));
|
||||
if (callback != null) {
|
||||
callback.result(new PumpEnactResult().comment(resourceHelper.gs(R.string.pumpsuspended)).enacted(false).success(false)).run();
|
||||
callback.result(new PumpEnactResult(getInjector()).comment(resourceHelper.gs(R.string.pumpsuspended)).enacted(false).success(false)).run();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -572,7 +572,7 @@ public class LoopPlugin extends PluginBase {
|
|||
} else {
|
||||
getAapsLogger().debug(LTag.APS, "applyAPSRequest: Basal set correctly");
|
||||
if (callback != null) {
|
||||
callback.result(new PumpEnactResult().percent(request.percent).duration(0)
|
||||
callback.result(new PumpEnactResult(getInjector()).percent(request.percent).duration(0)
|
||||
.enacted(false).success(true).comment(resourceHelper.gs(R.string.basal_set_correctly))).run();
|
||||
}
|
||||
}
|
||||
|
@ -582,7 +582,7 @@ public class LoopPlugin extends PluginBase {
|
|||
&& request.percent == activeTemp.percentRate) {
|
||||
getAapsLogger().debug(LTag.APS, "applyAPSRequest: Temp basal set correctly");
|
||||
if (callback != null) {
|
||||
callback.result(new PumpEnactResult().percent(request.percent)
|
||||
callback.result(new PumpEnactResult(getInjector()).percent(request.percent)
|
||||
.enacted(false).success(true).duration(activeTemp.getPlannedRemainingMinutes())
|
||||
.comment(resourceHelper.gs(R.string.let_temp_basal_run))).run();
|
||||
}
|
||||
|
@ -598,7 +598,7 @@ public class LoopPlugin extends PluginBase {
|
|||
} else {
|
||||
getAapsLogger().debug(LTag.APS, "applyAPSRequest: Basal set correctly");
|
||||
if (callback != null) {
|
||||
callback.result(new PumpEnactResult().absolute(request.rate).duration(0)
|
||||
callback.result(new PumpEnactResult(getInjector()).absolute(request.rate).duration(0)
|
||||
.enacted(false).success(true).comment(resourceHelper.gs(R.string.basal_set_correctly))).run();
|
||||
}
|
||||
}
|
||||
|
@ -608,7 +608,7 @@ public class LoopPlugin extends PluginBase {
|
|||
&& Math.abs(request.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < pump.getPumpDescription().basalStep) {
|
||||
getAapsLogger().debug(LTag.APS, "applyAPSRequest: Temp basal set correctly");
|
||||
if (callback != null) {
|
||||
callback.result(new PumpEnactResult().absolute(activeTemp.tempBasalConvertedToAbsolute(now, profile))
|
||||
callback.result(new PumpEnactResult(getInjector()).absolute(activeTemp.tempBasalConvertedToAbsolute(now, profile))
|
||||
.enacted(false).success(true).duration(activeTemp.getPlannedRemainingMinutes())
|
||||
.comment(resourceHelper.gs(R.string.let_temp_basal_run))).run();
|
||||
}
|
||||
|
@ -627,7 +627,7 @@ public class LoopPlugin extends PluginBase {
|
|||
PumpInterface pump = configBuilderPlugin.getActivePumpPlugin();
|
||||
if (pump == null) {
|
||||
if (callback != null)
|
||||
callback.result(new PumpEnactResult().enacted(false).success(false).comment(resourceHelper.gs(R.string.nopumpselected))).run();
|
||||
callback.result(new PumpEnactResult(getInjector()).enacted(false).success(false).comment(resourceHelper.gs(R.string.nopumpselected))).run();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -635,7 +635,7 @@ public class LoopPlugin extends PluginBase {
|
|||
if (lastBolusTime != 0 && lastBolusTime + 3 * 60 * 1000 > System.currentTimeMillis()) {
|
||||
getAapsLogger().debug(LTag.APS, "SMB requested but still in 3 min interval");
|
||||
if (callback != null) {
|
||||
callback.result(new PumpEnactResult()
|
||||
callback.result(new PumpEnactResult(getInjector())
|
||||
.comment(resourceHelper.gs(R.string.smb_frequency_exceeded))
|
||||
.enacted(false).success(false)).run();
|
||||
}
|
||||
|
@ -645,7 +645,7 @@ public class LoopPlugin extends PluginBase {
|
|||
if (!pump.isInitialized()) {
|
||||
getAapsLogger().debug(LTag.APS, "applySMBRequest: " + resourceHelper.gs(R.string.pumpNotInitialized));
|
||||
if (callback != null) {
|
||||
callback.result(new PumpEnactResult().comment(resourceHelper.gs(R.string.pumpNotInitialized)).enacted(false).success(false)).run();
|
||||
callback.result(new PumpEnactResult(getInjector()).comment(resourceHelper.gs(R.string.pumpNotInitialized)).enacted(false).success(false)).run();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -653,7 +653,7 @@ public class LoopPlugin extends PluginBase {
|
|||
if (pump.isSuspended()) {
|
||||
getAapsLogger().debug(LTag.APS, "applySMBRequest: " + resourceHelper.gs(R.string.pumpsuspended));
|
||||
if (callback != null) {
|
||||
callback.result(new PumpEnactResult().comment(resourceHelper.gs(R.string.pumpsuspended)).enacted(false).success(false)).run();
|
||||
callback.result(new PumpEnactResult(getInjector()).comment(resourceHelper.gs(R.string.pumpsuspended)).enacted(false).success(false)).run();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class ActionLoopDisable(injector: HasAndroidInjector) : Action(injector) {
|
|||
}
|
||||
})
|
||||
} else {
|
||||
callback.result(PumpEnactResult().success(true).comment(R.string.alreadydisabled)).run()
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.alreadydisabled)).run()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ class ActionLoopEnable(injector: HasAndroidInjector) : Action(injector) {
|
|||
loopPlugin.setPluginEnabled(PluginType.LOOP, true)
|
||||
configBuilderPlugin.storeSettings("ActionLoopEnable")
|
||||
rxBus.send(EventRefreshOverview("ActionLoopEnable"))
|
||||
callback.result(PumpEnactResult().success(true).comment(R.string.ok))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
|
||||
} else {
|
||||
callback.result(PumpEnactResult().success(true).comment(R.string.alreadyenabled))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.alreadyenabled))?.run()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@ class ActionLoopResume(injector: HasAndroidInjector) : Action(injector) {
|
|||
configBuilderPlugin.storeSettings("ActionLoopResume")
|
||||
loopPlugin.createOfflineEvent(0)
|
||||
rxBus.send(EventRefreshOverview("ActionLoopResume"))
|
||||
callback.result(PumpEnactResult().success(true).comment(R.string.ok))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
|
||||
} else {
|
||||
callback.result(PumpEnactResult().success(true).comment(R.string.notsuspended))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.notsuspended))?.run()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,9 +32,9 @@ class ActionLoopSuspend(injector: HasAndroidInjector) : Action(injector) {
|
|||
if (!loopPlugin.isSuspended) {
|
||||
loopPlugin.suspendLoop(minutes.getMinutes())
|
||||
rxBus.send(EventRefreshOverview("ActionLoopSuspend"))
|
||||
callback.result(PumpEnactResult().success(true).comment(R.string.ok))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
|
||||
} else {
|
||||
callback.result(PumpEnactResult().success(true).comment(R.string.alreadysuspended))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.alreadysuspended))?.run()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class ActionNotification(injector: HasAndroidInjector) : Action(injector) {
|
|||
rxBus.send(EventNewNotification(notification))
|
||||
NSUpload.uploadError(text.value)
|
||||
rxBus.send(EventRefreshOverview("ActionNotification"))
|
||||
callback.result(PumpEnactResult().success(true).comment(R.string.ok))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
|
|
|
@ -34,27 +34,27 @@ class ActionProfileSwitch(injector: HasAndroidInjector) : Action(injector) {
|
|||
//Check for uninitialized profileName
|
||||
if (inputProfileName.value == "") {
|
||||
aapsLogger.error(LTag.AUTOMATION, "Selected profile not initialized")
|
||||
callback.result(PumpEnactResult().success(false).comment(R.string.error_field_must_not_be_empty))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(false).comment(R.string.error_field_must_not_be_empty))?.run()
|
||||
return
|
||||
}
|
||||
if (profileFunction.getProfile() == null) {
|
||||
aapsLogger.error(LTag.AUTOMATION, "ProfileFunctions not initialized")
|
||||
callback.result(PumpEnactResult().success(false).comment(R.string.noprofile))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(false).comment(R.string.noprofile))?.run()
|
||||
return
|
||||
}
|
||||
if (inputProfileName.value == activeProfileName) {
|
||||
aapsLogger.debug(LTag.AUTOMATION, "Profile is already switched")
|
||||
callback.result(PumpEnactResult().success(true).comment(R.string.alreadyset))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.alreadyset))?.run()
|
||||
return
|
||||
}
|
||||
val profileStore = activePlugin.activeProfileInterface.profile ?: return
|
||||
if (profileStore.getSpecificProfile(inputProfileName.value) == null) {
|
||||
aapsLogger.error(LTag.AUTOMATION, "Selected profile does not exist! - ${inputProfileName.value}")
|
||||
callback.result(PumpEnactResult().success(false).comment(R.string.notexists))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(false).comment(R.string.notexists))?.run()
|
||||
return
|
||||
}
|
||||
activePlugin.activeTreatments.doProfileSwitch(profileStore, inputProfileName.value, 0, 100, 0, DateUtil.now())
|
||||
callback.result(PumpEnactResult().success(true).comment(R.string.ok))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
|
||||
}
|
||||
|
||||
override fun generateDialog(root: LinearLayout) {
|
||||
|
|
|
@ -38,7 +38,7 @@ class ActionProfileSwitchPercent(injector: HasAndroidInjector) : Action(injector
|
|||
|
||||
override fun doAction(callback: Callback) {
|
||||
activePlugin.activeTreatments.doProfileSwitch(duration.value, pct.value.toInt(), 0)
|
||||
callback.result(PumpEnactResult().success(true).comment(R.string.ok))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
|
||||
}
|
||||
|
||||
override fun generateDialog(root: LinearLayout) {
|
||||
|
|
|
@ -26,7 +26,7 @@ class ActionSendSMS(injector: HasAndroidInjector) : Action(injector) {
|
|||
|
||||
override fun doAction(callback: Callback) {
|
||||
val result = smsCommunicatorPlugin.sendNotificationToAllNumbers(text.value)
|
||||
callback.result(PumpEnactResult().success(result).comment(if (result) R.string.ok else R.string.danar_error))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(result).comment(if (result) R.string.ok else R.string.danar_error))?.run()
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
|
|
|
@ -41,7 +41,7 @@ class ActionStartTempTarget(injector: HasAndroidInjector) : Action(injector) {
|
|||
|
||||
override fun doAction(callback: Callback) {
|
||||
activePlugin.activeTreatments.addToHistoryTempTarget(tt())
|
||||
callback.result(PumpEnactResult().success(true).comment(R.string.ok))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
|
||||
}
|
||||
|
||||
override fun generateDialog(root: LinearLayout) {
|
||||
|
|
|
@ -27,6 +27,6 @@ class ActionStopTempTarget(injector: HasAndroidInjector) : Action(injector) {
|
|||
.source(Source.USER)
|
||||
.low(0.0).high(0.0)
|
||||
activePlugin.activeTreatments.addToHistoryTempTarget(tempTarget)
|
||||
callback.result(PumpEnactResult().success(true).comment(R.string.ok))?.run()
|
||||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run()
|
||||
}
|
||||
}
|
|
@ -171,7 +171,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
@Override protected void onStart() {
|
||||
super.onStart();
|
||||
ruffyScripter = new RuffyScripter(MainApp.instance());
|
||||
OPERATION_NOT_SUPPORTED = new PumpEnactResult()
|
||||
OPERATION_NOT_SUPPORTED = new PumpEnactResult(getInjector())
|
||||
.success(false).enacted(false).comment(MainApp.gs(R.string.combo_pump_unsupported_operation));
|
||||
}
|
||||
|
||||
|
@ -263,7 +263,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
log.error("setNewBasalProfile not initialized");
|
||||
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
||||
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
|
||||
return new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(R.string.pumpNotInitializedProfileNotSet));
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(MainApp.gs(R.string.pumpNotInitializedProfileNotSet));
|
||||
}
|
||||
|
||||
BasalProfile requestedBasalProfile = convertProfileToComboProfile(profile);
|
||||
|
@ -271,12 +271,12 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
//dismiss previously "FAILED" overview notifications
|
||||
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
return new PumpEnactResult().success(true).enacted(false);
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||
}
|
||||
|
||||
CommandResult stateResult = runCommand(null, 1, ruffyScripter::readPumpState);
|
||||
if (stateResult.state.unsafeUsageDetected == PumpState.UNSUPPORTED_BASAL_RATE_PROFILE) {
|
||||
return new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(R.string.combo_force_disabled_notification));
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(MainApp.gs(R.string.combo_force_disabled_notification));
|
||||
}
|
||||
|
||||
CommandResult setResult = runCommand(MainApp.gs(R.string.combo_activity_setting_basal_profile), 2,
|
||||
|
@ -284,7 +284,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
if (!setResult.success) {
|
||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
|
||||
return new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(R.string.failedupdatebasalprofile));
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(MainApp.gs(R.string.failedupdatebasalprofile));
|
||||
}
|
||||
|
||||
pump.basalProfile = requestedBasalProfile;
|
||||
|
@ -295,7 +295,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
//issue success notification
|
||||
Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60);
|
||||
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
|
||||
return new PumpEnactResult().success(true).enacted(true);
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -493,7 +493,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
if (detailedBolusInfo.insulin == 0 && detailedBolusInfo.carbs == 0) {
|
||||
// neither carbs nor bolus requested
|
||||
log.error("deliverTreatment: Invalid input");
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.bolusDelivered(0d).carbsDelivered(0d)
|
||||
.comment(MainApp.gs(R.string.danar_invalidinput));
|
||||
} else if (detailedBolusInfo.insulin > 0) {
|
||||
|
@ -509,7 +509,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
bolusingEvent.setPercent(100);
|
||||
RxBus.Companion.getINSTANCE().send(bolusingEvent);
|
||||
|
||||
return new PumpEnactResult().success(true).enacted(true)
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true)
|
||||
.bolusDelivered(0d).carbsDelivered(detailedBolusInfo.carbs)
|
||||
.comment(MainApp.gs(R.string.virtualpump_resultok));
|
||||
}
|
||||
|
@ -527,16 +527,16 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
// check pump is ready and all pump bolus records are known
|
||||
CommandResult stateResult = runCommand(null, 2, () -> ruffyScripter.readQuickInfo(1));
|
||||
if (!stateResult.success) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.combo_error_no_connection_no_bolus_delivered));
|
||||
}
|
||||
if (stateResult.reservoirLevel != -1 && stateResult.reservoirLevel - 0.5 < detailedBolusInfo.insulin) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.combo_reservoir_level_insufficient_for_bolus));
|
||||
}
|
||||
// the commands above ensured a connection was made, which updated this field
|
||||
if (pumpHistoryChanged) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.combo_bolus_rejected_due_to_pump_history_change));
|
||||
}
|
||||
|
||||
|
@ -550,7 +550,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
&& previousBolus.timestamp + 60 * 1000 > System.currentTimeMillis()) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Bolus request rejected, same bolus was successfully delivered very recently");
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.bolus_frequency_exceeded));
|
||||
}
|
||||
|
||||
|
@ -563,10 +563,10 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
while (previousBolus.timestamp == timeCheckResult.state.pumpTime
|
||||
&& maxWaitTimeout > System.currentTimeMillis()) {
|
||||
if (cancelBolus) {
|
||||
return new PumpEnactResult().success(true).enacted(false);
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||
}
|
||||
if (!timeCheckResult.success) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.combo_error_no_connection_no_bolus_delivered));
|
||||
}
|
||||
if (L.isEnabled(L.PUMP))
|
||||
|
@ -582,7 +582,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
}
|
||||
|
||||
if (cancelBolus) {
|
||||
return new PumpEnactResult().success(true).enacted(false);
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||
}
|
||||
|
||||
Treatment treatment = new Treatment();
|
||||
|
@ -603,7 +603,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
// (reads 2 records to update `recentBoluses` further down)
|
||||
CommandResult postBolusStateResult = runCommand(null, 3, () -> ruffyScripter.readQuickInfo(2));
|
||||
if (!postBolusStateResult.success) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.combo_error_bolus_verification_failed));
|
||||
}
|
||||
Bolus lastPumpBolus = postBolusStateResult.history != null && !postBolusStateResult.history.bolusHistory.isEmpty()
|
||||
|
@ -613,9 +613,9 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
// no bolus delivered?
|
||||
if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus)) {
|
||||
if (cancelBolus) {
|
||||
return new PumpEnactResult().success(true).enacted(false);
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||
} else {
|
||||
return new PumpEnactResult()
|
||||
return new PumpEnactResult(getInjector())
|
||||
.success(false)
|
||||
.enacted(false)
|
||||
.comment(MainApp.gs(R.string.combo_error_no_bolus_delivered));
|
||||
|
@ -624,7 +624,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
|
||||
// at least some insulin delivered, so add it to treatments
|
||||
if (!addBolusToTreatments(detailedBolusInfo, lastPumpBolus))
|
||||
return new PumpEnactResult().success(false).enacted(true)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(true)
|
||||
.comment(MainApp.gs(R.string.combo_error_updating_treatment_record));
|
||||
|
||||
// check pump bolus record has a sane timestamp
|
||||
|
@ -641,16 +641,16 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
// only a partial bolus was delivered
|
||||
if (Math.abs(lastPumpBolus.amount - detailedBolusInfo.insulin) > 0.01) {
|
||||
if (cancelBolus) {
|
||||
return new PumpEnactResult().success(true).enacted(true);
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true);
|
||||
}
|
||||
return new PumpEnactResult().success(false).enacted(true)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(true)
|
||||
.comment(MainApp.gs(R.string.combo_error_partial_bolus_delivered,
|
||||
lastPumpBolus.amount, detailedBolusInfo.insulin));
|
||||
}
|
||||
|
||||
// full bolus was delivered successfully
|
||||
incrementBolusCount();
|
||||
return new PumpEnactResult()
|
||||
return new PumpEnactResult(getInjector())
|
||||
.success(true)
|
||||
.enacted(lastPumpBolus.amount > 0)
|
||||
.bolusDelivered(lastPumpBolus.amount)
|
||||
|
@ -748,7 +748,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
log.debug("setTempBasalPercent called with " + percent + "% for " + durationInMinutes + "min");
|
||||
|
||||
if (pumpHistoryChanged && percent > 110) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.combo_high_temp_rejected_due_to_pump_history_changes));
|
||||
}
|
||||
|
||||
|
@ -776,7 +776,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
CommandResult commandResult = runCommand(MainApp.gs(R.string.combo_pump_action_setting_tbr, percent, durationInMinutes),
|
||||
3, () -> ruffyScripter.setTbr(finalAdjustedPercent, durationInMinutes));
|
||||
if (!commandResult.success) {
|
||||
return new PumpEnactResult().success(false).enacted(false);
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false);
|
||||
}
|
||||
|
||||
PumpState state = commandResult.state;
|
||||
|
@ -793,7 +793,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
}
|
||||
|
||||
incrementTbrCount();
|
||||
return new PumpEnactResult().success(true).enacted(true).isPercent(true)
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true).isPercent(true)
|
||||
.percent(state.tbrPercent).duration(state.tbrRemainingDuration);
|
||||
}
|
||||
|
||||
|
@ -818,16 +818,16 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
if (enforceNew) {
|
||||
CommandResult stateResult = runCommand(MainApp.gs(R.string.combo_pump_action_refreshing), 2, ruffyScripter::readPumpState);
|
||||
if (!stateResult.success) {
|
||||
return new PumpEnactResult().success(false).enacted(false);
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false);
|
||||
}
|
||||
if (!stateResult.state.tbrActive) {
|
||||
return new PumpEnactResult().success(true).enacted(false);
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||
}
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("cancelTempBasal: hard-cancelling TBR since force requested");
|
||||
CommandResult cancelResult = runCommand(MainApp.gs(R.string.combo_pump_action_cancelling_tbr), 2, ruffyScripter::cancelTbr);
|
||||
if (!cancelResult.success) {
|
||||
return new PumpEnactResult().success(false).enacted(false);
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false);
|
||||
}
|
||||
if (!cancelResult.state.tbrActive) {
|
||||
TemporaryBasal tempBasal = new TemporaryBasal()
|
||||
|
@ -835,19 +835,19 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
.duration(0)
|
||||
.source(Source.USER);
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
|
||||
return new PumpEnactResult().isTempCancel(true).success(true).enacted(true);
|
||||
return new PumpEnactResult(getInjector()).isTempCancel(true).success(true).enacted(true);
|
||||
} else {
|
||||
return new PumpEnactResult().success(false).enacted(false);
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false);
|
||||
}
|
||||
} else if (activeTemp == null) {
|
||||
return new PumpEnactResult().success(true).enacted(false);
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||
} else if ((activeTemp.percentRate >= 90 && activeTemp.percentRate <= 110) && activeTemp.getPlannedRemainingMinutes() <= 15) {
|
||||
// Let fake neutral temp keep run (see below)
|
||||
// Note that since this runs on the queue a connection is opened regardless, but this
|
||||
// case doesn't occur all that often, so it's not worth optimizing (1.3k SetTBR vs 4 cancelTBR).
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("cancelTempBasal: skipping changing tbr since it already is at " + activeTemp.percentRate + "% and running for another " + activeTemp.getPlannedRemainingMinutes() + " mins.");
|
||||
return new PumpEnactResult().success(true).enacted(true)
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true)
|
||||
.comment("cancelTempBasal skipping changing tbr since it already is at "
|
||||
+ activeTemp.percentRate + "% and running for another "
|
||||
+ activeTemp.getPlannedRemainingMinutes() + " mins.");
|
||||
|
@ -1355,7 +1355,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult loadTDDs() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = readHistory(new PumpHistoryRequest().tddHistory(PumpHistoryRequest.FULL));
|
||||
if (result.success) {
|
||||
List<Tdd> tdds = pump.tddHistory;
|
||||
|
|
|
@ -410,7 +410,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
|||
// neither carbs nor bolus requested
|
||||
if (isLoggingEnabled())
|
||||
LOG.error("deliverTreatment: Invalid input");
|
||||
return new PumpEnactResult().success(false).enacted(false).bolusDelivered(0d).carbsDelivered(0d)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).bolusDelivered(0d).carbsDelivered(0d)
|
||||
.comment(MainApp.gs(R.string.danar_invalidinput));
|
||||
} else if (detailedBolusInfo.insulin > 0) {
|
||||
// bolus needed, ask pump to deliver it
|
||||
|
@ -431,7 +431,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
|||
if (isLoggingEnabled())
|
||||
LOG.debug("deliverTreatment: Carb only treatment.");
|
||||
|
||||
return new PumpEnactResult().success(true).enacted(true).bolusDelivered(0d)
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true).bolusDelivered(0d)
|
||||
.carbsDelivered(detailedBolusInfo.carbs).comment(MainApp.gs(R.string.virtualpump_resultok));
|
||||
}
|
||||
} finally {
|
||||
|
@ -452,8 +452,8 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
|||
protected abstract void triggerUIChange();
|
||||
|
||||
|
||||
public static PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
|
||||
return new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(resourceId));
|
||||
public PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(MainApp.gs(resourceId));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
|
|||
// Pump interface
|
||||
@NonNull @Override
|
||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
|
||||
if (sExecutionService == null) {
|
||||
log.error("setNewBasalProfile sExecutionService is null");
|
||||
|
@ -180,7 +180,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
|
|||
@NonNull @Override
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||
DanaRPump pump = danaRPump;
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
|
||||
if (percent < 0) {
|
||||
result.isTempCancel = false;
|
||||
|
@ -235,7 +235,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
|
|||
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
||||
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
|
||||
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
ExtendedBolus runningEB = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) {
|
||||
result.enacted = false;
|
||||
|
@ -273,7 +273,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult cancelExtendedBolus() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
ExtendedBolus runningEB = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
if (runningEB != null) {
|
||||
sExecutionService.extendedBolusStop();
|
||||
|
|
|
@ -167,7 +167,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
boolean connectionOK = false;
|
||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
|
||||
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t);
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep;
|
||||
result.bolusDelivered = t.insulin;
|
||||
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||
|
@ -181,7 +181,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, false);
|
||||
return result;
|
||||
} else {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = false;
|
||||
result.bolusDelivered = 0d;
|
||||
result.carbsDelivered = 0d;
|
||||
|
@ -199,7 +199,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
||||
// connect("setTempBasalAbsolute old data");
|
||||
//}
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
|
||||
absoluteRate = constraintChecker.applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
||||
|
||||
|
@ -336,7 +336,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
if (treatmentsPlugin.isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) {
|
||||
return cancelExtendedBolus();
|
||||
}
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = true;
|
||||
result.enacted = false;
|
||||
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
|
||||
|
@ -350,7 +350,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
}
|
||||
|
||||
private PumpEnactResult cancelRealTempBasal() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
TemporaryBasal runningTB = treatmentsPlugin.getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (runningTB != null) {
|
||||
sExecutionService.tempBasalStop();
|
||||
|
|
|
@ -17,13 +17,18 @@ import java.io.IOException;
|
|||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.DaggerService;
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
|
||||
|
@ -51,7 +56,8 @@ import info.nightscout.androidaps.utils.ToastUtils;
|
|||
*/
|
||||
|
||||
public abstract class AbstractDanaRExecutionService extends DaggerService {
|
||||
protected Logger log = StacktraceLoggerWrapper.getLogger(L.PUMP);
|
||||
@Inject HasAndroidInjector injector;
|
||||
@Inject AAPSLogger aapsLogger;
|
||||
|
||||
protected String mDevName;
|
||||
|
||||
|
@ -102,8 +108,7 @@ public abstract class AbstractDanaRExecutionService extends DaggerService {
|
|||
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
String action = intent.getAction();
|
||||
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Device was disconnected " + device.getName());//Device was disconnected
|
||||
aapsLogger.debug(LTag.PUMP, "Device was disconnected " + device.getName());//Device was disconnected
|
||||
if (mBTDevice != null && mBTDevice.getName() != null && mBTDevice.getName().equals(device.getName())) {
|
||||
if (mSerialIOThread != null) {
|
||||
mSerialIOThread.disconnect("BT disconnection broadcast");
|
||||
|
@ -164,7 +169,7 @@ public abstract class AbstractDanaRExecutionService extends DaggerService {
|
|||
try {
|
||||
mRfcommSocket = mBTDevice.createRfcommSocketToServiceRecord(SPP_UUID);
|
||||
} catch (IOException e) {
|
||||
log.error("Error creating socket: ", e);
|
||||
aapsLogger.error("Error creating socket: ", e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -178,8 +183,7 @@ public abstract class AbstractDanaRExecutionService extends DaggerService {
|
|||
}
|
||||
|
||||
public void bolusStop() {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("bolusStop >>>>> @ " + (mBolusingTreatment == null ? "" : mBolusingTreatment.insulin));
|
||||
aapsLogger.debug(LTag.PUMP, "bolusStop >>>>> @ " + (mBolusingTreatment == null ? "" : mBolusingTreatment.insulin));
|
||||
MsgBolusStop stop = new MsgBolusStop();
|
||||
stop.forced = true;
|
||||
if (isConnected()) {
|
||||
|
@ -194,7 +198,7 @@ public abstract class AbstractDanaRExecutionService extends DaggerService {
|
|||
}
|
||||
|
||||
public PumpEnactResult loadHistory(byte type) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(injector);
|
||||
if (!isConnected()) return result;
|
||||
MessageBase msg = null;
|
||||
switch (type) {
|
||||
|
|
|
@ -24,7 +24,7 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
|||
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||
|
@ -115,8 +115,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("EventAppExit received");
|
||||
aapsLogger.debug(LTag.PUMP, "EventAppExit received");
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("Application exit");
|
||||
context.unregisterReceiver(receiver);
|
||||
|
@ -155,7 +154,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
} catch (IOException e) {
|
||||
//log.error("Unhandled exception", e);
|
||||
if (e.getMessage().contains("socket closed")) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,14 +232,12 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
return;
|
||||
}
|
||||
long timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L;
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds");
|
||||
aapsLogger.debug(LTag.PUMP, "Pump time difference: " + timeDiff + " seconds");
|
||||
if (Math.abs(timeDiff) > 10) {
|
||||
mSerialIOThread.sendMessage(new MsgSetTime(new Date()));
|
||||
mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump));
|
||||
timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L;
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds");
|
||||
aapsLogger.debug(LTag.PUMP, "Pump time difference: " + timeDiff + " seconds");
|
||||
}
|
||||
danaRPump.setLastSettingsRead(now);
|
||||
}
|
||||
|
@ -249,8 +246,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
rxBus.send(new EventInitializationChanged());
|
||||
//NSUpload.uploadDeviceStatus();
|
||||
if (danaRPump.getDailyTotalUnits() > danaRPump.getMaxDailyTotalUnits() * Constants.dailyLimitWarning) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Approaching daily limit: " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits());
|
||||
aapsLogger.debug(LTag.PUMP, "Approaching daily limit: " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits());
|
||||
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
|
||||
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT);
|
||||
rxBus.send(new EventNewNotification(reportFail));
|
||||
|
@ -259,7 +255,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,8 +337,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 15 sec expecting broken comm
|
||||
stop.stopped = true;
|
||||
stop.forced = true;
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Communication stopped");
|
||||
aapsLogger.debug(LTag.PUMP, "Communication stopped");
|
||||
}
|
||||
}
|
||||
SystemClock.sleep(300);
|
||||
|
@ -385,11 +380,9 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
public void run() {
|
||||
if (danaRPump.getLastBolusTime() > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old
|
||||
t.insulin = danaRPump.getLastBolusAmount();
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Used bolus amount from history: " + danaRPump.getLastBolusAmount());
|
||||
aapsLogger.debug(LTag.PUMP, "Used bolus amount from history: " + danaRPump.getLastBolusAmount());
|
||||
} else {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Bolus amount in history too old: " + DateUtil.dateAndTimeString(danaRPump.getLastBolusTime()));
|
||||
aapsLogger.debug(LTag.PUMP, "Bolus amount in history too old: " + DateUtil.dateAndTimeString(danaRPump.getLastBolusTime()));
|
||||
}
|
||||
synchronized (o) {
|
||||
o.notify();
|
||||
|
@ -399,7 +392,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
try {
|
||||
o.wait();
|
||||
} catch (InterruptedException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -442,11 +435,11 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
|
||||
public PumpEnactResult setUserOptions() {
|
||||
if (!isConnected())
|
||||
return new PumpEnactResult().success(false);
|
||||
return new PumpEnactResult(injector).success(false);
|
||||
SystemClock.sleep(300);
|
||||
MsgSetUserOptions msg = new MsgSetUserOptions(aapsLogger, danaRPump);
|
||||
mSerialIOThread.sendMessage(msg);
|
||||
SystemClock.sleep(200);
|
||||
return new PumpEnactResult().success(!msg.failed);
|
||||
return new PumpEnactResult(injector).success(!msg.failed);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
boolean connectionOK = false;
|
||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
|
||||
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t);
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep;
|
||||
result.bolusDelivered = t.insulin;
|
||||
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||
|
@ -184,7 +184,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, false);
|
||||
return result;
|
||||
} else {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = false;
|
||||
result.bolusDelivered = 0d;
|
||||
result.carbsDelivered = 0d;
|
||||
|
@ -202,7 +202,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
||||
// connect("setTempBasalAbsolute old data");
|
||||
//}
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
|
||||
absoluteRate = constraintChecker.applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
||||
|
||||
|
@ -339,7 +339,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
if (treatmentsPlugin.isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) {
|
||||
return cancelExtendedBolus();
|
||||
}
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = true;
|
||||
result.enacted = false;
|
||||
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
|
||||
|
@ -353,7 +353,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
}
|
||||
|
||||
private PumpEnactResult cancelRealTempBasal() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
TemporaryBasal runningTB = treatmentsPlugin.getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (runningTB != null) {
|
||||
sExecutionService.tempBasalStop();
|
||||
|
|
|
@ -24,7 +24,7 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
|||
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||
|
@ -106,8 +106,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
|||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("EventAppExit received");
|
||||
aapsLogger.debug(LTag.PUMP, "EventAppExit received");
|
||||
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("Application exit");
|
||||
|
@ -147,7 +146,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
|||
} catch (IOException e) {
|
||||
//log.error("Unhandled exception", e);
|
||||
if (e.getMessage().contains("socket closed")) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,16 +220,14 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
|||
return;
|
||||
}
|
||||
long timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L;
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds");
|
||||
aapsLogger.debug(LTag.PUMP, "Pump time difference: " + timeDiff + " seconds");
|
||||
if (Math.abs(timeDiff) > 10) {
|
||||
waitForWholeMinute(); // Dana can set only whole minute
|
||||
// add 10sec to be sure we are over minute (will be cutted off anyway)
|
||||
mSerialIOThread.sendMessage(new MsgSetTime(new Date(DateUtil.now() + T.secs(10).msecs())));
|
||||
mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump));
|
||||
timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L;
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds");
|
||||
aapsLogger.debug(LTag.PUMP, "Pump time difference: " + timeDiff + " seconds");
|
||||
}
|
||||
danaRPump.setLastSettingsRead(now);
|
||||
}
|
||||
|
@ -239,8 +236,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
|||
rxBus.send(new EventInitializationChanged());
|
||||
//NSUpload.uploadDeviceStatus();
|
||||
if (danaRPump.getDailyTotalUnits() > danaRPump.getMaxDailyTotalUnits() * Constants.dailyLimitWarning) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Approaching daily limit: " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits());
|
||||
aapsLogger.debug(LTag.PUMP, "Approaching daily limit: " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits());
|
||||
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
|
||||
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT);
|
||||
rxBus.send(new EventNewNotification(reportFail));
|
||||
|
@ -249,7 +245,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
|||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -325,8 +321,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
|||
if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 15 sec expecting broken comm
|
||||
stop.stopped = true;
|
||||
stop.forced = true;
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Communication stopped");
|
||||
aapsLogger.debug(LTag.PUMP, "Communication stopped");
|
||||
}
|
||||
}
|
||||
SystemClock.sleep(300);
|
||||
|
|
|
@ -306,7 +306,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
|
||||
if (danaRSService == null) {
|
||||
getAapsLogger().error("setNewBasalProfile sExecutionService is null");
|
||||
|
@ -413,7 +413,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
|
|||
boolean connectionOK = false;
|
||||
if (detailedBolusInfo.insulin > 0 || carbs > 0)
|
||||
connectionOK = danaRSService.bolus(detailedBolusInfo.insulin, (int) carbs, DateUtil.now() + T.mins(carbTime).msecs(), t);
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep;
|
||||
result.bolusDelivered = t.insulin;
|
||||
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||
|
@ -440,7 +440,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
|
|||
getAapsLogger().debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
||||
return result;
|
||||
} else {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = false;
|
||||
result.bolusDelivered = 0d;
|
||||
result.carbsDelivered = 0d;
|
||||
|
@ -469,7 +469,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
|
|||
// connect("setTempBasalAbsolute old data");
|
||||
//}
|
||||
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
|
||||
absoluteRate = constraintChecker.applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
||||
|
||||
|
@ -541,7 +541,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
|
|||
@NonNull @Override
|
||||
public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||
DanaRPump pump = danaRPump;
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
|
||||
if (percent < 0) {
|
||||
result.isTempCancel = false;
|
||||
|
@ -593,7 +593,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
|
|||
|
||||
private synchronized PumpEnactResult setHighTempBasalPercent(Integer percent) {
|
||||
DanaRPump pump = danaRPump;
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
boolean connectionOK = danaRSService.highTempBasal(percent);
|
||||
if (connectionOK && pump.isTempBasalInProgress() && pump.getTempBasalPercent() == percent) {
|
||||
result.enacted = true;
|
||||
|
@ -620,7 +620,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
|
|||
// needs to be rounded
|
||||
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
||||
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
ExtendedBolus runningEB = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) {
|
||||
result.enacted = false;
|
||||
|
@ -655,7 +655,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
|
|||
|
||||
@NonNull @Override
|
||||
public synchronized PumpEnactResult cancelTempBasal(boolean force) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
TemporaryBasal runningTB = treatmentsPlugin.getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (runningTB != null) {
|
||||
danaRSService.tempBasalStop();
|
||||
|
@ -679,7 +679,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
|
|||
|
||||
@NonNull @Override
|
||||
public synchronized PumpEnactResult cancelExtendedBolus() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
ExtendedBolus runningEB = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
if (runningEB != null) {
|
||||
danaRSService.extendedBolusStop();
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.os.SystemClock;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.DaggerService;
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
|
@ -86,6 +87,7 @@ import io.reactivex.disposables.CompositeDisposable;
|
|||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class DanaRSService extends DaggerService {
|
||||
@Inject HasAndroidInjector injector;
|
||||
@Inject AAPSLogger aapsLogger;
|
||||
@Inject RxBusWrapper rxBus;
|
||||
@Inject SP sp;
|
||||
|
@ -260,7 +262,7 @@ public class DanaRSService extends DaggerService {
|
|||
public PumpEnactResult loadEvents() {
|
||||
|
||||
if (!danaRSPlugin.isInitialized()) {
|
||||
PumpEnactResult result = new PumpEnactResult().success(false);
|
||||
PumpEnactResult result = new PumpEnactResult(injector).success(false);
|
||||
result.comment = "pump not initialized";
|
||||
return result;
|
||||
}
|
||||
|
@ -285,13 +287,13 @@ public class DanaRSService extends DaggerService {
|
|||
lastHistoryFetched = 0;
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Events loaded");
|
||||
danaRPump.setLastConnection(System.currentTimeMillis());
|
||||
return new PumpEnactResult().success(true);
|
||||
return new PumpEnactResult(injector).success(true);
|
||||
}
|
||||
|
||||
|
||||
public PumpEnactResult setUserSettings() {
|
||||
bleComm.sendMessage(new DanaRS_Packet_Option_Get_User_Option(aapsLogger, danaRPump));
|
||||
return new PumpEnactResult().success(true);
|
||||
return new PumpEnactResult(injector).success(true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -485,7 +487,7 @@ public class DanaRSService extends DaggerService {
|
|||
}
|
||||
|
||||
public PumpEnactResult loadHistory(byte type) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(injector);
|
||||
if (!isConnected()) return result;
|
||||
DanaRS_Packet_History_ msg = null;
|
||||
switch (type) {
|
||||
|
|
|
@ -29,7 +29,6 @@ import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInf
|
|||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed;
|
||||
import info.nightscout.androidaps.plugins.pump.danaRv2.services.DanaRv2ExecutionService;
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
|
@ -185,7 +184,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
boolean connectionOK = false;
|
||||
if (detailedBolusInfo.insulin > 0 || carbs > 0)
|
||||
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) carbs, DateUtil.now() + T.mins(carbTime).msecs(), t);
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep;
|
||||
result.bolusDelivered = t.insulin;
|
||||
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||
|
@ -197,7 +196,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
// remove carbs because it's get from history separately
|
||||
return result;
|
||||
} else {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = false;
|
||||
result.bolusDelivered = 0d;
|
||||
result.carbsDelivered = 0d;
|
||||
|
@ -225,7 +224,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
// connect("setTempBasalAbsolute old data");
|
||||
//}
|
||||
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
|
||||
absoluteRate = constraintChecker.applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
||||
|
||||
|
@ -296,7 +295,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
@NonNull @Override
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||
DanaRPump pump = danaRPump;
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
|
||||
if (percent < 0) {
|
||||
result.isTempCancel = false;
|
||||
|
@ -348,7 +347,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
|
||||
private PumpEnactResult setHighTempBasalPercent(Integer percent) {
|
||||
DanaRPump pump = danaRPump;
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
boolean connectionOK = sExecutionService.highTempBasal(percent);
|
||||
if (connectionOK && pump.isTempBasalInProgress() && pump.getTempBasalPercent() == percent) {
|
||||
result.enacted = true;
|
||||
|
@ -370,7 +369,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult cancelTempBasal(boolean force) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
TemporaryBasal runningTB = treatmentsPlugin.getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (runningTB != null) {
|
||||
sExecutionService.tempBasalStop();
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.Date;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.activities.ErrorHelperActivity;
|
||||
|
@ -26,7 +27,7 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
|||
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||
|
@ -87,6 +88,7 @@ import io.reactivex.disposables.CompositeDisposable;
|
|||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
||||
@Inject HasAndroidInjector injector;
|
||||
@Inject AAPSLogger aapsLogger;
|
||||
@Inject RxBusWrapper rxBus;
|
||||
@Inject ResourceHelper resourceHelper;
|
||||
|
@ -130,8 +132,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("EventAppExit received");
|
||||
aapsLogger.debug(LTag.PUMP, "EventAppExit received");
|
||||
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("Application exit");
|
||||
|
@ -165,7 +166,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
} catch (IOException e) {
|
||||
//log.error("Unhandled exception", e);
|
||||
if (e.getMessage().contains("socket closed")) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,12 +231,10 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
return;
|
||||
}
|
||||
long timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L;
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds");
|
||||
aapsLogger.debug(LTag.PUMP, "Pump time difference: " + timeDiff + " seconds");
|
||||
if (Math.abs(timeDiff) > 3) {
|
||||
if (Math.abs(timeDiff) > 60 * 60 * 1.5) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds - large difference");
|
||||
aapsLogger.debug(LTag.PUMP, "Pump time difference: " + timeDiff + " seconds - large difference");
|
||||
//If time-diff is very large, warn user until we can synchronize history readings properly
|
||||
Intent i = new Intent(context, ErrorHelperActivity.class);
|
||||
i.putExtra("soundid", R.raw.error);
|
||||
|
@ -255,8 +254,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
mSerialIOThread.sendMessage(new MsgSetTime(new Date(DateUtil.now() + T.secs(10).msecs())));
|
||||
mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump));
|
||||
timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L;
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds");
|
||||
aapsLogger.debug(LTag.PUMP, "Pump time difference: " + timeDiff + " seconds");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,8 +281,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
rxBus.send(new EventInitializationChanged());
|
||||
//NSUpload.uploadDeviceStatus();
|
||||
if (danaRPump.getDailyTotalUnits() > danaRPump.getMaxDailyTotalUnits() * Constants.dailyLimitWarning) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Approaching daily limit: " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits());
|
||||
aapsLogger.debug(LTag.PUMP, "Approaching daily limit: " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits());
|
||||
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
|
||||
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT);
|
||||
rxBus.send(new EventNewNotification(reportFail));
|
||||
|
@ -293,7 +290,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -329,7 +326,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
|
||||
public boolean tempBasalShortDuration(int percent, int durationInMinutes) {
|
||||
if (durationInMinutes != 15 && durationInMinutes != 30) {
|
||||
log.error("Wrong duration param");
|
||||
aapsLogger.error("Wrong duration param");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -414,7 +411,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 15 sec expecting broken comm
|
||||
stop.stopped = true;
|
||||
stop.forced = true;
|
||||
log.error("Communication stopped");
|
||||
aapsLogger.error("Communication stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -459,8 +456,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
}
|
||||
|
||||
public void bolusStop() {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("bolusStop >>>>> @ " + (mBolusingTreatment == null ? "" : mBolusingTreatment.insulin));
|
||||
aapsLogger.debug(LTag.PUMP, "bolusStop >>>>> @ " + (mBolusingTreatment == null ? "" : mBolusingTreatment.insulin));
|
||||
MsgBolusStop stop = new MsgBolusStop();
|
||||
stop.forced = true;
|
||||
if (isConnected()) {
|
||||
|
@ -486,18 +482,17 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
|
||||
public PumpEnactResult loadEvents() {
|
||||
if (!danaRv2Plugin.isInitialized()) {
|
||||
PumpEnactResult result = new PumpEnactResult().success(false);
|
||||
PumpEnactResult result = new PumpEnactResult(injector).success(false);
|
||||
result.comment = "pump not initialized";
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
if (!isConnected())
|
||||
return new PumpEnactResult().success(false);
|
||||
return new PumpEnactResult(injector).success(false);
|
||||
SystemClock.sleep(300);
|
||||
MsgHistoryEvents_v2 msg = new MsgHistoryEvents_v2(lastHistoryFetched);
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Loading event history from: " + DateUtil.dateAndTimeString(lastHistoryFetched));
|
||||
aapsLogger.debug(LTag.PUMP, "Loading event history from: " + DateUtil.dateAndTimeString(lastHistoryFetched));
|
||||
|
||||
mSerialIOThread.sendMessage(msg);
|
||||
while (!msg.done && mRfcommSocket.isConnected()) {
|
||||
|
@ -509,7 +504,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
else
|
||||
lastHistoryFetched = 0;
|
||||
danaRPump.setLastConnection(System.currentTimeMillis());
|
||||
return new PumpEnactResult().success(true);
|
||||
return new PumpEnactResult(injector).success(true);
|
||||
}
|
||||
|
||||
public boolean updateBasalsInPump(final Profile profile) {
|
||||
|
@ -528,12 +523,12 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
|
||||
public PumpEnactResult setUserOptions() {
|
||||
if (!isConnected())
|
||||
return new PumpEnactResult().success(false);
|
||||
return new PumpEnactResult(injector).success(false);
|
||||
SystemClock.sleep(300);
|
||||
MsgSetUserOptions msg = new MsgSetUserOptions(aapsLogger, danaRPump);
|
||||
mSerialIOThread.sendMessage(msg);
|
||||
SystemClock.sleep(200);
|
||||
return new PumpEnactResult().success(!msg.failed);
|
||||
return new PumpEnactResult(injector).success(!msg.failed);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -217,7 +217,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
injector, aapsLogger, resourceHelper, commandQueue
|
||||
|
||||
);
|
||||
|
||||
this.aapsLogger = aapsLogger;
|
||||
this.rxBus = rxBus;
|
||||
this.resourceHelper = resourceHelper;
|
||||
|
@ -468,7 +467,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
rxBus.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
List<BasalProfileBlock> profileBlocks = new ArrayList<>();
|
||||
for (int i = 0; i < profile.getBasalValues().length; i++) {
|
||||
|
@ -565,7 +564,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
double insulin = Math.round(detailedBolusInfo.insulin / 0.01) * 0.01;
|
||||
if (insulin > 0) {
|
||||
try {
|
||||
|
@ -677,7 +676,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
if (activeBasalRate == null) return result;
|
||||
if (activeBasalRate.getActiveBasalRate() == 0) return result;
|
||||
double percent = 100D / activeBasalRate.getActiveBasalRate() * absoluteRate;
|
||||
|
@ -726,7 +725,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
percent = (int) Math.round(((double) percent) / 10d) * 10;
|
||||
if (percent == 100) return cancelTempBasal(true);
|
||||
else if (percent > 250) percent = 250;
|
||||
|
@ -781,7 +780,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
}
|
||||
|
||||
public PumpEnactResult setExtendedBolusOnly(Double insulin, Integer durationInMinutes) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
try {
|
||||
DeliverBolusMessage bolusMessage = new DeliverBolusMessage();
|
||||
bolusMessage.setBolusType(BolusType.EXTENDED);
|
||||
|
@ -819,7 +818,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
PumpEnactResult cancelEBResult = null;
|
||||
if (isFakingTempsByExtendedBoluses()) cancelEBResult = cancelExtendedBolusOnly();
|
||||
PumpEnactResult cancelTBRResult = cancelTempBasalOnly();
|
||||
|
@ -840,7 +839,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
}
|
||||
|
||||
private PumpEnactResult cancelTempBasalOnly() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
try {
|
||||
alertService.ignore(AlertType.WARNING_36);
|
||||
connectionService.requestMessage(new CancelTBRMessage()).await();
|
||||
|
@ -883,7 +882,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
}
|
||||
|
||||
private PumpEnactResult cancelExtendedBolusOnly() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
try {
|
||||
for (ActiveBolus activeBolus : activeBoluses) {
|
||||
if (activeBolus.getBolusType() == BolusType.EXTENDED || activeBolus.getBolusType() == BolusType.MULTIWAVE) {
|
||||
|
@ -1015,7 +1014,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
}
|
||||
|
||||
public PumpEnactResult stopPump() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
try {
|
||||
SetOperatingModeMessage operatingModeMessage = new SetOperatingModeMessage();
|
||||
operatingModeMessage.setOperatingMode(OperatingMode.STOPPED);
|
||||
|
@ -1038,7 +1037,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
}
|
||||
|
||||
public PumpEnactResult startPump() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
try {
|
||||
SetOperatingModeMessage operatingModeMessage = new SetOperatingModeMessage();
|
||||
operatingModeMessage.setOperatingMode(OperatingMode.STARTED);
|
||||
|
@ -1061,7 +1060,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
}
|
||||
|
||||
public PumpEnactResult setTBROverNotification(boolean enabled) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
boolean valueBefore = tbrOverNotificationBlock.isEnabled();
|
||||
tbrOverNotificationBlock.setEnabled(enabled);
|
||||
try {
|
||||
|
@ -1125,7 +1124,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult loadTDDs() {
|
||||
return new PumpEnactResult().success(true);
|
||||
return new PumpEnactResult(getInjector()).success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -78,7 +78,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
|
|||
@NonNull @Override
|
||||
public PumpEnactResult loadTDDs() {
|
||||
//no result, could read DB in the future?
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
|
|||
@NonNull @Override
|
||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||
// Do nothing here. we are using ConfigBuilderPlugin.getPlugin().getActiveProfile().getProfile();
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = true;
|
||||
return result;
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = true;
|
||||
result.bolusDelivered = detailedBolusInfo.insulin;
|
||||
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||
|
@ -182,7 +182,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = false;
|
||||
result.comment = MainApp.gs(R.string.pumperror);
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
|
@ -192,7 +192,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = false;
|
||||
result.comment = MainApp.gs(R.string.pumperror);
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
|
@ -202,7 +202,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = false;
|
||||
result.comment = MainApp.gs(R.string.pumperror);
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
|
@ -212,7 +212,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult cancelTempBasal(boolean force) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = false;
|
||||
result.comment = MainApp.gs(R.string.pumperror);
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
|
@ -222,7 +222,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
|
|||
|
||||
@NonNull @Override
|
||||
public PumpEnactResult cancelExtendedBolus() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = false;
|
||||
result.comment = MainApp.gs(R.string.pumperror);
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
|
|
|
@ -828,7 +828,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
MedtronicPumpStatus mdtPumpStatus = getMDTPumpStatus();
|
||||
|
||||
if (detailedBolusInfo.insulin > mdtPumpStatus.reservoirRemainingUnits) {
|
||||
return new PumpEnactResult() //
|
||||
return new PumpEnactResult(getInjector()) //
|
||||
.success(false) //
|
||||
.enacted(false) //
|
||||
.comment(MainApp.gs(R.string.medtronic_cmd_bolus_could_not_be_delivered_no_insulin,
|
||||
|
@ -921,13 +921,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
this.busyTimestamps.add(time);
|
||||
setEnableCustomAction(MedtronicCustomActionType.ClearBolusBlock, true);
|
||||
|
||||
return new PumpEnactResult().success(true) //
|
||||
return new PumpEnactResult(getInjector()).success(true) //
|
||||
.enacted(true) //
|
||||
.bolusDelivered(detailedBolusInfo.insulin) //
|
||||
.carbsDelivered(detailedBolusInfo.carbs);
|
||||
|
||||
} else {
|
||||
return new PumpEnactResult() //
|
||||
return new PumpEnactResult(getInjector()) //
|
||||
.success(bolusDeliveryType == BolusDeliveryType.CancelDelivery) //
|
||||
.enacted(false) //
|
||||
.comment(MainApp.gs(R.string.medtronic_cmd_bolus_could_not_be_delivered));
|
||||
|
@ -948,11 +948,11 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
}
|
||||
|
||||
if (success) {
|
||||
return new PumpEnactResult() //
|
||||
return new PumpEnactResult(getInjector()) //
|
||||
.success(true) //
|
||||
.enacted(false);
|
||||
} else {
|
||||
return new PumpEnactResult() //
|
||||
return new PumpEnactResult(getInjector()) //
|
||||
.success(false) //
|
||||
.enacted(false) //
|
||||
.comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable));
|
||||
|
@ -988,7 +988,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
setRefreshButtonEnabled(true);
|
||||
|
||||
return new PumpEnactResult() //
|
||||
return new PumpEnactResult(getInjector()) //
|
||||
.success(false) //
|
||||
.enacted(false) //
|
||||
.comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable));
|
||||
|
@ -1008,7 +1008,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
if (isLoggingEnabled())
|
||||
LOG.warn(getLogPrefix() + "setTempBasalAbsolute - Could not read current TBR, canceling operation.");
|
||||
finishAction("TBR");
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.medtronic_cmd_cant_read_tbr));
|
||||
} else {
|
||||
if (isLoggingEnabled())
|
||||
|
@ -1030,7 +1030,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
if (isLoggingEnabled())
|
||||
LOG.info(getLogPrefix() + "setTempBasalAbsolute - No enforceNew and same rate. Exiting.");
|
||||
finishAction("TBR");
|
||||
return new PumpEnactResult().success(true).enacted(false);
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||
}
|
||||
}
|
||||
// if not the same rate, we cancel and start new
|
||||
|
@ -1056,7 +1056,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
finishAction("TBR");
|
||||
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.medtronic_cmd_cant_cancel_tbr_stop_op));
|
||||
}
|
||||
}
|
||||
|
@ -1088,13 +1088,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
finishAction("TBR");
|
||||
|
||||
return new PumpEnactResult().success(true).enacted(true) //
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true) //
|
||||
.absolute(absoluteRate).duration(durationInMinutes);
|
||||
|
||||
} else {
|
||||
finishAction("TBR");
|
||||
|
||||
return new PumpEnactResult().success(false).enacted(false) //
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false) //
|
||||
.comment(MainApp.gs(R.string.medtronic_cmd_tbr_could_not_be_delivered));
|
||||
}
|
||||
|
||||
|
@ -1396,7 +1396,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
setRefreshButtonEnabled(true);
|
||||
|
||||
return new PumpEnactResult() //
|
||||
return new PumpEnactResult(getInjector()) //
|
||||
.success(false) //
|
||||
.enacted(false) //
|
||||
.comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable));
|
||||
|
@ -1412,13 +1412,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
if (isLoggingEnabled())
|
||||
LOG.info(getLogPrefix() + "cancelTempBasal - TBR already canceled.");
|
||||
finishAction("TBR");
|
||||
return new PumpEnactResult().success(true).enacted(false);
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||
}
|
||||
} else {
|
||||
if (isLoggingEnabled())
|
||||
LOG.warn(getLogPrefix() + "cancelTempBasal - Could not read currect TBR, canceling operation.");
|
||||
finishAction("TBR");
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.medtronic_cmd_cant_read_tbr));
|
||||
}
|
||||
|
||||
|
@ -1439,13 +1439,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
|
||||
|
||||
return new PumpEnactResult().success(true).enacted(true) //
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true) //
|
||||
.isTempCancel(true);
|
||||
} else {
|
||||
if (isLoggingEnabled())
|
||||
LOG.info(getLogPrefix() + "cancelTempBasal - Cancel TBR failed.");
|
||||
|
||||
return new PumpEnactResult().success(response).enacted(response) //
|
||||
return new PumpEnactResult(getInjector()).success(response).enacted(response) //
|
||||
.comment(MainApp.gs(R.string.medtronic_cmd_cant_cancel_tbr));
|
||||
}
|
||||
}
|
||||
|
@ -1472,7 +1472,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
// this shouldn't be needed, but let's do check if profile setting we are setting is same as current one
|
||||
if (isProfileSame(profile)) {
|
||||
return new PumpEnactResult() //
|
||||
return new PumpEnactResult(getInjector()) //
|
||||
.success(true) //
|
||||
.enacted(false) //
|
||||
.comment(MainApp.gs(R.string.medtronic_cmd_basal_profile_not_set_is_same));
|
||||
|
@ -1484,7 +1484,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
setRefreshButtonEnabled(true);
|
||||
|
||||
return new PumpEnactResult() //
|
||||
return new PumpEnactResult(getInjector()) //
|
||||
.success(false) //
|
||||
.enacted(false) //
|
||||
.comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable));
|
||||
|
@ -1497,7 +1497,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
String profileInvalid = isProfileValid(basalProfile);
|
||||
|
||||
if (profileInvalid != null) {
|
||||
return new PumpEnactResult() //
|
||||
return new PumpEnactResult(getInjector()) //
|
||||
.success(false) //
|
||||
.enacted(false) //
|
||||
.comment(MainApp.gs(R.string.medtronic_cmd_set_profile_pattern_overflow, profileInvalid));
|
||||
|
@ -1512,9 +1512,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
LOG.info(getLogPrefix() + "Basal Profile was set: " + response);
|
||||
|
||||
if (response) {
|
||||
return new PumpEnactResult().success(true).enacted(true);
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true);
|
||||
} else {
|
||||
return new PumpEnactResult().success(response).enacted(response) //
|
||||
return new PumpEnactResult(getInjector()).success(response).enacted(response) //
|
||||
.comment(MainApp.gs(R.string.medtronic_cmd_basal_profile_could_not_be_set));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ class VirtualPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
override fun loadTDDs(): PumpEnactResult { //no result, could read DB in the future?
|
||||
return PumpEnactResult()
|
||||
return PumpEnactResult(injector)
|
||||
}
|
||||
|
||||
override fun getCustomActions(): List<CustomAction>? {
|
||||
|
@ -179,7 +179,7 @@ class VirtualPumpPlugin @Inject constructor(
|
|||
override fun setNewBasalProfile(profile: Profile): PumpEnactResult {
|
||||
lastDataTime = System.currentTimeMillis()
|
||||
// Do nothing here. we are using ConfigBuilderPlugin.getPlugin().getActiveProfile().getProfile();
|
||||
val result = PumpEnactResult()
|
||||
val result = PumpEnactResult(injector)
|
||||
result.success = true
|
||||
val notification = Notification(Notification.PROFILE_SET_OK, resourceHelper.gs(R.string.profile_set_ok), Notification.INFO, 60)
|
||||
rxBus.send(EventNewNotification(notification))
|
||||
|
@ -207,7 +207,7 @@ class VirtualPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
|
||||
val result = PumpEnactResult()
|
||||
val result = PumpEnactResult(injector)
|
||||
result.success = true
|
||||
result.bolusDelivered = detailedBolusInfo.insulin
|
||||
result.carbsDelivered = detailedBolusInfo.carbs
|
||||
|
@ -242,7 +242,7 @@ class VirtualPumpPlugin @Inject constructor(
|
|||
.absolute(absoluteRate)
|
||||
.duration(durationInMinutes)
|
||||
.source(Source.USER)
|
||||
val result = PumpEnactResult()
|
||||
val result = PumpEnactResult(injector)
|
||||
result.success = true
|
||||
result.enacted = true
|
||||
result.isTempCancel = false
|
||||
|
@ -262,7 +262,7 @@ class VirtualPumpPlugin @Inject constructor(
|
|||
.percent(percent)
|
||||
.duration(durationInMinutes)
|
||||
.source(Source.USER)
|
||||
val result = PumpEnactResult()
|
||||
val result = PumpEnactResult(injector)
|
||||
result.success = true
|
||||
result.enacted = true
|
||||
result.percent = percent
|
||||
|
@ -299,7 +299,7 @@ class VirtualPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
override fun cancelTempBasal(force: Boolean): PumpEnactResult {
|
||||
val result = PumpEnactResult()
|
||||
val result = PumpEnactResult(injector)
|
||||
result.success = true
|
||||
result.isTempCancel = true
|
||||
result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
|
||||
|
@ -316,7 +316,7 @@ class VirtualPumpPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
override fun cancelExtendedBolus(): PumpEnactResult {
|
||||
val result = PumpEnactResult()
|
||||
val result = PumpEnactResult(injector)
|
||||
if (treatmentsPlugin.isInHistoryExtendedBoluslInProgress) {
|
||||
val exStop = ExtendedBolus(System.currentTimeMillis())
|
||||
exStop.source = Source.USER
|
||||
|
|
|
@ -96,7 +96,7 @@ class CommandQueue @Inject constructor(
|
|||
var performing: Command? = null
|
||||
|
||||
private fun executingNowError(): PumpEnactResult =
|
||||
PumpEnactResult().success(false).enacted(false).comment(resourceHelper.gs(R.string.executingrightnow))
|
||||
PumpEnactResult(injector).success(false).enacted(false).comment(resourceHelper.gs(R.string.executingrightnow))
|
||||
|
||||
override fun isRunning(type: CommandType): Boolean = performing?.commandType == type
|
||||
|
||||
|
@ -251,7 +251,7 @@ class CommandQueue @Inject constructor(
|
|||
@Synchronized
|
||||
override fun cancelAllBoluses() {
|
||||
if (!isRunning(CommandType.BOLUS)) {
|
||||
rxBus.send(EventDismissBolusProgressIfRunning(PumpEnactResult().success(true).enacted(false)))
|
||||
rxBus.send(EventDismissBolusProgressIfRunning(PumpEnactResult(injector).success(true).enacted(false)))
|
||||
}
|
||||
removeAll(CommandType.BOLUS)
|
||||
removeAll(CommandType.SMB_BOLUS)
|
||||
|
@ -335,13 +335,13 @@ class CommandQueue @Inject constructor(
|
|||
override fun setProfile(profile: Profile, callback: Callback?): Boolean {
|
||||
if (isThisProfileSet(profile)) {
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "Correct profile already set")
|
||||
callback?.result(PumpEnactResult().success(true).enacted(false))?.run()
|
||||
callback?.result(PumpEnactResult(injector).success(true).enacted(false))?.run()
|
||||
return false
|
||||
}
|
||||
if (!MainApp.isEngineeringModeOrRelease()) {
|
||||
val notification = Notification(Notification.NOT_ENG_MODE_OR_RELEASE, resourceHelper.gs(R.string.not_eng_mode_or_release), Notification.URGENT)
|
||||
rxBus.send(EventNewNotification(notification))
|
||||
callback?.result(PumpEnactResult().success(false).enacted(false).comment(resourceHelper.gs(R.string.not_eng_mode_or_release)))?.run()
|
||||
callback?.result(PumpEnactResult(injector).success(false).enacted(false).comment(resourceHelper.gs(R.string.not_eng_mode_or_release)))?.run()
|
||||
return false
|
||||
}
|
||||
// Compare with pump limits
|
||||
|
@ -350,7 +350,7 @@ class CommandQueue @Inject constructor(
|
|||
if (basalValue.value < activePlugin.get().activePump.pumpDescription.basalMinimumRate) {
|
||||
val notification = Notification(Notification.BASAL_VALUE_BELOW_MINIMUM, resourceHelper.gs(R.string.basalvaluebelowminimum), Notification.URGENT)
|
||||
rxBus.send(EventNewNotification(notification))
|
||||
callback?.result(PumpEnactResult().success(false).enacted(false).comment(resourceHelper.gs(R.string.basalvaluebelowminimum)))?.run()
|
||||
callback?.result(PumpEnactResult(injector).success(false).enacted(false).comment(resourceHelper.gs(R.string.basalvaluebelowminimum)))?.run()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
|
|||
import javax.inject.Inject
|
||||
|
||||
abstract class Command(
|
||||
injector: HasAndroidInjector,
|
||||
val injector: HasAndroidInjector,
|
||||
val commandType: CommandType,
|
||||
val callback: Callback? = null
|
||||
) {
|
||||
|
@ -42,7 +42,7 @@ abstract class Command(
|
|||
abstract fun status(): String
|
||||
|
||||
fun cancel() {
|
||||
val result = PumpEnactResult()
|
||||
val result = PumpEnactResult(injector)
|
||||
result.success = false
|
||||
result.comment = resourceHelper.gs(R.string.connectiontimedout)
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "Result cancel")
|
||||
|
|
|
@ -23,7 +23,7 @@ class CommandReadStatus(
|
|||
localAlertUtils.notifyPumpStatusRead()
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "CommandReadStatus executed. Reason: $reason")
|
||||
val pump = activePlugin.activePump
|
||||
val result = PumpEnactResult().success(false)
|
||||
val result = PumpEnactResult(injector).success(false)
|
||||
val lastConnection = pump.lastDataTime()
|
||||
if (lastConnection > System.currentTimeMillis() - T.mins(1).msecs()) result.success(true)
|
||||
callback?.result(result)?.run()
|
||||
|
|
|
@ -24,11 +24,11 @@ class CommandSMBBolus(
|
|||
val lastBolusTime = activePlugin.activeTreatments.lastBolusTime
|
||||
if (lastBolusTime != 0L && lastBolusTime + T.mins(3).msecs() > DateUtil.now()) {
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "SMB requested but still in 3 min interval")
|
||||
r = PumpEnactResult().enacted(false).success(false).comment("SMB requested but still in 3 min interval")
|
||||
r = PumpEnactResult(injector).enacted(false).success(false).comment("SMB requested but still in 3 min interval")
|
||||
} else if (detailedBolusInfo.deliverAt != 0L && detailedBolusInfo.deliverAt + T.mins(1).msecs() > System.currentTimeMillis()) {
|
||||
r = activePlugin.activePump.deliverTreatment(detailedBolusInfo)
|
||||
} else {
|
||||
r = PumpEnactResult().enacted(false).success(false).comment("SMB request too old")
|
||||
r = PumpEnactResult(injector).enacted(false).success(false).comment("SMB request too old")
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "SMB bolus canceled. deliverAt: " + DateUtil.dateAndTimeString(detailedBolusInfo.deliverAt))
|
||||
}
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "Result success: ${r.success} enacted: ${r.enacted}")
|
||||
|
|
|
@ -26,7 +26,7 @@ class CommandSetProfile constructor(
|
|||
override fun execute() {
|
||||
if (commandQueue.isThisProfileSet(profile)) {
|
||||
aapsLogger.debug(LTag.PUMPQUEUE, "Correct profile already set. profile: $profile")
|
||||
callback?.result(PumpEnactResult().success(true).enacted(false))?.run()
|
||||
callback?.result(PumpEnactResult(injector).success(true).enacted(false))?.run()
|
||||
return
|
||||
}
|
||||
val r = activePlugin.activePump.setNewBasalProfile(profile)
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
package info
|
||||
|
||||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.data.Profile
|
||||
import org.json.JSONObject
|
||||
import org.junit.Rule
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
import org.mockito.junit.MockitoRule
|
||||
|
||||
open class TestBase {
|
||||
val validProfileJSON = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"},{\"time\":\"2:00\",\"value\":\"110\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
||||
val validProfile: Profile = Profile(JSONObject(validProfileJSON), Constants.MGDL)
|
||||
|
||||
// Add a JUnit rule that will setup the @Mock annotated vars and log.
|
||||
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
|
||||
@get:Rule
|
||||
|
|
|
@ -1,24 +1,18 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||
|
||||
import android.content.Context
|
||||
import com.google.common.base.Optional
|
||||
import dagger.Lazy
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.TestBase
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.queue.Callback
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
|
@ -26,6 +20,7 @@ import org.junit.Assert
|
|||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers.eq
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.`when`
|
||||
|
@ -36,6 +31,7 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
@PrepareForTest(VirtualPumpPlugin::class, RxBusWrapper::class)
|
||||
class ActionLoopDisableTest : TestBase() {
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var rxBus: RxBusWrapper
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
|
@ -46,6 +42,22 @@ class ActionLoopDisableTest : TestBase() {
|
|||
|
||||
lateinit var sut: ActionLoopDisable
|
||||
|
||||
private var injector: HasAndroidInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is ActionLoopDisable) {
|
||||
it.loopPlugin = loopPlugin
|
||||
it.resourceHelper = resourceHelper
|
||||
it.configBuilderPlugin = configBuilderPlugin
|
||||
it.commandQueue = commandQueue
|
||||
it.rxBus = rxBus
|
||||
}
|
||||
if (it is PumpEnactResult) {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
|
||||
|
@ -56,14 +68,7 @@ class ActionLoopDisableTest : TestBase() {
|
|||
`when`(resourceHelper.gs(R.string.disableloop)).thenReturn("Disable loop")
|
||||
`when`(resourceHelper.gs(R.string.alreadydisabled)).thenReturn("Disable loop")
|
||||
|
||||
sut = ActionLoopDisable(HasAndroidInjector { AndroidInjector { Unit } }) // do nothing injector
|
||||
.also { // inject the mocks
|
||||
it.loopPlugin = loopPlugin
|
||||
it.resourceHelper = resourceHelper
|
||||
it.configBuilderPlugin = configBuilderPlugin
|
||||
it.commandQueue = commandQueue
|
||||
it.rxBus = rxBus
|
||||
}
|
||||
sut = ActionLoopDisable(injector) // do nothing injector
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -83,15 +88,22 @@ class ActionLoopDisableTest : TestBase() {
|
|||
|
||||
@Test
|
||||
fun doActionTest() {
|
||||
`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true)
|
||||
sut.doAction(object : Callback() {
|
||||
override fun run() {}
|
||||
})
|
||||
Mockito.verify(loopPlugin, Mockito.times(1)).setPluginEnabled(PluginType.LOOP, true)
|
||||
Mockito.verify(loopPlugin, Mockito.times(1)).setPluginEnabled(PluginType.LOOP, false)
|
||||
Mockito.verify(configBuilderPlugin, Mockito.times(1)).storeSettings("ActionLoopDisable")
|
||||
Mockito.verify(commandQueue, Mockito.times(1)).cancelTempBasal(eq(true), anyObject())
|
||||
|
||||
// another call should keep it disabled
|
||||
`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false)
|
||||
|
||||
// another call should keep it disabled, no new invocation
|
||||
sut.doAction(object : Callback() {
|
||||
override fun run() {}
|
||||
})
|
||||
Mockito.verify(loopPlugin, Mockito.times(2)).setPluginEnabled(PluginType.LOOP, true)
|
||||
Mockito.verify(loopPlugin, Mockito.times(1)).setPluginEnabled(PluginType.LOOP, false)
|
||||
Mockito.verify(configBuilderPlugin, Mockito.times(1)).storeSettings("ActionLoopDisable")
|
||||
Mockito.verify(commandQueue, Mockito.times(1)).cancelTempBasal(eq(true), anyObject())
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS
|
||||
|
||||
import android.content.Context
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.AAPSMocker
|
||||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.MainApp
|
||||
|
@ -74,6 +76,6 @@ class DanaRSPluginTest : DanaRSTestBase() {
|
|||
Mockito.`when`(resourceHelper.gs(eq(R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate")
|
||||
|
||||
rxBus = RxBusWrapper()
|
||||
danaRSPlugin = DanaRSPlugin(aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump)
|
||||
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump)
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import android.content.Context
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
||||
import info.nightscout.androidaps.interfaces.Constraint
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
|
@ -47,7 +49,7 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() {
|
|||
|
||||
@Before
|
||||
fun mock() {
|
||||
danaRSPlugin = DanaRSPlugin(aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump)
|
||||
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump)
|
||||
Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0))
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
|||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||
|
|
|
@ -67,7 +67,7 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() {
|
|||
|
||||
@Before
|
||||
fun mock() {
|
||||
danaRSPlugin = DanaRSPlugin(aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump)
|
||||
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump)
|
||||
danaRSPlugin.bolusingTreatment = Treatment(treatmentInjector)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue