PumpEnactResult -> kt
This commit is contained in:
parent
00ee60ff1e
commit
2ea423c704
28 changed files with 478 additions and 613 deletions
|
@ -2,6 +2,22 @@
|
|||
<code_scheme name="Project" version="173">
|
||||
<option name="AUTODETECT_INDENTS" value="false" />
|
||||
<JetCodeStyleSettings>
|
||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||
<value>
|
||||
<package name="java.util" alias="false" withSubpackages="false" />
|
||||
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
||||
<package name="io.ktor" alias="false" withSubpackages="true" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="PACKAGES_IMPORT_LAYOUT">
|
||||
<value>
|
||||
<package name="" alias="false" withSubpackages="true" />
|
||||
<package name="java" alias="false" withSubpackages="true" />
|
||||
<package name="javax" alias="false" withSubpackages="true" />
|
||||
<package name="kotlin" alias="false" withSubpackages="true" />
|
||||
<package name="" alias="true" withSubpackages="true" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="ALIGN_IN_COLUMNS_CASE_BRANCH" value="true" />
|
||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="6" />
|
||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="6" />
|
||||
|
|
|
@ -509,18 +509,18 @@ open class LoopPlugin @Inject constructor(
|
|||
*/
|
||||
private fun applyTBRRequest(request: APSResult?, profile: Profile?, callback: Callback?) {
|
||||
if (!request!!.tempBasalRequested) {
|
||||
callback?.result(PumpEnactResult(injector).enacted(false).success(true).comment(resourceHelper.gs(R.string.nochangerequested)))?.run()
|
||||
callback?.result(PumpEnactResult(injector).enacted(false).success(true).comment(R.string.nochangerequested))?.run()
|
||||
return
|
||||
}
|
||||
val pump = activePlugin.activePump
|
||||
if (!pump.isInitialized()) {
|
||||
aapsLogger.debug(LTag.APS, "applyAPSRequest: " + resourceHelper.gs(R.string.pumpNotInitialized))
|
||||
callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpNotInitialized)).enacted(false).success(false))?.run()
|
||||
callback?.result(PumpEnactResult(injector).comment(R.string.pumpNotInitialized).enacted(false).success(false))?.run()
|
||||
return
|
||||
}
|
||||
if (pump.isSuspended()) {
|
||||
aapsLogger.debug(LTag.APS, "applyAPSRequest: " + resourceHelper.gs(R.string.pumpsuspended))
|
||||
callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpsuspended)).enacted(false).success(false))?.run()
|
||||
callback?.result(PumpEnactResult(injector).comment(R.string.pumpsuspended).enacted(false).success(false))?.run()
|
||||
return
|
||||
}
|
||||
aapsLogger.debug(LTag.APS, "applyAPSRequest: $request")
|
||||
|
@ -534,13 +534,13 @@ open class LoopPlugin @Inject constructor(
|
|||
} else {
|
||||
aapsLogger.debug(LTag.APS, "applyAPSRequest: Basal set correctly")
|
||||
callback?.result(PumpEnactResult(injector).percent(request.percent).duration(0)
|
||||
.enacted(false).success(true).comment(resourceHelper.gs(R.string.basal_set_correctly)))?.run()
|
||||
.enacted(false).success(true).comment(R.string.basal_set_correctly))?.run()
|
||||
}
|
||||
} else if (activeTemp != null && activeTemp.plannedRemainingMinutes > 5 && request.duration - activeTemp.plannedRemainingMinutes < 30 && request.percent == activeTemp.percentRate) {
|
||||
aapsLogger.debug(LTag.APS, "applyAPSRequest: Temp basal set correctly")
|
||||
callback?.result(PumpEnactResult(injector).percent(request.percent)
|
||||
.enacted(false).success(true).duration(activeTemp.plannedRemainingMinutes)
|
||||
.comment(resourceHelper.gs(R.string.let_temp_basal_run)))?.run()
|
||||
.comment(R.string.let_temp_basal_run))?.run()
|
||||
} else {
|
||||
aapsLogger.debug(LTag.APS, "applyAPSRequest: tempBasalPercent()")
|
||||
commandQueue.tempBasalPercent(request.percent, request.duration, false, profile!!, callback)
|
||||
|
@ -553,13 +553,13 @@ open class LoopPlugin @Inject constructor(
|
|||
} else {
|
||||
aapsLogger.debug(LTag.APS, "applyAPSRequest: Basal set correctly")
|
||||
callback?.result(PumpEnactResult(injector).absolute(request.rate).duration(0)
|
||||
.enacted(false).success(true).comment(resourceHelper.gs(R.string.basal_set_correctly)))?.run()
|
||||
.enacted(false).success(true).comment(R.string.basal_set_correctly))?.run()
|
||||
}
|
||||
} else if (activeTemp != null && activeTemp.plannedRemainingMinutes > 5 && request.duration - activeTemp.plannedRemainingMinutes < 30 && abs(request.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < pump.pumpDescription.basalStep) {
|
||||
aapsLogger.debug(LTag.APS, "applyAPSRequest: Temp basal set correctly")
|
||||
callback?.result(PumpEnactResult(injector).absolute(activeTemp.tempBasalConvertedToAbsolute(now, profile))
|
||||
.enacted(false).success(true).duration(activeTemp.plannedRemainingMinutes)
|
||||
.comment(resourceHelper.gs(R.string.let_temp_basal_run)))?.run()
|
||||
.comment(R.string.let_temp_basal_run))?.run()
|
||||
} else {
|
||||
aapsLogger.debug(LTag.APS, "applyAPSRequest: setTempBasalAbsolute()")
|
||||
commandQueue.tempBasalAbsolute(request.rate, request.duration, false, profile!!, callback)
|
||||
|
@ -576,18 +576,18 @@ open class LoopPlugin @Inject constructor(
|
|||
if (lastBolusTime != 0L && lastBolusTime + 3 * 60 * 1000 > System.currentTimeMillis()) {
|
||||
aapsLogger.debug(LTag.APS, "SMB requested but still in 3 min interval")
|
||||
callback?.result(PumpEnactResult(injector)
|
||||
.comment(resourceHelper.gs(R.string.smb_frequency_exceeded))
|
||||
.comment(R.string.smb_frequency_exceeded)
|
||||
.enacted(false).success(false))?.run()
|
||||
return
|
||||
}
|
||||
if (!pump.isInitialized()) {
|
||||
aapsLogger.debug(LTag.APS, "applySMBRequest: " + resourceHelper.gs(R.string.pumpNotInitialized))
|
||||
callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpNotInitialized)).enacted(false).success(false))?.run()
|
||||
callback?.result(PumpEnactResult(injector).comment(R.string.pumpNotInitialized).enacted(false).success(false))?.run()
|
||||
return
|
||||
}
|
||||
if (pump.isSuspended()) {
|
||||
aapsLogger.debug(LTag.APS, "applySMBRequest: " + resourceHelper.gs(R.string.pumpsuspended))
|
||||
callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpsuspended)).enacted(false).success(false))?.run()
|
||||
callback?.result(PumpEnactResult(injector).comment(R.string.pumpsuspended).enacted(false).success(false))?.run()
|
||||
return
|
||||
}
|
||||
aapsLogger.debug(LTag.APS, "applySMBRequest: $request")
|
||||
|
|
|
@ -128,7 +128,7 @@ open class CommandQueue @Inject constructor(
|
|||
}
|
||||
|
||||
private fun executingNowError(): PumpEnactResult =
|
||||
PumpEnactResult(injector).success(false).enacted(false).comment(resourceHelper.gs(R.string.executingrightnow))
|
||||
PumpEnactResult(injector).success(false).enacted(false).comment(R.string.executingrightnow)
|
||||
|
||||
override fun isRunning(type: CommandType): Boolean = performing?.commandType == type
|
||||
|
||||
|
@ -380,7 +380,7 @@ open class CommandQueue @Inject constructor(
|
|||
if (!buildHelper.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(injector).success(false).enacted(false).comment(resourceHelper.gs(R.string.not_eng_mode_or_release)))?.run()
|
||||
callback?.result(PumpEnactResult(injector).success(false).enacted(false).comment(R.string.not_eng_mode_or_release)))?.run()
|
||||
return false
|
||||
}
|
||||
*/
|
||||
|
@ -390,7 +390,7 @@ open 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(injector).success(false).enacted(false).comment(resourceHelper.gs(R.string.basalvaluebelowminimum)))?.run()
|
||||
callback?.result(PumpEnactResult(injector).success(false).enacted(false).comment(R.string.basalvaluebelowminimum))?.run()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import info.nightscout.androidaps.TestBaseWithProfile
|
|||
import info.nightscout.androidaps.dana.DanaPump
|
||||
import info.nightscout.androidaps.danar.DanaRPlugin
|
||||
import info.nightscout.androidaps.danars.DanaRSPlugin
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
|
||||
|
@ -91,6 +92,9 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
|
|||
if (it is Objective) {
|
||||
it.sp = sp
|
||||
}
|
||||
if (it is PumpEnactResult) {
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,6 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
var injector: HasAndroidInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is PumpEnactResult) {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
if (it is AuthRequest) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import dagger.android.HasAndroidInjector
|
|||
import info.nightscout.androidaps.Config
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.androidaps.TestPumpPlugin
|
||||
import info.nightscout.androidaps.core.R
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.Constraint
|
||||
|
@ -120,6 +121,7 @@ class CommandQueueTest : TestBaseWithProfile() {
|
|||
`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(rateConstraint)
|
||||
val percentageConstraint = Constraint(0)
|
||||
`when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject())).thenReturn(percentageConstraint)
|
||||
`when`(resourceHelper.gs(R.string.connectiontimedout)).thenReturn("Connection timed out")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -41,7 +41,6 @@ class ActionAlarmTest : TestBase() {
|
|||
it.timerUtil = timerUtil
|
||||
}
|
||||
if (it is PumpEnactResult) {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@ class ActionNotificationTest : TestBase() {
|
|||
it.nsUpload = nsUpload
|
||||
}
|
||||
if (it is PumpEnactResult) {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,6 @@ open class ActionsTestBase : TestBaseWithProfile() {
|
|||
it.rxBus = rxBus
|
||||
}
|
||||
if (it is PumpEnactResult) {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
if (it is InputTempTarget) {
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.os.SystemClock;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -166,7 +165,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
super.onStart();
|
||||
ruffyScripter = new RuffyScripter(context);
|
||||
OPERATION_NOT_SUPPORTED = new PumpEnactResult(getInjector())
|
||||
.success(false).enacted(false).comment(getResourceHelper().gs(R.string.combo_pump_unsupported_operation));
|
||||
.success(false).enacted(false).comment(R.string.combo_pump_unsupported_operation);
|
||||
}
|
||||
|
||||
public ComboPump getPump() {
|
||||
|
@ -252,7 +251,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
getAapsLogger().error("setNewBasalProfile not initialized");
|
||||
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, getResourceHelper().gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
||||
rxBus.send(new EventNewNotification(notification));
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(R.string.pumpNotInitializedProfileNotSet));
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(R.string.pumpNotInitializedProfileNotSet);
|
||||
}
|
||||
|
||||
BasalProfile requestedBasalProfile = convertProfileToComboProfile(profile);
|
||||
|
@ -265,7 +264,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
|
||||
CommandResult stateResult = runCommand(null, 1, ruffyScripter::readPumpState);
|
||||
if (stateResult.state.unsafeUsageDetected == PumpState.UNSUPPORTED_BASAL_RATE_PROFILE) {
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(R.string.combo_force_disabled_notification));
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(R.string.combo_force_disabled_notification);
|
||||
}
|
||||
|
||||
CommandResult setResult = runCommand(getResourceHelper().gs(R.string.combo_activity_setting_basal_profile), 2,
|
||||
|
@ -273,7 +272,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
if (!setResult.success) {
|
||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, getResourceHelper().gs(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||
rxBus.send(new EventNewNotification(notification));
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(R.string.failedupdatebasalprofile));
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(R.string.failedupdatebasalprofile);
|
||||
}
|
||||
|
||||
pump.basalProfile = requestedBasalProfile;
|
||||
|
@ -480,7 +479,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
getAapsLogger().error("deliverTreatment: Invalid input");
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.bolusDelivered(0d).carbsDelivered(0d)
|
||||
.comment(getResourceHelper().gs(R.string.invalidinput));
|
||||
.comment(R.string.invalidinput);
|
||||
} else if (detailedBolusInfo.insulin > 0) {
|
||||
// bolus needed, ask pump to deliver it
|
||||
return deliverBolus(detailedBolusInfo);
|
||||
|
@ -496,7 +495,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true)
|
||||
.bolusDelivered(0d).carbsDelivered(detailedBolusInfo.carbs)
|
||||
.comment(getResourceHelper().gs(R.string.virtualpump_resultok));
|
||||
.comment(R.string.virtualpump_resultok);
|
||||
}
|
||||
} finally {
|
||||
rxBus.send(new EventComboPumpUpdateGUI());
|
||||
|
@ -513,16 +512,16 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
CommandResult stateResult = runCommand(null, 2, () -> ruffyScripter.readQuickInfo(1));
|
||||
if (!stateResult.success) {
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(getResourceHelper().gs(R.string.combo_error_no_connection_no_bolus_delivered));
|
||||
.comment(R.string.combo_error_no_connection_no_bolus_delivered);
|
||||
}
|
||||
if (stateResult.reservoirLevel != -1 && stateResult.reservoirLevel - 0.5 < detailedBolusInfo.insulin) {
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(getResourceHelper().gs(R.string.combo_reservoir_level_insufficient_for_bolus));
|
||||
.comment(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(getInjector()).success(false).enacted(false)
|
||||
.comment(getResourceHelper().gs(R.string.combo_bolus_rejected_due_to_pump_history_change));
|
||||
.comment(R.string.combo_bolus_rejected_due_to_pump_history_change);
|
||||
}
|
||||
|
||||
Bolus previousBolus = stateResult.history != null && !stateResult.history.bolusHistory.isEmpty()
|
||||
|
@ -535,7 +534,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
&& previousBolus.timestamp + 60 * 1000 > System.currentTimeMillis()) {
|
||||
getAapsLogger().debug(LTag.PUMP, "Bolus request rejected, same bolus was successfully delivered very recently");
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(getResourceHelper().gs(R.string.bolus_frequency_exceeded));
|
||||
.comment(R.string.bolus_frequency_exceeded);
|
||||
}
|
||||
|
||||
// if the last bolus was given in the current minute, wait till the pump clock moves
|
||||
|
@ -551,7 +550,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
}
|
||||
if (!timeCheckResult.success) {
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(getResourceHelper().gs(R.string.combo_error_no_connection_no_bolus_delivered));
|
||||
.comment(R.string.combo_error_no_connection_no_bolus_delivered);
|
||||
}
|
||||
getAapsLogger().debug(LTag.PUMP, "Waiting for pump clock to advance for the next unused bolus record timestamp");
|
||||
SystemClock.sleep(2000);
|
||||
|
@ -586,7 +585,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
CommandResult postBolusStateResult = runCommand(null, 3, () -> ruffyScripter.readQuickInfo(2));
|
||||
if (!postBolusStateResult.success) {
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(getResourceHelper().gs(R.string.combo_error_bolus_verification_failed));
|
||||
.comment(R.string.combo_error_bolus_verification_failed);
|
||||
}
|
||||
Bolus lastPumpBolus = postBolusStateResult.history != null && !postBolusStateResult.history.bolusHistory.isEmpty()
|
||||
? postBolusStateResult.history.bolusHistory.get(0)
|
||||
|
@ -600,14 +599,14 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
return new PumpEnactResult(getInjector())
|
||||
.success(false)
|
||||
.enacted(false)
|
||||
.comment(getResourceHelper().gs(R.string.combo_error_no_bolus_delivered));
|
||||
.comment(R.string.combo_error_no_bolus_delivered);
|
||||
}
|
||||
}
|
||||
|
||||
// at least some insulin delivered, so add it to treatments
|
||||
if (!addBolusToTreatments(detailedBolusInfo, lastPumpBolus))
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(true)
|
||||
.comment(getResourceHelper().gs(R.string.combo_error_updating_treatment_record));
|
||||
.comment(R.string.combo_error_updating_treatment_record);
|
||||
|
||||
// check pump bolus record has a sane timestamp
|
||||
long now = System.currentTimeMillis();
|
||||
|
@ -741,7 +740,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
|
||||
if (pumpHistoryChanged && percent > 110) {
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(getResourceHelper().gs(R.string.combo_high_temp_rejected_due_to_pump_history_changes));
|
||||
.comment(R.string.combo_high_temp_rejected_due_to_pump_history_changes);
|
||||
}
|
||||
|
||||
int adjustedPercent = percent;
|
||||
|
@ -1338,8 +1337,8 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
|||
@NonNull @Override
|
||||
public PumpEnactResult loadTDDs() {
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = readHistory(new PumpHistoryRequest().tddHistory(PumpHistoryRequest.FULL));
|
||||
if (result.success) {
|
||||
result.success(readHistory(new PumpHistoryRequest().tddHistory(PumpHistoryRequest.FULL)));
|
||||
if (result.getSuccess()) {
|
||||
List<Tdd> tdds = pump.tddHistory;
|
||||
if (tdds != null) {
|
||||
HashMap<Long, TDD> map = new HashMap<>();
|
||||
|
|
|
@ -5,6 +5,7 @@ import dagger.android.AndroidInjector
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.combo.R
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus
|
||||
|
@ -34,6 +35,9 @@ class ComboPluginTest : TestBase() {
|
|||
|
||||
val injector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is PumpEnactResult) {
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +46,7 @@ class ComboPluginTest : TestBase() {
|
|||
@Before
|
||||
fun prepareMocks() {
|
||||
`when`(resourceHelper.gs(R.string.novalidbasalrate)).thenReturn("No valid basal rate read from pump")
|
||||
`when`(resourceHelper.gs(R.string.combo_pump_unsupported_operation)).thenReturn("Requested operation not supported by pump")
|
||||
comboPlugin = ComboPlugin(injector, aapsLogger, RxBusWrapper(aapsSchedulers), resourceHelper, profileFunction, treatmentsPlugin, sp, commandQueue, context, databaseHelper)
|
||||
}
|
||||
|
||||
|
|
|
@ -68,5 +68,5 @@ abstract class Intervals<T : Interval> {
|
|||
|
||||
@Synchronized operator fun get(index: Int): T? = rawData.valueAt(index)
|
||||
|
||||
@Synchronized fun getReversed(index: Int): T? = rawData.valueAt(size() - 1 - index)
|
||||
@Synchronized fun getReversed(index: Int): T = rawData.valueAt(size() - 1 - index)
|
||||
}
|
|
@ -1,201 +0,0 @@
|
|||
package info.nightscout.androidaps.data;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.core.R;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.Round;
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||
|
||||
public class PumpEnactResult {
|
||||
@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
|
||||
public String comment = "";
|
||||
|
||||
// Result of basal change
|
||||
public int duration = -1; // duration set [minutes]
|
||||
public double absolute = -1d; // absolute rate [U/h] , isPercent = false
|
||||
public int percent = -1; // percent of current basal [%] (100% = current basal), isPercent = true
|
||||
public boolean isPercent = false; // if true percent is used, otherwise absolute
|
||||
public boolean isTempCancel = false; // if true we are caceling temp basal
|
||||
// Result of treatment delivery
|
||||
public double bolusDelivered = 0d; // real value of delivered insulin
|
||||
public double carbsDelivered = 0d; // real value of delivered carbs
|
||||
|
||||
public boolean queued = false;
|
||||
|
||||
public PumpEnactResult(HasAndroidInjector injector) {
|
||||
injector.androidInjector().inject(this);
|
||||
}
|
||||
|
||||
public PumpEnactResult success(boolean success) {
|
||||
this.success = success;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PumpEnactResult enacted(boolean enacted) {
|
||||
this.enacted = enacted;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PumpEnactResult comment(String comment) {
|
||||
this.comment = comment;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PumpEnactResult comment(int comment) {
|
||||
this.comment = resourceHelper.gs(comment);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PumpEnactResult duration(int duration) {
|
||||
this.duration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PumpEnactResult absolute(double absolute) {
|
||||
this.absolute = absolute;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PumpEnactResult percent(int percent) {
|
||||
this.percent = percent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PumpEnactResult isPercent(boolean isPercent) {
|
||||
this.isPercent = isPercent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PumpEnactResult isTempCancel(boolean isTempCancel) {
|
||||
this.isTempCancel = isTempCancel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PumpEnactResult bolusDelivered(double bolusDelivered) {
|
||||
this.bolusDelivered = bolusDelivered;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PumpEnactResult carbsDelivered(double carbsDelivered) {
|
||||
this.carbsDelivered = carbsDelivered;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PumpEnactResult queued(boolean queued) {
|
||||
this.queued = queued;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String log() {
|
||||
return "Success: " + success +
|
||||
" Enacted: " + enacted +
|
||||
" Comment: " + comment +
|
||||
" Duration: " + duration +
|
||||
" Absolute: " + absolute +
|
||||
" Percent: " + percent +
|
||||
" IsPercent: " + isPercent +
|
||||
" IsTempCancel: " + isTempCancel +
|
||||
" bolusDelivered: " + bolusDelivered +
|
||||
" carbsDelivered: " + carbsDelivered +
|
||||
" Queued: " + queued;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String ret = resourceHelper.gs(R.string.success) + ": " + success;
|
||||
if (enacted) {
|
||||
if (bolusDelivered > 0) {
|
||||
ret += "\n" + resourceHelper.gs(R.string.enacted) + ": " + enacted;
|
||||
ret += "\n" + resourceHelper.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + resourceHelper.gs(R.string.configbuilder_insulin)
|
||||
+ ": " + bolusDelivered + " " + resourceHelper.gs(R.string.insulin_unit_shortname);
|
||||
} else if (isTempCancel) {
|
||||
ret += "\n" + resourceHelper.gs(R.string.enacted) + ": " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "\n" + resourceHelper.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + resourceHelper.gs(R.string.canceltemp);
|
||||
} else if (isPercent) {
|
||||
ret += "\n" + resourceHelper.gs(R.string.enacted) + ": " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "\n" + resourceHelper.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + resourceHelper.gs(R.string.duration) + ": " + duration + " min";
|
||||
ret += "\n" + resourceHelper.gs(R.string.percent) + ": " + percent + "%";
|
||||
} else {
|
||||
ret += "\n" + resourceHelper.gs(R.string.enacted) + ": " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "\n" + resourceHelper.gs(R.string.comment) + ": " + comment;
|
||||
ret += "\n" + resourceHelper.gs(R.string.duration) + ": " + duration + " min";
|
||||
ret += "\n" + resourceHelper.gs(R.string.absolute) + ": " + absolute + " U/h";
|
||||
}
|
||||
} else {
|
||||
ret += "\n" + resourceHelper.gs(R.string.comment) + ": " + comment;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String toHtml() {
|
||||
String ret = "<b>" + resourceHelper.gs(R.string.success) + "</b>: " + success;
|
||||
if (queued) {
|
||||
ret = resourceHelper.gs(R.string.waitingforpumpresult);
|
||||
} else if (enacted) {
|
||||
if (bolusDelivered > 0) {
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.smb_shortname) + "</b>: " + bolusDelivered + " " + resourceHelper.gs(R.string.insulin_unit_shortname);
|
||||
} else if (isTempCancel) {
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment +
|
||||
"<br>" + resourceHelper.gs(R.string.canceltemp);
|
||||
} else if (isPercent && percent != -1) {
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.duration) + "</b>: " + duration + " min";
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.percent) + "</b>: " + percent + "%";
|
||||
} else if (absolute != -1) {
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.enacted) + "</b>: " + enacted;
|
||||
if (!comment.isEmpty())
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment;
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.duration) + "</b>: " + duration + " min";
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.absolute) + "</b>: " + DecimalFormatter.to2Decimal(absolute) + " U/h";
|
||||
}
|
||||
} else {
|
||||
if (!comment.isEmpty())
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public JSONObject json(Profile profile) {
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
if (bolusDelivered > 0) {
|
||||
result.put("smb", bolusDelivered);
|
||||
} else if (isTempCancel) {
|
||||
result.put("rate", 0);
|
||||
result.put("duration", 0);
|
||||
} else if (isPercent) {
|
||||
// Nightscout is expecting absolute value
|
||||
Double abs = Round.roundTo(profile.getBasal() * percent / 100, 0.01);
|
||||
result.put("rate", abs);
|
||||
result.put("duration", duration);
|
||||
} else {
|
||||
result.put("rate", absolute);
|
||||
result.put("duration", duration);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,165 @@
|
|||
package info.nightscout.androidaps.data
|
||||
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.core.R
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||
import info.nightscout.androidaps.utils.Round
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import org.json.JSONObject
|
||||
import javax.inject.Inject
|
||||
|
||||
class PumpEnactResult(injector: HasAndroidInjector) {
|
||||
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
|
||||
init {
|
||||
injector.androidInjector().inject(this)
|
||||
}
|
||||
|
||||
var success = false // request was processed successfully (but possible no change was needed)
|
||||
var enacted = false // request was processed successfully and change has been made
|
||||
var comment = ""
|
||||
|
||||
// Result of basal change
|
||||
var duration = -1 // duration set [minutes]
|
||||
var absolute = -1.0 // absolute rate [U/h] , isPercent = false
|
||||
var percent = -1 // percent of current basal [%] (100% = current basal), isPercent = true
|
||||
var isPercent = false // if true percent is used, otherwise absolute
|
||||
var isTempCancel = false // if true we are canceling temp basal
|
||||
|
||||
// Result of treatment delivery
|
||||
var bolusDelivered = 0.0 // real value of delivered insulin
|
||||
var carbsDelivered = 0.0 // real value of delivered carbs
|
||||
var queued = false
|
||||
fun success(success: Boolean): PumpEnactResult {
|
||||
this.success = success
|
||||
return this
|
||||
}
|
||||
|
||||
fun enacted(enacted: Boolean): PumpEnactResult = this.also { it.enacted = enacted }
|
||||
fun comment(comment: String): PumpEnactResult = this.also { it.comment = comment }
|
||||
fun comment(comment: Int): PumpEnactResult = this.also { it.comment = resourceHelper.gs(comment) }
|
||||
fun duration(duration: Int): PumpEnactResult = this.also { it.duration = duration }
|
||||
fun absolute(absolute: Double): PumpEnactResult = this.also { it.absolute = absolute }
|
||||
fun percent(percent: Int): PumpEnactResult = this.also { it.percent = percent }
|
||||
fun isPercent(isPercent: Boolean): PumpEnactResult = this.also { it.isPercent = isPercent }
|
||||
fun isTempCancel(isTempCancel: Boolean): PumpEnactResult = this.also { it.isTempCancel = isTempCancel }
|
||||
fun bolusDelivered(bolusDelivered: Double): PumpEnactResult = this.also { it.bolusDelivered = bolusDelivered }
|
||||
fun carbsDelivered(carbsDelivered: Double): PumpEnactResult = this.also { it.carbsDelivered = carbsDelivered }
|
||||
fun queued(queued: Boolean): PumpEnactResult = this.also { it.queued = queued }
|
||||
|
||||
fun log(): String {
|
||||
return "Success: " + success +
|
||||
" Enacted: " + enacted +
|
||||
" Comment: " + comment +
|
||||
" Duration: " + duration +
|
||||
" Absolute: " + absolute +
|
||||
" Percent: " + percent +
|
||||
" IsPercent: " + isPercent +
|
||||
" IsTempCancel: " + isTempCancel +
|
||||
" bolusDelivered: " + bolusDelivered +
|
||||
" carbsDelivered: " + carbsDelivered +
|
||||
" Queued: " + queued
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
var ret = resourceHelper.gs(R.string.success) + ": " + success
|
||||
if (enacted) {
|
||||
when {
|
||||
bolusDelivered > 0 -> {
|
||||
ret += "\n${resourceHelper.gs(R.string.enacted)}: $enacted"
|
||||
ret += "\n${resourceHelper.gs(R.string.comment)}: $comment"
|
||||
ret += "\n${resourceHelper.gs(R.string.configbuilder_insulin)}: $bolusDelivered ${resourceHelper.gs(R.string.insulin_unit_shortname)}"
|
||||
}
|
||||
|
||||
isTempCancel -> {
|
||||
ret += "\n${resourceHelper.gs(R.string.enacted)}: $enacted"
|
||||
if (comment.isNotEmpty()) ret += "\n${resourceHelper.gs(R.string.comment)}: $comment"
|
||||
ret += "\n${resourceHelper.gs(R.string.canceltemp)}"
|
||||
}
|
||||
|
||||
isPercent -> {
|
||||
ret += "\n${resourceHelper.gs(R.string.enacted)}: $enacted"
|
||||
if (comment.isNotEmpty()) ret += "\n${resourceHelper.gs(R.string.comment)}: $comment"
|
||||
ret += "\n${resourceHelper.gs(R.string.duration)}: $duration min"
|
||||
ret += "\n${resourceHelper.gs(R.string.percent)}: $percent%"
|
||||
}
|
||||
|
||||
else -> {
|
||||
ret += "\n${resourceHelper.gs(R.string.enacted)}: $enacted"
|
||||
if (comment.isNotEmpty()) ret += "\n${resourceHelper.gs(R.string.comment)}: $comment"
|
||||
ret += "\n${resourceHelper.gs(R.string.duration)}: $duration min"
|
||||
ret += "\n${resourceHelper.gs(R.string.absolute)}: $absolute U/h"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ret += "\n${resourceHelper.gs(R.string.comment)}: $comment"
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
fun toHtml(): String {
|
||||
var ret = "<b>" + resourceHelper.gs(R.string.success) + "</b>: " + success
|
||||
if (queued) {
|
||||
ret = resourceHelper.gs(R.string.waitingforpumpresult)
|
||||
} else if (enacted) {
|
||||
when {
|
||||
bolusDelivered > 0 -> {
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.enacted) + "</b>: " + enacted
|
||||
if (comment.isNotEmpty()) ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.smb_shortname) + "</b>: " + bolusDelivered + " " + resourceHelper.gs(R.string.insulin_unit_shortname)
|
||||
}
|
||||
|
||||
isTempCancel -> {
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.enacted) + "</b>: " + enacted
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment +
|
||||
"<br>" + resourceHelper.gs(R.string.canceltemp)
|
||||
}
|
||||
|
||||
isPercent && percent != -1 -> {
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.enacted) + "</b>: " + enacted
|
||||
if (comment.isNotEmpty()) ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.duration) + "</b>: " + duration + " min"
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.percent) + "</b>: " + percent + "%"
|
||||
}
|
||||
|
||||
absolute != -1.0 -> {
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.enacted) + "</b>: " + enacted
|
||||
if (comment.isNotEmpty()) ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.duration) + "</b>: " + duration + " min"
|
||||
ret += "<br><b>" + resourceHelper.gs(R.string.absolute) + "</b>: " + DecimalFormatter.to2Decimal(absolute) + " U/h"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (comment.isNotEmpty()) ret += "<br><b>" + resourceHelper.gs(R.string.comment) + "</b>: " + comment
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
fun json(profile: Profile): JSONObject {
|
||||
val result = JSONObject()
|
||||
when {
|
||||
bolusDelivered > 0 -> {
|
||||
result.put("smb", bolusDelivered)
|
||||
}
|
||||
|
||||
isTempCancel -> {
|
||||
result.put("rate", 0)
|
||||
result.put("duration", 0)
|
||||
}
|
||||
|
||||
isPercent -> {
|
||||
// Nightscout is expecting absolute value
|
||||
val abs = Round.roundTo(profile.basal * percent / 100, 0.01)
|
||||
result.put("rate", abs)
|
||||
result.put("duration", duration)
|
||||
}
|
||||
|
||||
else -> {
|
||||
result.put("rate", absolute)
|
||||
result.put("duration", duration)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package info.nightscout.androidaps.plugins.general.nsclient;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
@ -212,7 +211,7 @@ public class NSUpload {
|
|||
|
||||
JSONObject requested = new JSONObject();
|
||||
|
||||
if (lastRun.getTbrSetByPump() != null && lastRun.getTbrSetByPump().enacted) { // enacted
|
||||
if (lastRun.getTbrSetByPump() != null && lastRun.getTbrSetByPump().getEnacted()) { // enacted
|
||||
deviceStatus.enacted = lastRun.getRequest().json();
|
||||
deviceStatus.enacted.put("rate", lastRun.getTbrSetByPump().json(profile).get("rate"));
|
||||
deviceStatus.enacted.put("duration", lastRun.getTbrSetByPump().json(profile).get("duration"));
|
||||
|
@ -222,11 +221,11 @@ public class NSUpload {
|
|||
requested.put("temp", "absolute");
|
||||
deviceStatus.enacted.put("requested", requested);
|
||||
}
|
||||
if (lastRun.getTbrSetByPump() != null && lastRun.getTbrSetByPump().enacted) { // enacted
|
||||
if (lastRun.getTbrSetByPump() != null && lastRun.getTbrSetByPump().getEnacted()) { // enacted
|
||||
if (deviceStatus.enacted == null) {
|
||||
deviceStatus.enacted = lastRun.getRequest().json();
|
||||
}
|
||||
deviceStatus.enacted.put("smb", lastRun.getTbrSetByPump().bolusDelivered);
|
||||
deviceStatus.enacted.put("smb", lastRun.getTbrSetByPump().getBolusDelivered());
|
||||
requested.put("smb", lastRun.getRequest().getSmb());
|
||||
deviceStatus.enacted.put("requested", requested);
|
||||
}
|
||||
|
@ -240,9 +239,7 @@ public class NSUpload {
|
|||
}
|
||||
deviceStatus.device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL;
|
||||
JSONObject pumpstatus = pumpInterface.getJSONStatus(profile, profileName, version);
|
||||
if (pumpstatus != null) {
|
||||
deviceStatus.pump = pumpstatus;
|
||||
}
|
||||
|
||||
deviceStatus.uploaderBattery = receiverStatusStore.getBatteryLevel();
|
||||
|
||||
|
|
|
@ -406,7 +406,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
|||
// neither carbs nor bolus requested
|
||||
aapsLogger.error("deliverTreatment: Invalid input");
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).bolusDelivered(0d).carbsDelivered(0d)
|
||||
.comment(getResourceHelper().gs(R.string.invalidinput));
|
||||
.comment(R.string.invalidinput);
|
||||
} else if (detailedBolusInfo.insulin > 0) {
|
||||
// bolus needed, ask pump to deliver it
|
||||
return deliverBolus(detailedBolusInfo);
|
||||
|
@ -426,7 +426,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
|||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: Carb only treatment.");
|
||||
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true).bolusDelivered(0d)
|
||||
.carbsDelivered(detailedBolusInfo.carbs).comment(getResourceHelper().gs(R.string.common_resultok));
|
||||
.carbsDelivered(detailedBolusInfo.carbs).comment(R.string.common_resultok);
|
||||
}
|
||||
} finally {
|
||||
triggerUIChange();
|
||||
|
@ -471,6 +471,6 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
|||
protected abstract void triggerUIChange();
|
||||
|
||||
private PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(resourceId));
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(resourceId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ class PumpEnactResultTest : TestBaseWithProfile() {
|
|||
val injector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is PumpEnactResult) {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.resourceHelper = resourceHelper
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,24 +169,21 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
|
||||
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t);
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep;
|
||||
result.bolusDelivered = t.insulin;
|
||||
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||
if (!result.success)
|
||||
result.comment = resourceHelper.gs(R.string.boluserrorcode, detailedBolusInfo.insulin, t.insulin, danaPump.getBolusStartErrorCode());
|
||||
result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep)
|
||||
.bolusDelivered(t.insulin)
|
||||
.carbsDelivered(detailedBolusInfo.carbs);
|
||||
if (!result.getSuccess())
|
||||
result.comment(resourceHelper.gs(R.string.boluserrorcode, detailedBolusInfo.insulin, t.insulin, danaPump.getBolusStartErrorCode()));
|
||||
else
|
||||
result.comment = resourceHelper.gs(R.string.ok);
|
||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
||||
result.comment(R.string.ok);
|
||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.getBolusDelivered());
|
||||
detailedBolusInfo.insulin = t.insulin;
|
||||
detailedBolusInfo.date = System.currentTimeMillis();
|
||||
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false);
|
||||
return result;
|
||||
} else {
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = false;
|
||||
result.bolusDelivered = 0d;
|
||||
result.carbsDelivered = 0d;
|
||||
result.comment = resourceHelper.gs(R.string.invalidinput);
|
||||
result.success(false).bolusDelivered(0d).carbsDelivered(0d).comment(R.string.invalidinput);
|
||||
aapsLogger.error("deliverTreatment: Invalid input");
|
||||
return result;
|
||||
}
|
||||
|
@ -221,11 +218,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping temp basal (doTempOff)");
|
||||
return cancelRealTempBasal();
|
||||
}
|
||||
result.success = true;
|
||||
result.enacted = false;
|
||||
result.percent = 100;
|
||||
result.isPercent = true;
|
||||
result.isTempCancel = true;
|
||||
result.success(true).enacted(false).percent(100).isPercent(true).isTempCancel(true);
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: doTempOff OK");
|
||||
return result;
|
||||
}
|
||||
|
@ -245,7 +238,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
if (activeExtended != null && useExtendedBoluses) {
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)");
|
||||
result = cancelExtendedBolus();
|
||||
if (!result.success) {
|
||||
if (!result.getSuccess()) {
|
||||
aapsLogger.error("setTempBasalAbsolute: Failed to stop previous extended bolus (doLowTemp || doHighTemp)");
|
||||
return result;
|
||||
}
|
||||
|
@ -258,12 +251,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
if (enforceNew) {
|
||||
cancelTempBasal(true);
|
||||
} else {
|
||||
result.success = true;
|
||||
result.percent = percentRate;
|
||||
result.enacted = false;
|
||||
result.duration = activeTemp.getPlannedRemainingMinutes();
|
||||
result.isPercent = true;
|
||||
result.isTempCancel = false;
|
||||
result.success(true).percent(percentRate).enacted(false).duration(activeTemp.getPlannedRemainingMinutes()).isPercent(true).isTempCancel(false);
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Correct temp basal already set (doLowTemp || doHighTemp)");
|
||||
return result;
|
||||
}
|
||||
|
@ -279,7 +267,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)");
|
||||
result = cancelRealTempBasal();
|
||||
// Check for proper result
|
||||
if (!result.success) {
|
||||
if (!result.getSuccess()) {
|
||||
aapsLogger.error("setTempBasalAbsolute: Failed to stop previous temp basal (doExtendedTemp)");
|
||||
return result;
|
||||
}
|
||||
|
@ -300,12 +288,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
// Compare with extended rate in progress
|
||||
if (activeExtended != null && Math.abs(danaPump.getExtendedBolusAbsoluteRate() - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
|
||||
// correct extended already set
|
||||
result.success = true;
|
||||
result.absolute = danaPump.getExtendedBolusAbsoluteRate();
|
||||
result.enacted = false;
|
||||
result.duration = danaPump.getExtendedBolusRemainingMinutes();
|
||||
result.isPercent = false;
|
||||
result.isTempCancel = false;
|
||||
result.success(true).absolute(danaPump.getExtendedBolusAbsoluteRate()).enacted(false).duration(danaPump.getExtendedBolusRemainingMinutes()).isPercent(false).isTempCancel(false);
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Correct extended already set");
|
||||
return result;
|
||||
}
|
||||
|
@ -314,18 +297,17 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
double extendedAmount = extendedRateToSet / 2 * durationInHalfHours;
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Setting extended: " + extendedAmount + "U half hours: " + durationInHalfHours);
|
||||
result = setExtendedBolus(extendedAmount, durationInMinutes);
|
||||
if (!result.success) {
|
||||
if (!result.getSuccess()) {
|
||||
aapsLogger.error("setTempBasalAbsolute: Failed to set extended bolus");
|
||||
return result;
|
||||
}
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus set ok");
|
||||
result.absolute = result.absolute + getBaseBasalRate();
|
||||
result.absolute(result.getAbsolute() + getBaseBasalRate());
|
||||
return result;
|
||||
}
|
||||
// We should never end here
|
||||
aapsLogger.error("setTempBasalAbsolute: Internal error");
|
||||
result.success = false;
|
||||
result.comment = "Internal error";
|
||||
result.success(false).comment("Internal error");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -337,10 +319,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
return cancelExtendedBolus();
|
||||
}
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = true;
|
||||
result.enacted = false;
|
||||
result.comment = resourceHelper.gs(R.string.ok);
|
||||
result.isTempCancel = true;
|
||||
result.success(true).enacted(false).comment(R.string.ok).isTempCancel(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -354,18 +333,13 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
TemporaryBasal runningTB = activePlugin.getActiveTreatments().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (runningTB != null) {
|
||||
sExecutionService.tempBasalStop();
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
result.enacted(true).isTempCancel(true);
|
||||
}
|
||||
if (!danaPump.isTempBasalInProgress()) {
|
||||
result.success = true;
|
||||
result.isTempCancel = true;
|
||||
result.comment = resourceHelper.gs(R.string.ok);
|
||||
result.success(true).isTempCancel(true).comment(R.string.ok);
|
||||
aapsLogger.debug(LTag.PUMP, "cancelRealTempBasal: OK");
|
||||
} else {
|
||||
result.success = false;
|
||||
result.comment = resourceHelper.gs(R.string.danar_valuenotsetproperly);
|
||||
result.isTempCancel = true;
|
||||
result.success(false).comment(R.string.danar_valuenotsetproperly).isTempCancel(true);
|
||||
aapsLogger.error("cancelRealTempBasal: Failed to cancel temp basal");
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -188,22 +188,19 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
if (detailedBolusInfo.insulin > 0 || carbs > 0)
|
||||
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) carbs, DateUtil.now() + T.mins(carbTime).msecs(), t);
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep;
|
||||
result.bolusDelivered = t.insulin;
|
||||
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||
if (!result.success)
|
||||
result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, danaPump.getBolusStartErrorCode());
|
||||
result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep)
|
||||
.bolusDelivered(t.insulin)
|
||||
.carbsDelivered(detailedBolusInfo.carbs);
|
||||
if (!result.getSuccess())
|
||||
result.comment(resourceHelper.gs(R.string.boluserrorcode, detailedBolusInfo.insulin, t.insulin, danaPump.getBolusStartErrorCode()));
|
||||
else
|
||||
result.comment = resourceHelper.gs(R.string.ok);
|
||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
||||
result.comment(R.string.ok);
|
||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.getBolusDelivered());
|
||||
// remove carbs because it's get from history separately
|
||||
return result;
|
||||
} else {
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = false;
|
||||
result.bolusDelivered = 0d;
|
||||
result.carbsDelivered = 0d;
|
||||
result.comment = resourceHelper.gs(R.string.invalidinput);
|
||||
result.success(false).bolusDelivered(0d).carbsDelivered(0d).comment(R.string.invalidinput);
|
||||
aapsLogger.error("deliverTreatment: Invalid input");
|
||||
return result;
|
||||
}
|
||||
|
@ -241,18 +238,14 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping temp basal (doTempOff)");
|
||||
return cancelTempBasal(false);
|
||||
}
|
||||
result.success = true;
|
||||
result.enacted = false;
|
||||
result.percent = 100;
|
||||
result.isPercent = true;
|
||||
result.isTempCancel = true;
|
||||
result.success(true).enacted(false).percent(100).isPercent(true).isTempCancel(true);
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: doTempOff OK");
|
||||
return result;
|
||||
}
|
||||
|
||||
if (doLowTemp || doHighTemp) {
|
||||
int percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
|
||||
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 mins. So if it's less than .10u/h, set a zero temp.
|
||||
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp.
|
||||
if (absoluteRate < 0.10d) percentRate = 0;
|
||||
if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue();
|
||||
else percentRate = Round.floorTo((double) percentRate, 10d).intValue();
|
||||
|
@ -264,26 +257,21 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
// Correct basal already set ?
|
||||
if (activeTemp.percentRate == percentRate && activeTemp.getPlannedRemainingMinutes() > 4) {
|
||||
if (!enforceNew) {
|
||||
result.success = true;
|
||||
result.percent = percentRate;
|
||||
result.enacted = false;
|
||||
result.duration = activeTemp.getPlannedRemainingMinutes();
|
||||
result.isPercent = true;
|
||||
result.isTempCancel = false;
|
||||
result.success(true).percent(percentRate).enacted(false).duration(activeTemp.getPlannedRemainingMinutes()).isPercent(true).isTempCancel(false);
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Correct temp basal already set (doLowTemp || doHighTemp)");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Convert duration from minutes to hours
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)");
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " minutes (doLowTemp || doHighTemp)");
|
||||
if (percentRate == 0 && durationInMinutes > 30) {
|
||||
result = setTempBasalPercent(percentRate, durationInMinutes, profile, enforceNew);
|
||||
} else {
|
||||
// use special APS temp basal call ... 100+/15min .... 100-/30min
|
||||
result = setHighTempBasalPercent(percentRate, durationInMinutes);
|
||||
}
|
||||
if (!result.success) {
|
||||
if (!result.getSuccess()) {
|
||||
aapsLogger.error("setTempBasalAbsolute: Failed to set high temp basal");
|
||||
return result;
|
||||
}
|
||||
|
@ -292,8 +280,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
}
|
||||
// We should never end here
|
||||
aapsLogger.error("setTempBasalAbsolute: Internal error");
|
||||
result.success = false;
|
||||
result.comment = "Internal error";
|
||||
result.success(false).comment("Internal error");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -303,10 +290,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
|
||||
if (percent < 0) {
|
||||
result.isTempCancel = false;
|
||||
result.enacted = false;
|
||||
result.success = false;
|
||||
result.comment = resourceHelper.gs(R.string.invalidinput);
|
||||
result.isTempCancel(false).enacted(false).success(false).comment(R.string.invalidinput);
|
||||
aapsLogger.error("setTempBasalPercent: Invalid input");
|
||||
return result;
|
||||
}
|
||||
|
@ -315,13 +299,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
long now = System.currentTimeMillis();
|
||||
TemporaryBasal activeTemp = activePlugin.getActiveTreatments().getRealTempBasalFromHistory(now);
|
||||
if (activeTemp != null && activeTemp.percentRate == percent && activeTemp.getPlannedRemainingMinutes() > 4 && !enforceNew) {
|
||||
result.enacted = false;
|
||||
result.success = true;
|
||||
result.isTempCancel = false;
|
||||
result.comment = resourceHelper.gs(R.string.ok);
|
||||
result.duration = pump.getTempBasalRemainingMin();
|
||||
result.percent = pump.getTempBasalPercent();
|
||||
result.isPercent = true;
|
||||
result.enacted(false).success(true).isTempCancel(false).comment(R.string.ok).duration(pump.getTempBasalRemainingMin()).percent(pump.getTempBasalPercent()).isPercent(true);
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalPercent: Correct value already set");
|
||||
return result;
|
||||
}
|
||||
|
@ -333,19 +311,11 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
connectionOK = sExecutionService.tempBasal(percent, durationInHours);
|
||||
}
|
||||
if (connectionOK && pump.isTempBasalInProgress() && pump.getTempBasalPercent() == percent) {
|
||||
result.enacted = true;
|
||||
result.success = true;
|
||||
result.comment = resourceHelper.gs(R.string.ok);
|
||||
result.isTempCancel = false;
|
||||
result.duration = pump.getTempBasalRemainingMin();
|
||||
result.percent = pump.getTempBasalPercent();
|
||||
result.isPercent = true;
|
||||
result.enacted(true).success(true).comment(R.string.ok).isTempCancel(false).duration(pump.getTempBasalRemainingMin()).percent(pump.getTempBasalPercent()).isPercent(true);
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalPercent: OK");
|
||||
return result;
|
||||
}
|
||||
result.enacted = false;
|
||||
result.success = false;
|
||||
result.comment = resourceHelper.gs(R.string.tempbasaldeliveryerror);
|
||||
result.enacted(false).success(false).comment(R.string.tempbasaldeliveryerror);
|
||||
aapsLogger.error("setTempBasalPercent: Failed to set temp basal");
|
||||
return result;
|
||||
}
|
||||
|
@ -355,19 +325,11 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
boolean connectionOK = sExecutionService.highTempBasal(percent, durationInMinutes);
|
||||
if (connectionOK && pump.isTempBasalInProgress() && pump.getTempBasalPercent() == percent) {
|
||||
result.enacted = true;
|
||||
result.success = true;
|
||||
result.comment = resourceHelper.gs(R.string.ok);
|
||||
result.isTempCancel = false;
|
||||
result.duration = pump.getTempBasalRemainingMin();
|
||||
result.percent = pump.getTempBasalPercent();
|
||||
result.isPercent = true;
|
||||
result.enacted(true).success(true).comment(R.string.ok).isTempCancel(false).duration(pump.getTempBasalRemainingMin()).percent(pump.getTempBasalPercent()).isPercent(true);
|
||||
aapsLogger.debug(LTag.PUMP, "setHighTempBasalPercent: OK");
|
||||
return result;
|
||||
}
|
||||
result.enacted = false;
|
||||
result.success = false;
|
||||
result.comment = resourceHelper.gs(R.string.danar_valuenotsetproperly);
|
||||
result.enacted(false).success(false).comment(R.string.danar_valuenotsetproperly);
|
||||
aapsLogger.error("setHighTempBasalPercent: Failed to set temp basal");
|
||||
return result;
|
||||
}
|
||||
|
@ -378,18 +340,13 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
TemporaryBasal runningTB = activePlugin.getActiveTreatments().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (runningTB != null) {
|
||||
sExecutionService.tempBasalStop();
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
result.enacted(true).isTempCancel(true);
|
||||
}
|
||||
if (!danaPump.isTempBasalInProgress()) {
|
||||
result.success = true;
|
||||
result.isTempCancel = true;
|
||||
result.comment = resourceHelper.gs(R.string.ok);
|
||||
result.success(true).isTempCancel(true).comment(R.string.ok);
|
||||
aapsLogger.debug(LTag.PUMP, "cancelRealTempBasal: OK");
|
||||
} else {
|
||||
result.success = false;
|
||||
result.comment = resourceHelper.gs(R.string.danar_valuenotsetproperly);
|
||||
result.isTempCancel = true;
|
||||
result.success(false).comment(R.string.danar_valuenotsetproperly).isTempCancel(true);
|
||||
aapsLogger.error("cancelRealTempBasal: Failed to cancel temp basal");
|
||||
}
|
||||
return result;
|
||||
|
@ -400,12 +357,12 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
return PumpType.DanaRv2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull @Override
|
||||
public PumpEnactResult loadEvents() {
|
||||
return sExecutionService.loadEvents();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull @Override
|
||||
public PumpEnactResult setUserOptions() {
|
||||
return sExecutionService.setUserOptions();
|
||||
}
|
||||
|
|
|
@ -434,7 +434,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
public PumpEnactResult loadEvents() {
|
||||
if (!danaRv2Plugin.isInitialized()) {
|
||||
PumpEnactResult result = new PumpEnactResult(injector).success(false);
|
||||
result.comment = "pump not initialized";
|
||||
result.comment("pump not initialized");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.danar;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
@ -140,14 +139,14 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
|
|||
|
||||
if (sExecutionService == null) {
|
||||
getAapsLogger().error("setNewBasalProfile sExecutionService is null");
|
||||
result.comment = "setNewBasalProfile sExecutionService is null";
|
||||
result.comment("setNewBasalProfile sExecutionService is null");
|
||||
return result;
|
||||
}
|
||||
if (!isInitialized()) {
|
||||
getAapsLogger().error("setNewBasalProfile not initialized");
|
||||
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, getResourceHelper().gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
||||
rxBus.send(new EventNewNotification(notification));
|
||||
result.comment = getResourceHelper().gs(R.string.pumpNotInitializedProfileNotSet);
|
||||
result.comment(R.string.pumpNotInitializedProfileNotSet);
|
||||
return result;
|
||||
} else {
|
||||
rxBus.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
|
@ -155,15 +154,13 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
|
|||
if (!sExecutionService.updateBasalsInPump(profile)) {
|
||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, getResourceHelper().gs(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||
rxBus.send(new EventNewNotification(notification));
|
||||
result.comment = getResourceHelper().gs(R.string.failedupdatebasalprofile);
|
||||
result.comment(R.string.failedupdatebasalprofile);
|
||||
} else {
|
||||
rxBus.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
rxBus.send(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
Notification notification = new Notification(Notification.PROFILE_SET_OK, getResourceHelper().gs(R.string.profile_set_ok), Notification.INFO, 60);
|
||||
rxBus.send(new EventNewNotification(notification));
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.comment = "OK";
|
||||
result.success(true).enacted(true).comment("OK");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -222,10 +219,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
|
|||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
|
||||
if (percent < 0) {
|
||||
result.isTempCancel = false;
|
||||
result.enacted = false;
|
||||
result.success = false;
|
||||
result.comment = getResourceHelper().gs(R.string.invalidinput);
|
||||
result.isTempCancel(false).enacted(false).success(false).comment(R.string.invalidinput);
|
||||
getAapsLogger().error("setTempBasalPercent: Invalid input");
|
||||
return result;
|
||||
}
|
||||
|
@ -234,32 +228,28 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
|
|||
long now = System.currentTimeMillis();
|
||||
TemporaryBasal activeTemp = activePlugin.getActiveTreatments().getRealTempBasalFromHistory(now);
|
||||
if (activeTemp != null && activeTemp.percentRate == percent && activeTemp.getPlannedRemainingMinutes() > 4 && !enforceNew) {
|
||||
result.enacted = false;
|
||||
result.success = true;
|
||||
result.isTempCancel = false;
|
||||
result.comment = getResourceHelper().gs(R.string.ok);
|
||||
result.duration = pump.getTempBasalRemainingMin();
|
||||
result.percent = pump.getTempBasalPercent();
|
||||
result.isPercent = true;
|
||||
result.enacted(false).success(true).isTempCancel(false)
|
||||
.comment(R.string.ok)
|
||||
.duration(pump.getTempBasalRemainingMin())
|
||||
.percent(pump.getTempBasalPercent())
|
||||
.isPercent(true);
|
||||
getAapsLogger().debug(LTag.PUMP, "setTempBasalPercent: Correct value already set");
|
||||
return result;
|
||||
}
|
||||
int durationInHours = Math.max(durationInMinutes / 60, 1);
|
||||
boolean connectionOK = sExecutionService.tempBasal(percent, durationInHours);
|
||||
if (connectionOK && pump.isTempBasalInProgress() && pump.getTempBasalPercent() == percent) {
|
||||
result.enacted = true;
|
||||
result.success = true;
|
||||
result.comment = getResourceHelper().gs(R.string.ok);
|
||||
result.isTempCancel = false;
|
||||
result.duration = pump.getTempBasalRemainingMin();
|
||||
result.percent = pump.getTempBasalPercent();
|
||||
result.isPercent = true;
|
||||
result.enacted(true)
|
||||
.success(true)
|
||||
.comment(R.string.ok)
|
||||
.isTempCancel(false)
|
||||
.duration(pump.getTempBasalRemainingMin())
|
||||
.percent(pump.getTempBasalPercent())
|
||||
.isPercent(true);
|
||||
getAapsLogger().debug(LTag.PUMP, "setTempBasalPercent: OK");
|
||||
return result;
|
||||
}
|
||||
result.enacted = false;
|
||||
result.success = false;
|
||||
result.comment = getResourceHelper().gs(R.string.tempbasaldeliveryerror);
|
||||
result.enacted(false).success(false).comment(R.string.tempbasaldeliveryerror);
|
||||
getAapsLogger().error("setTempBasalPercent: Failed to set temp basal");
|
||||
return result;
|
||||
}
|
||||
|
@ -275,33 +265,31 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
|
|||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
ExtendedBolus runningEB = activePlugin.getActiveTreatments().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) {
|
||||
result.enacted = false;
|
||||
result.success = true;
|
||||
result.comment = getResourceHelper().gs(R.string.ok);
|
||||
result.duration = pump.getExtendedBolusRemainingMinutes();
|
||||
result.absolute = pump.getExtendedBolusAbsoluteRate();
|
||||
result.isPercent = false;
|
||||
result.isTempCancel = false;
|
||||
result.enacted(false)
|
||||
.success(true)
|
||||
.comment(R.string.ok)
|
||||
.duration(pump.getExtendedBolusRemainingMinutes())
|
||||
.absolute(pump.getExtendedBolusAbsoluteRate())
|
||||
.isPercent(false)
|
||||
.isTempCancel(false);
|
||||
getAapsLogger().debug(LTag.PUMP, "setExtendedBolus: Correct extended bolus already set. Current: " + pump.getExtendedBolusAmount() + " Asked: " + insulin);
|
||||
return result;
|
||||
}
|
||||
boolean connectionOK = sExecutionService.extendedBolus(insulin, durationInHalfHours);
|
||||
if (connectionOK && pump.isExtendedInProgress() && Math.abs(pump.getExtendedBolusAmount() - insulin) < getPumpDescription().extendedBolusStep) {
|
||||
result.enacted = true;
|
||||
result.success = true;
|
||||
result.comment = getResourceHelper().gs(R.string.ok);
|
||||
result.isTempCancel = false;
|
||||
result.duration = pump.getExtendedBolusRemainingMinutes();
|
||||
result.absolute = pump.getExtendedBolusAbsoluteRate();
|
||||
result.enacted(true)
|
||||
.success(true)
|
||||
.comment(R.string.ok)
|
||||
.isTempCancel(false)
|
||||
.duration(pump.getExtendedBolusRemainingMinutes())
|
||||
.absolute(pump.getExtendedBolusAbsoluteRate())
|
||||
.isPercent(false);
|
||||
if (!sp.getBoolean("danar_useextended", false))
|
||||
result.bolusDelivered = pump.getExtendedBolusAmount();
|
||||
result.isPercent = false;
|
||||
result.bolusDelivered(pump.getExtendedBolusAmount());
|
||||
getAapsLogger().debug(LTag.PUMP, "setExtendedBolus: OK");
|
||||
return result;
|
||||
}
|
||||
result.enacted = false;
|
||||
result.success = false;
|
||||
result.comment = getResourceHelper().gs(R.string.danar_valuenotsetproperly);
|
||||
result.enacted(false).success(false).comment(R.string.danar_valuenotsetproperly);
|
||||
getAapsLogger().error("setExtendedBolus: Failed to extended bolus");
|
||||
return result;
|
||||
}
|
||||
|
@ -312,16 +300,13 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
|
|||
ExtendedBolus runningEB = activePlugin.getActiveTreatments().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
if (runningEB != null) {
|
||||
sExecutionService.extendedBolusStop();
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
result.enacted(true).isTempCancel(true);
|
||||
}
|
||||
if (!danaPump.isExtendedInProgress()) {
|
||||
result.success = true;
|
||||
result.comment = getResourceHelper().gs(R.string.ok);
|
||||
result.success(true).comment(R.string.ok);
|
||||
getAapsLogger().debug(LTag.PUMP, "cancelExtendedBolus: OK");
|
||||
} else {
|
||||
result.success = false;
|
||||
result.comment = getResourceHelper().gs(R.string.danar_valuenotsetproperly);
|
||||
result.success(false).comment(R.string.danar_valuenotsetproperly);
|
||||
getAapsLogger().error("cancelExtendedBolus: Failed to cancel extended bolus");
|
||||
}
|
||||
return result;
|
||||
|
@ -433,7 +418,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
|
|||
* DanaR interface
|
||||
*/
|
||||
|
||||
@Override
|
||||
@NonNull @Override
|
||||
public PumpEnactResult loadHistory(byte type) {
|
||||
return sExecutionService.loadHistory(type);
|
||||
}
|
||||
|
@ -477,8 +462,8 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
|
|||
DanaPump pump = danaPump;
|
||||
String ret = "";
|
||||
if (pump.getLastConnection() != 0) {
|
||||
long agoMsec = System.currentTimeMillis() - pump.getLastConnection();
|
||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||
long agoMilliseconds = System.currentTimeMillis() - pump.getLastConnection();
|
||||
int agoMin = (int) (agoMilliseconds / 60d / 1000d);
|
||||
ret += "LastConn: " + agoMin + " min ago\n";
|
||||
}
|
||||
if (pump.getLastBolusTime() != 0) {
|
||||
|
|
|
@ -167,24 +167,21 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
|
||||
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t);
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep;
|
||||
result.bolusDelivered = t.insulin;
|
||||
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||
if (!result.success)
|
||||
result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, danaPump.getBolusStartErrorCode());
|
||||
result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep)
|
||||
.bolusDelivered(t.insulin)
|
||||
.carbsDelivered(detailedBolusInfo.carbs);
|
||||
if (!result.getSuccess())
|
||||
result.comment(resourceHelper.gs(R.string.boluserrorcode, detailedBolusInfo.insulin, t.insulin, danaPump.getBolusStartErrorCode()));
|
||||
else
|
||||
result.comment = resourceHelper.gs(R.string.ok);
|
||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
||||
result.comment(R.string.ok);
|
||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.getBolusDelivered());
|
||||
detailedBolusInfo.insulin = t.insulin;
|
||||
detailedBolusInfo.date = System.currentTimeMillis();
|
||||
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false);
|
||||
return result;
|
||||
} else {
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = false;
|
||||
result.bolusDelivered = 0d;
|
||||
result.carbsDelivered = 0d;
|
||||
result.comment = resourceHelper.gs(R.string.invalidinput);
|
||||
result.success(false).bolusDelivered(0d).carbsDelivered(0d).comment(R.string.invalidinput);
|
||||
aapsLogger.error("deliverTreatment: Invalid input");
|
||||
return result;
|
||||
}
|
||||
|
@ -219,11 +216,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping temp basal (doTempOff)");
|
||||
return cancelRealTempBasal();
|
||||
}
|
||||
result.success = true;
|
||||
result.enacted = false;
|
||||
result.percent = 100;
|
||||
result.isPercent = true;
|
||||
result.isTempCancel = true;
|
||||
result.success(true).enacted(false).percent(100).isPercent(true).isTempCancel(true);
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: doTempOff OK");
|
||||
return result;
|
||||
}
|
||||
|
@ -243,7 +236,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
if (activeExtended != null && useExtendedBoluses) {
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)");
|
||||
result = cancelExtendedBolus();
|
||||
if (!result.success) {
|
||||
if (!result.getSuccess()) {
|
||||
aapsLogger.error("setTempBasalAbsolute: Failed to stop previous extended bolus (doLowTemp || doHighTemp)");
|
||||
return result;
|
||||
}
|
||||
|
@ -256,12 +249,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
if (enforceNew) {
|
||||
cancelTempBasal(true);
|
||||
} else {
|
||||
result.success = true;
|
||||
result.percent = percentRate;
|
||||
result.enacted = false;
|
||||
result.duration = activeTemp.getPlannedRemainingMinutes();
|
||||
result.isPercent = true;
|
||||
result.isTempCancel = false;
|
||||
result.success(true).percent(percentRate).enacted(false).duration(activeTemp.getPlannedRemainingMinutes()).isPercent(true).isTempCancel(false);
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Correct temp basal already set (doLowTemp || doHighTemp)");
|
||||
return result;
|
||||
}
|
||||
|
@ -277,7 +265,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)");
|
||||
result = cancelRealTempBasal();
|
||||
// Check for proper result
|
||||
if (!result.success) {
|
||||
if (!result.getSuccess()) {
|
||||
aapsLogger.error("setTempBasalAbsolute: Failed to stop previous temp basal (doExtendedTemp)");
|
||||
return result;
|
||||
}
|
||||
|
@ -298,12 +286,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
// Compare with extended rate in progress
|
||||
if (activeExtended != null && Math.abs(danaPump.getExtendedBolusAbsoluteRate() - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
|
||||
// correct extended already set
|
||||
result.success = true;
|
||||
result.absolute = danaPump.getExtendedBolusAbsoluteRate();
|
||||
result.enacted = false;
|
||||
result.duration = danaPump.getExtendedBolusRemainingMinutes();
|
||||
result.isPercent = false;
|
||||
result.isTempCancel = false;
|
||||
result.success(true).absolute(danaPump.getExtendedBolusAbsoluteRate()).enacted(false).duration(danaPump.getExtendedBolusRemainingMinutes()).isPercent(false).isTempCancel(false);
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Correct extended already set");
|
||||
return result;
|
||||
}
|
||||
|
@ -312,18 +295,17 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
double extendedAmount = extendedRateToSet / 2 * durationInHalfHours;
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Setting extended: " + extendedAmount + "U half hours: " + durationInHalfHours);
|
||||
result = setExtendedBolus(extendedAmount, durationInMinutes);
|
||||
if (!result.success) {
|
||||
if (!result.getSuccess()) {
|
||||
aapsLogger.error("setTempBasalAbsolute: Failed to set extended bolus");
|
||||
return result;
|
||||
}
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus set ok");
|
||||
result.absolute = result.absolute + getBaseBasalRate();
|
||||
result.absolute(result.getAbsolute() + getBaseBasalRate());
|
||||
return result;
|
||||
}
|
||||
// We should never end here
|
||||
aapsLogger.error("setTempBasalAbsolute: Internal error");
|
||||
result.success = false;
|
||||
result.comment = "Internal error";
|
||||
result.success(false).comment("Internal error");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -335,10 +317,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
return cancelExtendedBolus();
|
||||
}
|
||||
PumpEnactResult result = new PumpEnactResult(getInjector());
|
||||
result.success = true;
|
||||
result.enacted = false;
|
||||
result.comment = resourceHelper.gs(R.string.ok);
|
||||
result.isTempCancel = true;
|
||||
result.success(true).enacted(false).comment(R.string.ok).isTempCancel(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -352,18 +331,13 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
TemporaryBasal runningTB = activePlugin.getActiveTreatments().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (runningTB != null) {
|
||||
sExecutionService.tempBasalStop();
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
result.enacted(true).isTempCancel(true);
|
||||
}
|
||||
if (!danaPump.isTempBasalInProgress()) {
|
||||
result.success = true;
|
||||
result.isTempCancel = true;
|
||||
result.comment = resourceHelper.gs(R.string.ok);
|
||||
result.success(true).isTempCancel(true).comment(R.string.ok);
|
||||
aapsLogger.debug(LTag.PUMP, "cancelRealTempBasal: OK");
|
||||
} else {
|
||||
result.success = false;
|
||||
result.comment = resourceHelper.gs(R.string.danar_valuenotsetproperly);
|
||||
result.isTempCancel = true;
|
||||
result.success(false).comment(R.string.danar_valuenotsetproperly).isTempCancel(true);
|
||||
aapsLogger.error("cancelRealTempBasal: Failed to cancel temp basal");
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -267,8 +267,7 @@ public abstract class AbstractDanaRExecutionService extends DaggerService {
|
|||
}
|
||||
SystemClock.sleep(200);
|
||||
mSerialIOThread.sendMessage(new MsgPCCommStop(injector));
|
||||
result.success = true;
|
||||
result.comment = "OK";
|
||||
result.success(true).comment("OK");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.content.ServiceConnection;
|
|||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
@ -342,13 +343,13 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void connect(String reason) {
|
||||
public void connect(@NonNull String reason) {
|
||||
if (connectionService != null && alertService != null)
|
||||
connectionService.requestConnection(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(String reason) {
|
||||
public void disconnect(@NonNull String reason) {
|
||||
if (connectionService != null && alertService != null)
|
||||
connectionService.withdrawConnectionRequest(this);
|
||||
}
|
||||
|
@ -360,7 +361,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void getPumpStatus(String reason) {
|
||||
public void getPumpStatus(@NonNull String reason) {
|
||||
try {
|
||||
tbrOverNotificationBlock = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, TBROverNotificationBlock.class);
|
||||
readHistory();
|
||||
|
@ -507,9 +508,9 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
rxBus.send(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
Notification notification = new Notification(Notification.PROFILE_SET_OK, resourceHelper.gs(R.string.profile_set_ok), Notification.INFO, 60);
|
||||
rxBus.send(new EventNewNotification(notification));
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
|
||||
result.success(true)
|
||||
.enacted(true)
|
||||
.comment(R.string.virtualpump_resultok);
|
||||
this.profileBlocks = profileBlocks;
|
||||
try {
|
||||
fetchStatus();
|
||||
|
@ -519,23 +520,23 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
aapsLogger.info(LTag.PUMP, "Exception while setting profile: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, resourceHelper.gs(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||
rxBus.send(new EventNewNotification(notification));
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (InsightException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while setting profile: " + e.getClass().getCanonicalName());
|
||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, resourceHelper.gs(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||
rxBus.send(new EventNewNotification(notification));
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (Exception e) {
|
||||
aapsLogger.error("Exception while setting profile", e);
|
||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, resourceHelper.gs(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||
rxBus.send(new EventNewNotification(notification));
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isThisProfileSet(Profile profile) {
|
||||
public boolean isThisProfileSet(@NonNull Profile profile) {
|
||||
if (!isInitialized() || profileBlocks == null) return true;
|
||||
if (profile.getBasalValues().length != profileBlocks.size()) return false;
|
||||
if (activeBasalProfile != BasalProfile.PROFILE_1) return false;
|
||||
|
@ -594,8 +595,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
|
||||
bolusCancelled = false;
|
||||
}
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.success(true).enacted(true);
|
||||
Treatment t = new Treatment();
|
||||
t.isSMB = detailedBolusInfo.isSMB;
|
||||
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||
|
@ -655,26 +655,24 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
}
|
||||
}
|
||||
}
|
||||
Thread.sleep(200);
|
||||
SystemClock.sleep(200);
|
||||
}
|
||||
readHistory();
|
||||
fetchStatus();
|
||||
} catch (AppLayerErrorException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while delivering bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (InsightException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while delivering bolus: " + e.getClass().getCanonicalName());
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (Exception e) {
|
||||
aapsLogger.error("Exception while delivering bolus", e);
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
}
|
||||
} else if (detailedBolusInfo.carbs > 0) {
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.success(true).enacted(true);
|
||||
}
|
||||
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||
result.bolusDelivered = insulin;
|
||||
result.carbsDelivered(detailedBolusInfo.carbs).bolusDelivered(insulin);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -709,31 +707,31 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
double percent = 100D / activeBasalRate.getActiveBasalRate() * absoluteRate;
|
||||
if (isFakingTempsByExtendedBoluses()) {
|
||||
PumpEnactResult cancelEBResult = cancelExtendedBolusOnly();
|
||||
if (cancelEBResult.success) {
|
||||
if (cancelEBResult.getSuccess()) {
|
||||
if (percent > 250) {
|
||||
PumpEnactResult cancelTBRResult = cancelTempBasalOnly();
|
||||
if (cancelTBRResult.success) {
|
||||
if (cancelTBRResult.getSuccess()) {
|
||||
PumpEnactResult ebResult = setExtendedBolusOnly((absoluteRate - getBaseBasalRate()) / 60D
|
||||
* ((double) durationInMinutes), durationInMinutes,
|
||||
sp.getBoolean(R.string.key_disable_vibration_auto, false));
|
||||
if (ebResult.success) {
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.isPercent = false;
|
||||
result.absolute = absoluteRate;
|
||||
result.duration = durationInMinutes;
|
||||
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
|
||||
if (ebResult.getSuccess()) {
|
||||
result.success(true)
|
||||
.enacted(true)
|
||||
.isPercent(false)
|
||||
.absolute(absoluteRate)
|
||||
.duration(durationInMinutes)
|
||||
.comment(R.string.virtualpump_resultok);
|
||||
} else {
|
||||
result.comment = ebResult.comment;
|
||||
result.comment(ebResult.getComment());
|
||||
}
|
||||
} else {
|
||||
result.comment = cancelTBRResult.comment;
|
||||
result.comment(cancelTBRResult.getComment());
|
||||
}
|
||||
} else {
|
||||
return setTempBasalPercent((int) Math.round(percent), durationInMinutes, profile, enforceNew);
|
||||
}
|
||||
} else {
|
||||
result.comment = cancelEBResult.comment;
|
||||
result.comment(cancelEBResult.getComment());
|
||||
}
|
||||
} else {
|
||||
return setTempBasalPercent((int) Math.round(percent), durationInMinutes, profile, enforceNew);
|
||||
|
@ -769,23 +767,23 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
message.setPercentage(percent);
|
||||
connectionService.requestMessage(message);
|
||||
}
|
||||
result.isPercent = true;
|
||||
result.percent = percent;
|
||||
result.duration = durationInMinutes;
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
|
||||
result.isPercent(true)
|
||||
.percent(percent)
|
||||
.duration(durationInMinutes)
|
||||
.success(true)
|
||||
.enacted(true)
|
||||
.comment(R.string.virtualpump_resultok);
|
||||
readHistory();
|
||||
fetchStatus();
|
||||
} catch (AppLayerErrorException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while setting TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (InsightException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while setting TBR: " + e.getClass().getCanonicalName());
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (Exception e) {
|
||||
aapsLogger.error("Exception while setting TBR", e);
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -793,7 +791,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
@NonNull @Override
|
||||
public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) {
|
||||
PumpEnactResult result = cancelExtendedBolusOnly();
|
||||
if (result.success)
|
||||
if (result.getSuccess())
|
||||
result = setExtendedBolusOnly(insulin, durationInMinutes, sp.getBoolean(R.string.key_disable_vibration, false));
|
||||
try {
|
||||
fetchStatus();
|
||||
|
@ -830,18 +828,16 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
extendedBolus.insulin = insulin;
|
||||
extendedBolus.pumpId = insightBolusID.id;
|
||||
treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus);
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
|
||||
result.success(true).enacted(true).comment(R.string.virtualpump_resultok);
|
||||
} catch (AppLayerErrorException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while delivering extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (InsightException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while delivering extended bolus: " + e.getClass().getCanonicalName());
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (Exception e) {
|
||||
aapsLogger.error("Exception while delivering extended bolus", e);
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -852,9 +848,9 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
PumpEnactResult cancelEBResult = null;
|
||||
if (isFakingTempsByExtendedBoluses()) cancelEBResult = cancelExtendedBolusOnly();
|
||||
PumpEnactResult cancelTBRResult = cancelTempBasalOnly();
|
||||
result.success = (cancelEBResult != null && cancelEBResult.success) && cancelTBRResult.success;
|
||||
result.enacted = (cancelEBResult != null && cancelEBResult.enacted) || cancelTBRResult.enacted;
|
||||
result.comment = cancelEBResult != null ? cancelEBResult.comment : cancelTBRResult.comment;
|
||||
result.success((cancelEBResult != null && cancelEBResult.getSuccess()) && cancelTBRResult.getSuccess());
|
||||
result.enacted((cancelEBResult != null && cancelEBResult.getEnacted()) || cancelTBRResult.getEnacted());
|
||||
result.comment(cancelEBResult != null ? cancelEBResult.getComment() : cancelTBRResult.getComment());
|
||||
try {
|
||||
fetchStatus();
|
||||
readHistory();
|
||||
|
@ -873,24 +869,24 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
try {
|
||||
alertService.ignore(AlertType.WARNING_36);
|
||||
connectionService.requestMessage(new CancelTBRMessage()).await();
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
result.success(true)
|
||||
.enacted(true)
|
||||
.isTempCancel(true);
|
||||
confirmAlert(AlertType.WARNING_36);
|
||||
alertService.ignore(null);
|
||||
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
|
||||
result.comment(R.string.virtualpump_resultok);
|
||||
} catch (NoActiveTBRToCanceLException e) {
|
||||
result.success = true;
|
||||
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
|
||||
result.success(true);
|
||||
result.comment(R.string.virtualpump_resultok);
|
||||
} catch (AppLayerErrorException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while canceling TBR: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (InsightException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while canceling TBR: " + e.getClass().getCanonicalName());
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (Exception e) {
|
||||
aapsLogger.error("Exception while canceling TBR", e);
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -937,22 +933,20 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
} else
|
||||
treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus);
|
||||
}
|
||||
result.enacted = true;
|
||||
result.success = true;
|
||||
result.enacted(true).success(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
result.success = true;
|
||||
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
|
||||
result.success(true).comment(R.string.virtualpump_resultok);
|
||||
} catch (AppLayerErrorException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while canceling extended bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (InsightException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while canceling extended bolus: " + e.getClass().getCanonicalName());
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (Exception e) {
|
||||
aapsLogger.error("Exception while canceling extended bolus", e);
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1051,19 +1045,18 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
SetOperatingModeMessage operatingModeMessage = new SetOperatingModeMessage();
|
||||
operatingModeMessage.setOperatingMode(OperatingMode.STOPPED);
|
||||
connectionService.requestMessage(operatingModeMessage).await();
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.success(true).enacted(true);
|
||||
fetchStatus();
|
||||
readHistory();
|
||||
} catch (AppLayerErrorException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while stopping pump: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (InsightException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while stopping pump: " + e.getClass().getCanonicalName());
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (Exception e) {
|
||||
aapsLogger.error("Exception while stopping pump", e);
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1074,19 +1067,18 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
SetOperatingModeMessage operatingModeMessage = new SetOperatingModeMessage();
|
||||
operatingModeMessage.setOperatingMode(OperatingMode.STARTED);
|
||||
connectionService.requestMessage(operatingModeMessage).await();
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.success(true).enacted(true);
|
||||
fetchStatus();
|
||||
readHistory();
|
||||
} catch (AppLayerErrorException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while starting pump: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (InsightException e) {
|
||||
aapsLogger.info(LTag.PUMP, "Exception while starting pump: " + e.getClass().getCanonicalName());
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (Exception e) {
|
||||
aapsLogger.error("Exception while starting pump", e);
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1097,20 +1089,19 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
tbrOverNotificationBlock.setEnabled(enabled);
|
||||
try {
|
||||
ParameterBlockUtil.writeConfigurationBlock(connectionService, tbrOverNotificationBlock);
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.success(true).enacted(true);
|
||||
} catch (AppLayerErrorException e) {
|
||||
tbrOverNotificationBlock.setEnabled(valueBefore);
|
||||
aapsLogger.info(LTag.PUMP, "Exception while updating TBR notification block: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (InsightException e) {
|
||||
tbrOverNotificationBlock.setEnabled(valueBefore);
|
||||
aapsLogger.info(LTag.PUMP, "Exception while updating TBR notification block: " + e.getClass().getSimpleName());
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
} catch (Exception e) {
|
||||
tbrOverNotificationBlock.setEnabled(valueBefore);
|
||||
aapsLogger.error("Exception while updating TBR notification block", e);
|
||||
result.comment = ExceptionTranslator.getString(context, e);
|
||||
result.comment(ExceptionTranslator.getString(context, e));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1124,27 +1115,27 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
public String shortStatus(boolean veryShort) {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
if (connectionService.getLastConnected() != 0) {
|
||||
Long agoMsec = System.currentTimeMillis() - connectionService.getLastConnected();
|
||||
long agoMsec = System.currentTimeMillis() - connectionService.getLastConnected();
|
||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||
ret.append(resourceHelper.gs(R.string.short_status_last_connected, agoMin) + "\n");
|
||||
ret.append(resourceHelper.gs(R.string.short_status_last_connected, agoMin)).append("\n");
|
||||
}
|
||||
if (activeTBR != null) {
|
||||
ret.append(resourceHelper.gs(R.string.short_status_tbr, activeTBR.getPercentage(),
|
||||
activeTBR.getInitialDuration() - activeTBR.getRemainingDuration(), activeTBR.getInitialDuration()) + "\n");
|
||||
activeTBR.getInitialDuration() - activeTBR.getRemainingDuration(), activeTBR.getInitialDuration())).append("\n");
|
||||
}
|
||||
if (activeBoluses != null) for (ActiveBolus activeBolus : activeBoluses) {
|
||||
if (activeBolus.getBolusType() == BolusType.STANDARD) continue;
|
||||
ret.append(resourceHelper.gs(activeBolus.getBolusType() == BolusType.MULTIWAVE ? R.string.short_status_multiwave : R.string.short_status_extended,
|
||||
activeBolus.getRemainingAmount(), activeBolus.getInitialAmount(), activeBolus.getRemainingDuration()) + "\n");
|
||||
activeBolus.getRemainingAmount(), activeBolus.getInitialAmount(), activeBolus.getRemainingDuration())).append("\n");
|
||||
}
|
||||
if (!veryShort && totalDailyDose != null) {
|
||||
ret.append(resourceHelper.gs(R.string.short_status_tdd, totalDailyDose.getBolusAndBasal()) + "\n");
|
||||
ret.append(resourceHelper.gs(R.string.short_status_tdd, totalDailyDose.getBolusAndBasal())).append("\n");
|
||||
}
|
||||
if (cartridgeStatus != null) {
|
||||
ret.append(resourceHelper.gs(R.string.short_status_reservoir, cartridgeStatus.getRemainingAmount()) + "\n");
|
||||
ret.append(resourceHelper.gs(R.string.short_status_reservoir, cartridgeStatus.getRemainingAmount())).append("\n");
|
||||
}
|
||||
if (batteryStatus != null) {
|
||||
ret.append(resourceHelper.gs(R.string.short_status_battery, batteryStatus.getBatteryAmount()) + "\n");
|
||||
ret.append(resourceHelper.gs(R.string.short_status_battery, batteryStatus.getBatteryAmount())).append("\n");
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
@ -1236,7 +1227,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
|||
temporaryBasal.isAbsolute = false;
|
||||
temporaryBasals.add(temporaryBasal);
|
||||
}
|
||||
Collections.sort(temporaryBasals, (o1, o2) -> (int) (o1.date - o2.date));
|
||||
temporaryBasals.sort((o1, o2) -> (int) (o1.date - o2.date));
|
||||
for (TemporaryBasal temporaryBasal : temporaryBasals)
|
||||
treatmentsPlugin.addToHistoryTempBasal(temporaryBasal);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import org.joda.time.LocalDateTime;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -908,7 +907,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
return new PumpEnactResult(getInjector()) //
|
||||
.success(bolusDeliveryType == BolusDeliveryType.CancelDelivery) //
|
||||
.enacted(false) //
|
||||
.comment(getResourceHelper().gs(R.string.medtronic_cmd_bolus_could_not_be_delivered));
|
||||
.comment(R.string.medtronic_cmd_bolus_could_not_be_delivered);
|
||||
}
|
||||
|
||||
} finally {
|
||||
|
@ -933,7 +932,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
return new PumpEnactResult(getInjector()) //
|
||||
.success(false) //
|
||||
.enacted(false) //
|
||||
.comment(getResourceHelper().gs(R.string.medtronic_pump_status_pump_unreachable));
|
||||
.comment(R.string.medtronic_pump_status_pump_unreachable);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -969,7 +968,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
return new PumpEnactResult(getInjector()) //
|
||||
.success(false) //
|
||||
.enacted(false) //
|
||||
.comment(getResourceHelper().gs(R.string.medtronic_pump_status_pump_unreachable));
|
||||
.comment(R.string.medtronic_pump_status_pump_unreachable);
|
||||
}
|
||||
|
||||
medtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable, rxBus);
|
||||
|
@ -983,7 +982,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
aapsLogger.warn(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute - Could not read current TBR, canceling operation.");
|
||||
finishAction("TBR");
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(getResourceHelper().gs(R.string.medtronic_cmd_cant_read_tbr));
|
||||
.comment(R.string.medtronic_cmd_cant_read_tbr);
|
||||
} else {
|
||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute: Current Basal: duration: " + tbrCurrent.getDurationMinutes() + " min, rate=" + tbrCurrent.getInsulinRate());
|
||||
}
|
||||
|
@ -1025,7 +1024,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
finishAction("TBR");
|
||||
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(getResourceHelper().gs(R.string.medtronic_cmd_cant_cancel_tbr_stop_op));
|
||||
.comment(R.string.medtronic_cmd_cant_cancel_tbr_stop_op);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1062,7 +1061,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
finishAction("TBR");
|
||||
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false) //
|
||||
.comment(getResourceHelper().gs(R.string.medtronic_cmd_tbr_could_not_be_delivered));
|
||||
.comment(R.string.medtronic_cmd_tbr_could_not_be_delivered);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1361,7 +1360,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
return new PumpEnactResult(getInjector()) //
|
||||
.success(false) //
|
||||
.enacted(false) //
|
||||
.comment(getResourceHelper().gs(R.string.medtronic_pump_status_pump_unreachable));
|
||||
.comment(R.string.medtronic_pump_status_pump_unreachable);
|
||||
}
|
||||
|
||||
medtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable, rxBus);
|
||||
|
@ -1379,7 +1378,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
aapsLogger.warn(LTag.PUMP, getLogPrefix() + "cancelTempBasal - Could not read currect TBR, canceling operation.");
|
||||
finishAction("TBR");
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||
.comment(getResourceHelper().gs(R.string.medtronic_cmd_cant_read_tbr));
|
||||
.comment(R.string.medtronic_cmd_cant_read_tbr);
|
||||
}
|
||||
|
||||
MedtronicUITask responseTask2 = rileyLinkMedtronicService.getMedtronicUIComm().executeCommand(MedtronicCommandType.CancelTBR);
|
||||
|
@ -1404,7 +1403,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - Cancel TBR failed.");
|
||||
|
||||
return new PumpEnactResult(getInjector()).success(response).enacted(response) //
|
||||
.comment(getResourceHelper().gs(R.string.medtronic_cmd_cant_cancel_tbr));
|
||||
.comment(R.string.medtronic_cmd_cant_cancel_tbr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1432,7 +1431,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
return new PumpEnactResult(getInjector()) //
|
||||
.success(true) //
|
||||
.enacted(false) //
|
||||
.comment(getResourceHelper().gs(R.string.medtronic_cmd_basal_profile_not_set_is_same));
|
||||
.comment(R.string.medtronic_cmd_basal_profile_not_set_is_same);
|
||||
}
|
||||
|
||||
setRefreshButtonEnabled(false);
|
||||
|
@ -1444,7 +1443,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
return new PumpEnactResult(getInjector()) //
|
||||
.success(false) //
|
||||
.enacted(false) //
|
||||
.comment(getResourceHelper().gs(R.string.medtronic_pump_status_pump_unreachable));
|
||||
.comment(R.string.medtronic_pump_status_pump_unreachable);
|
||||
}
|
||||
|
||||
medtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable, rxBus);
|
||||
|
@ -1471,7 +1470,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
return new PumpEnactResult(getInjector()).success(true).enacted(true);
|
||||
} else {
|
||||
return new PumpEnactResult(getInjector()).success(response).enacted(response) //
|
||||
.comment(getResourceHelper().gs(R.string.medtronic_cmd_basal_profile_could_not_be_set));
|
||||
.comment(R.string.medtronic_cmd_basal_profile_could_not_be_set);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1544,7 +1543,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
|
||||
@Override
|
||||
public void executeCustomAction(CustomActionType customActionType) {
|
||||
public void executeCustomAction(@NonNull CustomActionType customActionType) {
|
||||
|
||||
MedtronicCustomActionType mcat = (MedtronicCustomActionType) customActionType;
|
||||
|
||||
|
@ -1578,7 +1577,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
}
|
||||
|
||||
@Override
|
||||
public void timezoneOrDSTChanged(TimeChangeType changeType) {
|
||||
public void timezoneOrDSTChanged(@NonNull TimeChangeType changeType) {
|
||||
|
||||
aapsLogger.warn(LTag.PUMP, getLogPrefix() + "Time or TimeZone changed. ");
|
||||
|
||||
|
@ -1591,7 +1590,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
}
|
||||
|
||||
|
||||
private void setEnableCustomAction(MedtronicCustomActionType customAction, boolean isEnabled) {
|
||||
@SuppressWarnings("SameParameterValue") private void setEnableCustomAction(MedtronicCustomActionType customAction, boolean isEnabled) {
|
||||
|
||||
if (customAction == MedtronicCustomActionType.ClearBolusBlock) {
|
||||
this.customActionClearBolusBlock.setEnabled(isEnabled);
|
||||
|
|
|
@ -440,7 +440,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
|||
getCommandQueue().customCommand(new CommandAcknowledgeAlerts(), new Callback() {
|
||||
@Override public void run() {
|
||||
if (result != null) {
|
||||
aapsLogger.debug(LTag.PUMP, "Acknowledge alerts result: {} ({})", result.success, result.comment);
|
||||
aapsLogger.debug(LTag.PUMP, "Acknowledge alerts result: {} ({})", result.getSuccess(), result.getComment());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -584,7 +584,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
|||
public PumpEnactResult setNewBasalProfile(@NonNull Profile profile) {
|
||||
PumpEnactResult result = executeCommand(OmnipodCommandType.SET_BASAL_PROFILE, () -> aapsOmnipodErosManager.setBasalProfile(profile, true));
|
||||
|
||||
aapsLogger.info(LTag.PUMP, "Basal Profile was set: " + result.success);
|
||||
aapsLogger.info(LTag.PUMP, "Basal Profile was set: " + result.getSuccess());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -639,7 +639,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
|||
// neither carbs nor bolus requested
|
||||
aapsLogger.error("deliverTreatment: Invalid input: neither carbs nor insulin are set in treatment");
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).bolusDelivered(0d).carbsDelivered(0d)
|
||||
.comment(getResourceHelper().gs(info.nightscout.androidaps.core.R.string.invalidinput));
|
||||
.comment(info.nightscout.androidaps.core.R.string.invalidinput);
|
||||
} else if (detailedBolusInfo.insulin > 0) {
|
||||
// bolus needed, ask pump to deliver it
|
||||
return deliverBolus(detailedBolusInfo);
|
||||
|
@ -648,7 +648,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
|||
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
|
||||
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true).bolusDelivered(0d)
|
||||
.carbsDelivered(detailedBolusInfo.carbs).comment(getResourceHelper().gs(info.nightscout.androidaps.core.R.string.common_resultok));
|
||||
.carbsDelivered(detailedBolusInfo.carbs).comment(info.nightscout.androidaps.core.R.string.common_resultok);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -685,9 +685,9 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
|||
|
||||
PumpEnactResult result = executeCommand(OmnipodCommandType.SET_TEMPORARY_BASAL, () -> aapsOmnipodErosManager.setTemporaryBasal(new TempBasalPair(absoluteRate, false, durationInMinutes)));
|
||||
|
||||
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - setTBR. Response: " + result.success);
|
||||
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - setTBR. Response: " + result.getSuccess());
|
||||
|
||||
if (result.success) {
|
||||
if (result.getSuccess()) {
|
||||
incrementStatistics(OmnipodErosStorageKeys.Statistics.TBRS_SET);
|
||||
}
|
||||
|
||||
|
@ -889,7 +889,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
|||
|
||||
PumpEnactResult result = executeCommand(OmnipodCommandType.CONFIGURE_ALERTS, () -> aapsOmnipodErosManager.configureAlerts(alertConfigurations));
|
||||
|
||||
if (result.success) {
|
||||
if (result.getSuccess()) {
|
||||
aapsLogger.info(LTag.PUMP, "Successfully configured alerts in Pod");
|
||||
|
||||
podStateManager.setExpirationAlertTimeBeforeShutdown(expirationReminderTimeBeforeShutdown);
|
||||
|
@ -919,7 +919,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
|||
result = getPodStatus();
|
||||
}
|
||||
|
||||
if (result.success) {
|
||||
if (result.getSuccess()) {
|
||||
this.hasTimeDateOrTimeZoneChanged = false;
|
||||
timeChangeRetries = 0;
|
||||
|
||||
|
@ -1066,7 +1066,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
|||
boolean success = false;
|
||||
for (int i = 0; STARTUP_STATUS_REQUEST_TRIES > i; i++) {
|
||||
PumpEnactResult result = getPodStatus();
|
||||
if (result.success) {
|
||||
if (result.getSuccess()) {
|
||||
success = true;
|
||||
aapsLogger.debug(LTag.PUMP, "Successfully retrieved Pod status on startup");
|
||||
break;
|
||||
|
@ -1086,7 +1086,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
|||
@NonNull private PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
||||
PumpEnactResult result = executeCommand(OmnipodCommandType.SET_BOLUS, () -> aapsOmnipodErosManager.bolus(detailedBolusInfo));
|
||||
|
||||
if (result.success) {
|
||||
if (result.getSuccess()) {
|
||||
incrementStatistics(detailedBolusInfo.isSMB ? OmnipodErosStorageKeys.Statistics.SMB_BOLUSES_DELIVERED
|
||||
: OmnipodErosStorageKeys.Statistics.STANDARD_BOLUSES_DELIVERED);
|
||||
|
||||
|
@ -1136,7 +1136,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
|||
}
|
||||
|
||||
private PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(resourceId));
|
||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(resourceId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ public class AapsOmnipodErosManager {
|
|||
result.success(false).enacted(false).comment(translateException(ex));
|
||||
}
|
||||
|
||||
addToHistory(System.currentTimeMillis(), PodHistoryEntryType.INITIALIZE_POD, result.comment, result.success);
|
||||
addToHistory(System.currentTimeMillis(), PodHistoryEntryType.INITIALIZE_POD, result.getComment(), result.getSuccess());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -221,9 +221,9 @@ public class AapsOmnipodErosManager {
|
|||
result.success(false).enacted(false).comment(translateException(ex));
|
||||
}
|
||||
|
||||
addToHistory(System.currentTimeMillis(), PodHistoryEntryType.INSERT_CANNULA, result.comment, result.success);
|
||||
addToHistory(System.currentTimeMillis(), PodHistoryEntryType.INSERT_CANNULA, result.getComment(), result.getSuccess());
|
||||
|
||||
if (result.success) {
|
||||
if (result.getSuccess()) {
|
||||
uploadCareportalEvent(System.currentTimeMillis() - 1000, CareportalEvent.INSULINCHANGE);
|
||||
uploadCareportalEvent(System.currentTimeMillis(), CareportalEvent.SITECHANGE);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.os.Looper;
|
|||
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.tz.UTCProvider;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
|
@ -14,7 +15,6 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import dagger.android.AndroidInjector;
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
|
@ -30,8 +30,10 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodE
|
|||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||
import info.nightscout.androidaps.utils.rx.TestAapsSchedulers;
|
||||
|
||||
import static info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.OmnipodConstants.BASAL_STEP_DURATION;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
@ -49,6 +51,10 @@ public class OmnipodErosPumpPluginTest {
|
|||
@Mock CommandQueueProvider commandQueueProvider;
|
||||
@Mock RileyLinkUtil rileyLinkUtil;
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
when(resourceHelper.gs(anyInt(), anyLong())).thenReturn("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(Looper.class)
|
||||
|
@ -65,9 +71,7 @@ public class OmnipodErosPumpPluginTest {
|
|||
);
|
||||
when(activePluginProvider.getActiveTreatments().getTempBasalFromHistory(anyLong())).thenReturn(null);
|
||||
when(rileyLinkUtil.getRileyLinkHistory()).thenReturn(new ArrayList<>());
|
||||
when(injector.androidInjector()).thenReturn(new AndroidInjector<Object>() {
|
||||
@Override public void inject(Object instance) {
|
||||
}
|
||||
when(injector.androidInjector()).thenReturn(instance -> {
|
||||
});
|
||||
Profile profile = mock(Profile.class);
|
||||
|
||||
|
@ -92,17 +96,17 @@ public class OmnipodErosPumpPluginTest {
|
|||
PumpEnactResult result4 = plugin.setTempBasalPercent(0, 0, profile, false);
|
||||
PumpEnactResult result5 = plugin.setTempBasalPercent(-50, 60, profile, false);
|
||||
// Then return correct values
|
||||
assertEquals(result1.absolute, 0.4d, 0.01d);
|
||||
assertEquals(result1.duration, 30);
|
||||
assertEquals(result2.absolute, 25d, 0.01d);
|
||||
assertEquals(result2.duration, 30000);
|
||||
assertEquals(result3.absolute, 0d, 0.01d);
|
||||
assertEquals(result3.duration, 30);
|
||||
assertEquals(result4.absolute, -1d, 0.01d);
|
||||
assertEquals(result4.duration, -1);
|
||||
assertEquals(result1.getAbsolute(), 0.4d, 0.01d);
|
||||
assertEquals(result1.getDuration(), 30);
|
||||
assertEquals(result2.getAbsolute(), 25d, 0.01d);
|
||||
assertEquals(result2.getDuration(), 30000);
|
||||
assertEquals(result3.getAbsolute(), 0d, 0.01d);
|
||||
assertEquals(result3.getDuration(), 30);
|
||||
assertEquals(result4.getAbsolute(), -1d, 0.01d);
|
||||
assertEquals(result4.getDuration(), -1);
|
||||
// this is validated downstream, see TempBasalExtraCommand
|
||||
assertEquals(result5.absolute, -0.25d, 0.01d);
|
||||
assertEquals(result5.duration, 60);
|
||||
assertEquals(result5.getAbsolute(), -0.25d, 0.01d);
|
||||
assertEquals(result5.getDuration(), 60);
|
||||
|
||||
// Given zero basal
|
||||
when(profile.getBasal()).thenReturn(0d);
|
||||
|
@ -110,34 +114,34 @@ public class OmnipodErosPumpPluginTest {
|
|||
result1 = plugin.setTempBasalPercent(8000, 90, profile, false);
|
||||
result2 = plugin.setTempBasalPercent(0, 0, profile, false);
|
||||
// Then return zero values
|
||||
assertEquals(result1.absolute, 0d, 0.01d);
|
||||
assertEquals(result1.duration, 90);
|
||||
assertEquals(result2.absolute, -1d, 0.01d);
|
||||
assertEquals(result2.duration, -1);
|
||||
assertEquals(result1.getAbsolute(), 0d, 0.01d);
|
||||
assertEquals(result1.getDuration(), 90);
|
||||
assertEquals(result2.getAbsolute(), -1d, 0.01d);
|
||||
assertEquals(result2.getDuration(), -1);
|
||||
|
||||
// Given unhealthy basal
|
||||
when(profile.getBasal()).thenReturn(500d);
|
||||
// When treatment
|
||||
result1 = plugin.setTempBasalPercent(80, 30, profile, false);
|
||||
// Then return sane values
|
||||
assertEquals(result1.absolute, PumpType.Omnipod_Eros.determineCorrectBasalSize(500d * 0.8), 0.01d);
|
||||
assertEquals(result1.duration, 30);
|
||||
assertEquals(result1.getAbsolute(), PumpType.Omnipod_Eros.determineCorrectBasalSize(500d * 0.8), 0.01d);
|
||||
assertEquals(result1.getDuration(), 30);
|
||||
|
||||
// Given weird basal
|
||||
when(profile.getBasal()).thenReturn(1.234567d);
|
||||
// When treatment
|
||||
result1 = plugin.setTempBasalPercent(280, 600, profile, false);
|
||||
// Then return sane values
|
||||
assertEquals(result1.absolute, 3.4567876, 0.01d);
|
||||
assertEquals(result1.duration, 600);
|
||||
assertEquals(result1.getAbsolute(), 3.4567876, 0.01d);
|
||||
assertEquals(result1.getDuration(), 600);
|
||||
|
||||
// Given negative basal
|
||||
when(profile.getBasal()).thenReturn(-1.234567d);
|
||||
// When treatment
|
||||
result1 = plugin.setTempBasalPercent(280, 510, profile, false);
|
||||
// Then return negative value (this is validated further downstream, see TempBasalExtraCommand)
|
||||
assertEquals(result1.absolute, -3.4567876, 0.01d);
|
||||
assertEquals(result1.duration, 510);
|
||||
assertEquals(result1.getAbsolute(), -3.4567876, 0.01d);
|
||||
assertEquals(result1.getDuration(), 510);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue