Eopatch: handle stopped bolus properly

This commit is contained in:
Milos Kozak 2022-12-05 18:27:05 +01:00
parent d5af299692
commit 6a3f833a82
16 changed files with 44 additions and 75 deletions

View file

@ -9,7 +9,7 @@ import info.nightscout.plugins.aps.loop.extensions.json
import info.nightscout.plugins.extensions.toText
import info.nightscout.plugins.sync.nsShared.extensions.log
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
@ -43,91 +43,84 @@ class PumpEnactResultTest : TestBaseWithProfile() {
val per = PumpEnactResult(injector)
per.success(true)
Assert.assertEquals(true, per.success)
Assertions.assertEquals(true, per.success)
}
@Test fun enactedTest() {
val per = PumpEnactResult(injector)
per.enacted(true)
Assert.assertEquals(true, per.enacted)
Assertions.assertEquals(true, per.enacted)
}
@Test fun commentTest() {
val per = PumpEnactResult(injector)
per.comment("SomeComment")
Assert.assertEquals("SomeComment", per.comment)
Assertions.assertEquals("SomeComment", per.comment)
}
@Test fun durationTest() {
val per = PumpEnactResult(injector)
per.duration(10)
Assert.assertEquals(10, per.duration.toLong())
Assertions.assertEquals(10, per.duration.toLong())
}
@Test fun absoluteTest() {
val per = PumpEnactResult(injector)
per.absolute(11.0)
Assert.assertEquals(11.0, per.absolute, 0.01)
Assertions.assertEquals(11.0, per.absolute, 0.01)
}
@Test fun percentTest() {
val per = PumpEnactResult(injector)
per.percent(10)
Assert.assertEquals(10, per.percent)
Assertions.assertEquals(10, per.percent)
}
@Test fun isPercentTest() {
val per = PumpEnactResult(injector)
per.isPercent(true)
Assert.assertEquals(true, per.isPercent)
Assertions.assertEquals(true, per.isPercent)
}
@Test fun isTempCancelTest() {
val per = PumpEnactResult(injector)
per.isTempCancel(true)
Assert.assertEquals(true, per.isTempCancel)
Assertions.assertEquals(true, per.isTempCancel)
}
@Test fun bolusDeliveredTest() {
val per = PumpEnactResult(injector)
per.bolusDelivered(11.0)
Assert.assertEquals(11.0, per.bolusDelivered, 0.01)
}
@Test fun carbsDeliveredTest() {
val per = PumpEnactResult(injector)
per.carbsDelivered(11.0)
Assert.assertEquals(11.0, per.carbsDelivered, 0.01)
Assertions.assertEquals(11.0, per.bolusDelivered, 0.01)
}
@Test fun queuedTest() {
val per = PumpEnactResult(injector)
per.queued(true)
Assert.assertEquals(true, per.queued)
Assertions.assertEquals(true, per.queued)
}
@Test fun logTest() {
val per = PumpEnactResult(injector)
Assert.assertEquals(
"Success: false Enacted: false Comment: Duration: -1 Absolute: -1.0 Percent: -1 IsPercent: false IsTempCancel: false bolusDelivered: 0.0 carbsDelivered: 0.0 Queued: false",
Assertions.assertEquals(
"Success: false Enacted: false Comment: Duration: -1 Absolute: -1.0 Percent: -1 IsPercent: false IsTempCancel: false bolusDelivered: 0.0 Queued: false",
per.log()
)
}
@Test fun toStringTest() {
var per = PumpEnactResult(injector).enacted(true).bolusDelivered(10.0).comment("AAA")
Assert.assertEquals(
Assertions.assertEquals(
"""
Success: false
Enacted: true
@ -136,7 +129,7 @@ class PumpEnactResultTest : TestBaseWithProfile() {
""".trimIndent(), per.toText(rh)
)
per = PumpEnactResult(injector).enacted(true).isTempCancel(true).comment("AAA")
Assert.assertEquals(
Assertions.assertEquals(
"""
Success: false
Enacted: true
@ -145,7 +138,7 @@ class PumpEnactResultTest : TestBaseWithProfile() {
""".trimIndent(), per.toText(rh)
)
per = PumpEnactResult(injector).enacted(true).isPercent(true).percent(90).duration(20).comment("AAA")
Assert.assertEquals(
Assertions.assertEquals(
"""
Success: false
Enacted: true
@ -155,7 +148,7 @@ class PumpEnactResultTest : TestBaseWithProfile() {
""".trimIndent(), per.toText(rh)
)
per = PumpEnactResult(injector).enacted(true).isPercent(false).absolute(1.0).duration(30).comment("AAA")
Assert.assertEquals(
Assertions.assertEquals(
"""
Success: false
Enacted: true
@ -165,7 +158,7 @@ class PumpEnactResultTest : TestBaseWithProfile() {
""".trimIndent(), per.toText(rh)
)
per = PumpEnactResult(injector).enacted(false).comment("AAA")
Assert.assertEquals(
Assertions.assertEquals(
"""
Success: false
Comment: AAA
@ -176,15 +169,15 @@ class PumpEnactResultTest : TestBaseWithProfile() {
@Test fun toHtmlTest() {
var per: PumpEnactResult = PumpEnactResult(injector).enacted(true).bolusDelivered(10.0).comment("AAA")
Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>SMB</b>: 10.0 U", per.toHtml(rh))
Assertions.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>SMB</b>: 10.0 U", per.toHtml(rh))
per = PumpEnactResult(injector).enacted(true).isTempCancel(true).comment("AAA")
Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br>Cancel temp basal", per.toHtml(rh))
Assertions.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br>Cancel temp basal", per.toHtml(rh))
per = PumpEnactResult(injector).enacted(true).isPercent(true).percent(90).duration(20).comment("AAA")
Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>Duration</b>: 20 min<br><b>Percent</b>: 90%", per.toHtml(rh))
Assertions.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>Duration</b>: 20 min<br><b>Percent</b>: 90%", per.toHtml(rh))
per = PumpEnactResult(injector).enacted(true).isPercent(false).absolute(1.0).duration(30).comment("AAA")
Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>Duration</b>: 30 min<br><b>Absolute</b>: 1.00 U/h", per.toHtml(rh))
Assertions.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>Duration</b>: 30 min<br><b>Absolute</b>: 1.00 U/h", per.toHtml(rh))
per = PumpEnactResult(injector).enacted(false).comment("AAA")
Assert.assertEquals("<b>Success</b>: false<br><b>Comment</b>: AAA", per.toHtml(rh))
Assertions.assertEquals("<b>Success</b>: false<br><b>Comment</b>: AAA", per.toHtml(rh))
}
@Test fun jsonTest() {

View file

@ -25,7 +25,6 @@ class PumpEnactResult(injector: HasAndroidInjector) {
// 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.also { this.success = success }
@ -38,6 +37,5 @@ class PumpEnactResult(injector: HasAndroidInjector) {
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 }
}

View file

@ -179,7 +179,6 @@ open class VirtualPumpPlugin @Inject constructor(
val result = PumpEnactResult(injector)
.success(true)
.bolusDelivered(detailedBolusInfo.insulin)
.carbsDelivered(detailedBolusInfo.carbs)
.enacted(detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
.comment(rh.gs(info.nightscout.core.ui.R.string.virtualpump_resultok))
val bolusingEvent = EventOverviewBolusProgress

View file

@ -14,6 +14,5 @@ fun PumpEnactResult.log(): String {
" IsPercent: " + isPercent +
" IsTempCancel: " + isTempCancel +
" bolusDelivered: " + bolusDelivered +
" carbsDelivered: " + carbsDelivered +
" Queued: " + queued
}

View file

@ -629,8 +629,7 @@ public class ComboPlugin extends PumpPluginBase implements Pump, Constraints {
return new PumpEnactResult(getInjector())
.success(true)
.enacted(lastPumpBolus.amount > 0)
.bolusDelivered(lastPumpBolus.amount)
.carbsDelivered(detailedBolusInfo.carbs);
.bolusDelivered(lastPumpBolus.amount);
} finally {
pump.activity = null;
rxBus.send(new EventComboPumpUpdateGUI());

View file

@ -157,7 +157,7 @@ class DanaRKoreanPlugin @Inject constructor(
result
} else {
val result = PumpEnactResult(injector)
result.success(false).bolusDelivered(0.0).carbsDelivered(0.0).comment(info.nightscout.core.ui.R.string.invalid_input)
result.success(false).bolusDelivered(0.0).comment(info.nightscout.core.ui.R.string.invalid_input)
aapsLogger.error("deliverTreatment: Invalid input")
result
}

View file

@ -197,8 +197,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) carbs, carbTimeStamp, t);
PumpEnactResult result = new PumpEnactResult(getInjector());
result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.getInsulin()) < pumpDescription.getBolusStep())
.bolusDelivered(t.getInsulin())
.carbsDelivered(detailedBolusInfo.carbs);
.bolusDelivered(t.getInsulin());
if (!result.getSuccess())
result.comment(rh.gs(info.nightscout.pump.dana.R.string.boluserrorcode, detailedBolusInfo.insulin, t.getInsulin(),
danaPump.getBolusStartErrorCode()));
@ -209,7 +208,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
return result;
} else {
PumpEnactResult result = new PumpEnactResult(getInjector());
result.success(false).bolusDelivered(0d).carbsDelivered(0d).comment(info.nightscout.core.ui.R.string.invalid_input);
result.success(false).bolusDelivered(0d).comment(info.nightscout.core.ui.R.string.invalid_input);
aapsLogger.error("deliverTreatment: Invalid input");
return result;
}

View file

@ -172,8 +172,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.getCarbsTimestamp() != null ? detailedBolusInfo.getCarbsTimestamp() : detailedBolusInfo.timestamp, t);
PumpEnactResult result = new PumpEnactResult(getInjector());
result.success(connectionOK && Math.abs(detailedBolusInfo.insulin - t.getInsulin()) < pumpDescription.getBolusStep())
.bolusDelivered(t.getInsulin())
.carbsDelivered(detailedBolusInfo.carbs);
.bolusDelivered(t.getInsulin());
if (!result.getSuccess())
result.comment(rh.gs(info.nightscout.pump.dana.R.string.boluserrorcode, detailedBolusInfo.insulin, t.getInsulin(), danaPump.getBolusStartErrorCode()));
else
@ -199,7 +198,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
return result;
} else {
PumpEnactResult result = new PumpEnactResult(getInjector());
result.success(false).bolusDelivered(0d).carbsDelivered(0d).comment(info.nightscout.core.ui.R.string.invalid_input);
result.success(false).bolusDelivered(0d).comment(info.nightscout.core.ui.R.string.invalid_input);
aapsLogger.error("deliverTreatment: Invalid input");
return result;
}

View file

@ -306,7 +306,6 @@ class DanaRSPlugin @Inject constructor(
val result = PumpEnactResult(injector)
result.success = connectionOK && abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep
result.bolusDelivered = t.insulin
result.carbsDelivered = detailedBolusInfo.carbs
if (!result.success) {
var error = "" + danaPump.bolusStartErrorCode
when (danaPump.bolusStartErrorCode) {
@ -323,7 +322,6 @@ class DanaRSPlugin @Inject constructor(
val result = PumpEnactResult(injector)
result.success = false
result.bolusDelivered = 0.0
result.carbsDelivered = 0.0
result.comment = rh.gs(info.nightscout.core.ui.R.string.invalid_input)
aapsLogger.error("deliverTreatment: Invalid input")
result

View file

@ -278,7 +278,6 @@ class DiaconnG8Plugin @Inject constructor(
val result = PumpEnactResult(injector)
result.success = connectionOK
result.bolusDelivered = t.insulin
result.carbsDelivered = detailedBolusInfo.carbs
if (result.success) result.enacted = true
if (!result.success) {
@ -290,7 +289,6 @@ class DiaconnG8Plugin @Inject constructor(
val result = PumpEnactResult(injector)
result.success = false
result.bolusDelivered = 0.0
result.carbsDelivered = 0.0
result.comment = rh.gs(info.nightscout.core.ui.R.string.invalid_input)
aapsLogger.error("deliverTreatment: Invalid input")
result

View file

@ -266,12 +266,8 @@ class EopatchPumpPlugin @Inject constructor(
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
if (detailedBolusInfo.insulin == 0.0 && detailedBolusInfo.carbs == 0.0) {
// neither carbs nor bolus requested
aapsLogger.error("deliverTreatment: Invalid input: neither carbs nor insulin are set in treatment")
return PumpEnactResult(injector).success(false).enacted(false).bolusDelivered(0.0).carbsDelivered(0.0)
.comment(rh.gs(info.nightscout.core.ui.R.string.invalid_input))
} else if (detailedBolusInfo.insulin > 0.0) {
val askedInsulin = detailedBolusInfo.insulin
if (detailedBolusInfo.insulin > 0.0) {
var isSuccess = true
val result = BehaviorSubject.createDefault(true)
val disposable = result.hide()
@ -315,17 +311,14 @@ class EopatchPumpPlugin @Inject constructor(
disposable.dispose()
return if (isSuccess)
PumpEnactResult(injector).success(true)/*.enacted(true)*/.carbsDelivered(detailedBolusInfo.carbs).bolusDelivered(detailedBolusInfo.insulin)
return if (isSuccess && askedInsulin == detailedBolusInfo.insulin)
PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(detailedBolusInfo.insulin)
else
PumpEnactResult(injector).success(false)/*.enacted(false)*/.carbsDelivered(0.0).bolusDelivered(detailedBolusInfo.insulin)
PumpEnactResult(injector).success(false)/*.enacted(false)*/.bolusDelivered(detailedBolusInfo.insulin)
} else {
// no bolus required, carb only treatment
patchManager.addBolusToHistory(detailedBolusInfo)
return PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(0.0)
.carbsDelivered(detailedBolusInfo.carbs).comment(rh.gs(info.nightscout.core.ui.R.string.ok))
// no bolus required
return PumpEnactResult(injector).success(false).enacted(false).bolusDelivered(0.0).comment(rh.gs(info.nightscout.core.ui.R.string.error))
}
}

View file

@ -664,10 +664,7 @@ class MedtronicPumpPlugin @Inject constructor(
val time = now + bolusTime * 1000
busyTimestamps.add(time)
setEnableCustomAction(MedtronicCustomActionType.ClearBolusBlock, true)
PumpEnactResult(injector).success(true) //
.enacted(true) //
.bolusDelivered(detailedBolusInfo.insulin) //
.carbsDelivered(detailedBolusInfo.carbs)
PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(detailedBolusInfo.insulin)
}
} finally {
finishAction("Bolus")

View file

@ -661,7 +661,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements Pump, Riley
if (detailedBolusInfo.insulin == 0 && detailedBolusInfo.carbs == 0) {
// neither carbs nor bolus requested
aapsLogger.error("deliverTreatment: Invalid input: neither carbs nor insulin are set in treatment");
return new PumpEnactResult(getInjector()).success(false).enacted(false).bolusDelivered(0d).carbsDelivered(0d)
return new PumpEnactResult(getInjector()).success(false).enacted(false).bolusDelivered(0d)
.comment(info.nightscout.core.ui.R.string.invalid_input);
} else if (detailedBolusInfo.insulin > 0) {
// bolus needed, ask pump to deliver it
@ -679,8 +679,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements Pump, Riley
"[date=%d, carbs=%.2f, pumpSerial=%s] - Result: %b",
detailedBolusInfo.timestamp, detailedBolusInfo.carbs, serialNumber(), result));
return new PumpEnactResult(getInjector()).success(true).enacted(true).bolusDelivered(0d)
.carbsDelivered(detailedBolusInfo.carbs);
return new PumpEnactResult(getInjector()).success(true).enacted(true).bolusDelivered(0d);
}
}
@ -1115,8 +1114,6 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements Pump, Riley
if (result.getSuccess()) {
incrementStatistics(detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB ? OmnipodErosStorageKeys.Statistics.SMB_BOLUSES_DELIVERED
: OmnipodErosStorageKeys.Statistics.STANDARD_BOLUSES_DELIVERED);
result.carbsDelivered(detailedBolusInfo.carbs);
}
return result;

View file

@ -446,7 +446,7 @@ public class AapsOmnipodErosManager {
sp.remove(OmnipodErosStorageKeys.Preferences.ACTIVE_BOLUS);
return new PumpEnactResult(injector).success(true).enacted(true).carbsDelivered(detailedBolusInfo.carbs).bolusDelivered(detailedBolusInfo.insulin);
return new PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(detailedBolusInfo.insulin);
}
public PumpEnactResult cancelBolus() {

View file

@ -308,8 +308,7 @@ abstract class PumpPluginAbstract protected constructor(
if (detailedBolusInfo.insulin == 0.0 && detailedBolusInfo.carbs == 0.0) {
// neither carbs nor bolus requested
aapsLogger.error("deliverTreatment: Invalid input")
PumpEnactResult(injector).success(false).enacted(false).bolusDelivered(0.0).carbsDelivered(0.0)
.comment(info.nightscout.core.ui.R.string.invalid_input)
PumpEnactResult(injector).success(false).enacted(false).bolusDelivered(0.0).comment(info.nightscout.core.ui.R.string.invalid_input)
} else if (detailedBolusInfo.insulin > 0) {
// bolus needed, ask pump to deliver it
deliverBolus(detailedBolusInfo)
@ -324,8 +323,7 @@ abstract class PumpPluginAbstract protected constructor(
bolusingEvent.percent = 100
rxBus.send(bolusingEvent)
aapsLogger.debug(LTag.PUMP, "deliverTreatment: Carb only treatment.")
PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(0.0)
.carbsDelivered(detailedBolusInfo.carbs).comment(R.string.common_resultok)
PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(0.0).comment(R.string.common_resultok)
}
} finally {
triggerUIChange()

View file

@ -2,6 +2,7 @@ package info.nightscout.workflow.di
import dagger.Module
import dagger.android.ContributesAndroidInjector
import info.nightscout.workflow.DummyWorker
import info.nightscout.workflow.InvokeLoopWorker
import info.nightscout.workflow.LoadBgDataWorker
import info.nightscout.workflow.PrepareBasalDataWorker
@ -33,4 +34,5 @@ abstract class WorkflowModule {
@ContributesAndroidInjector abstract fun prepareBucketedDataWorkerInjector(): PrepareBucketedDataWorker
@ContributesAndroidInjector abstract fun loadBgDataWorkerInjector(): LoadBgDataWorker
@ContributesAndroidInjector abstract fun invokeLoopWorkerInjector(): InvokeLoopWorker
@ContributesAndroidInjector abstract fun dummyWorkerInjector(): DummyWorker
}