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