From 0c833d087ba0bdd57824cfa92a3fa28eb7d5db0c Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 4 Dec 2022 12:26:56 +0100 Subject: [PATCH] EOPATCH: fix setting of profile --- core/ui/src/main/res/values/strings.xml | 2 + .../nightscout/pump/combo/ComboPlugin.java | 2 +- .../androidaps/danar/AbstractDanaRPlugin.java | 2 +- .../androidaps/danar/DanaRPlugin.java | 4 +- .../nightscout/pump/danars/DanaRSPlugin.kt | 37 +++++++++++-------- .../plugins/pump/eopatch/EopatchPumpPlugin.kt | 33 ++++++++++------- 6 files changed, 46 insertions(+), 34 deletions(-) diff --git a/core/ui/src/main/res/values/strings.xml b/core/ui/src/main/res/values/strings.xml index 5a668615e9..ab131ced6f 100644 --- a/core/ui/src/main/res/values/strings.xml +++ b/core/ui/src/main/res/values/strings.xml @@ -163,6 +163,8 @@ DIA IC ISF + Canceling of temporary basal failed + Canceling of extended bolus failed Wrong password diff --git a/pump/combo/src/main/java/info/nightscout/pump/combo/ComboPlugin.java b/pump/combo/src/main/java/info/nightscout/pump/combo/ComboPlugin.java index 6d332c9460..362f658d35 100644 --- a/pump/combo/src/main/java/info/nightscout/pump/combo/ComboPlugin.java +++ b/pump/combo/src/main/java/info/nightscout/pump/combo/ComboPlugin.java @@ -823,7 +823,7 @@ public class ComboPlugin extends PumpPluginBase implements Pump, Constraints { ); return new PumpEnactResult(getInjector()).isTempCancel(true).success(true).enacted(true); } else { - return new PumpEnactResult(getInjector()).success(false).enacted(false); + return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(info.nightscout.core.ui.R.string.canceling_eb_failed); } } else if (activeTemp == null) { return new PumpEnactResult(getInjector()).success(true).enacted(false); diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java b/pump/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java index 39e26646a0..e2245e4d41 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java @@ -334,7 +334,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump serialNumber() ); } else - result.success(false).enacted(false).isTempCancel(true); + result.success(false).enacted(false).isTempCancel(true).comment(info.nightscout.core.ui.R.string.canceling_eb_failed); } else { result.success(true).comment(info.nightscout.core.ui.R.string.ok).isTempCancel(true); getAapsLogger().debug(LTag.PUMP, "cancelExtendedBolus: OK"); diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java b/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java index 36706555ca..077711adb6 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java @@ -353,9 +353,9 @@ public class DanaRPlugin extends AbstractDanaRPlugin { getPumpDescription().getPumpType(), serialNumber() ); - result.success(true).enacted(true).isTempCancel(true); + result.success(true).enacted(true).isTempCancel(true).comment(info.nightscout.core.ui.R.string.ok); } else - result.success(false).enacted(false).isTempCancel(true); + result.success(false).enacted(false).isTempCancel(true).comment(info.nightscout.core.ui.R.string.canceling_eb_failed); } else { result.success(true).isTempCancel(true).comment(info.nightscout.core.ui.R.string.ok); aapsLogger.debug(LTag.PUMP, "cancelRealTempBasal: OK"); diff --git a/pump/danars/src/main/java/info/nightscout/pump/danars/DanaRSPlugin.kt b/pump/danars/src/main/java/info/nightscout/pump/danars/DanaRSPlugin.kt index 400ff59f33..f5754912d9 100644 --- a/pump/danars/src/main/java/info/nightscout/pump/danars/DanaRSPlugin.kt +++ b/pump/danars/src/main/java/info/nightscout/pump/danars/DanaRSPlugin.kt @@ -522,35 +522,40 @@ class DanaRSPlugin @Inject constructor( @Synchronized override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult { - val result = PumpEnactResult(injector) if (danaPump.isTempBasalInProgress) { + aapsLogger.debug(LTag.PUMP, "cancelRealTempBasal: Failed") danaRSService?.tempBasalStop() - result.success = !danaPump.isTempBasalInProgress - result.enacted = true - result.isTempCancel = true + return PumpEnactResult(injector) + .success(!danaPump.isTempBasalInProgress) + .enacted(true) + .isTempCancel(true) + .comment(info.nightscout.core.ui.R.string.canceling_tbr_failed) } else { - result.success = true - result.enacted = false - result.isTempCancel = true - result.comment = rh.gs(info.nightscout.core.ui.R.string.ok) aapsLogger.debug(LTag.PUMP, "cancelRealTempBasal: OK") + return PumpEnactResult(injector) + .success(true) + .enacted(false) + .isTempCancel(true) + .comment(info.nightscout.core.ui.R.string.ok) } - return result } @Synchronized override fun cancelExtendedBolus(): PumpEnactResult { - val result = PumpEnactResult(injector) if (danaPump.isExtendedInProgress) { danaRSService?.extendedBolusStop() - result.success = !danaPump.isExtendedInProgress - result.enacted = true + aapsLogger.debug(LTag.PUMP, "cancelExtendedBolus: Failed") + return PumpEnactResult(injector) + .success(!danaPump.isExtendedInProgress) + .enacted(true) + .comment(info.nightscout.core.ui.R.string.canceling_eb_failed) } else { - result.success = true - result.enacted = false - result.comment = rh.gs(info.nightscout.core.ui.R.string.ok) aapsLogger.debug(LTag.PUMP, "cancelExtendedBolus: OK") + return PumpEnactResult(injector) + .success(true) + .enacted(false) + .isTempCancel(true) + .comment(info.nightscout.core.ui.R.string.ok) } - return result } override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject { diff --git a/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/EopatchPumpPlugin.kt b/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/EopatchPumpPlugin.kt index 813b617897..c771780d4a 100644 --- a/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/EopatchPumpPlugin.kt +++ b/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/EopatchPumpPlugin.kt @@ -176,19 +176,25 @@ class EopatchPumpPlugin @Inject constructor( override fun setNewBasalProfile(profile: Profile): PumpEnactResult { mLastDataTime = System.currentTimeMillis() if (patchManager.isActivated) { - if (patchManager.patchState.isTempBasalActive || patchManager.patchState.isBolusActive) { - return PumpEnactResult(injector) - } else { - var isSuccess: Boolean? = null - val result: BehaviorSubject = BehaviorSubject.create() - val disposable = result.hide() - .subscribe { - isSuccess = it - } + if (patchManager.patchState.isTempBasalActive) { + val cancelResult = cancelTempBasal(true) + if (!cancelResult.success) return PumpEnactResult(injector).isTempCancel(true).comment(info.nightscout.core.ui.R.string.canceling_tbr_failed) + } - val nb = preferenceManager.getNormalBasalManager().convertProfileToNormalBasal(profile) - mDisposables.add( - patchManager.startBasal(nb) + if (patchManager.patchState.isExtBolusActive) { + val cancelResult = cancelExtendedBolus() + if (!cancelResult.success) return PumpEnactResult(injector).comment(info.nightscout.core.ui.R.string.canceling_eb_failed) + } + var isSuccess: Boolean? = null + val result: BehaviorSubject = BehaviorSubject.create() + val disposable = result.hide() + .subscribe { + isSuccess = it + } + + val nb = preferenceManager.getNormalBasalManager().convertProfileToNormalBasal(profile) + mDisposables.add( + patchManager.startBasal(nb) .observeOn(aapsSchedulers.main) .subscribe({ response -> result.onNext(response.isSuccess) @@ -209,7 +215,6 @@ class EopatchPumpPlugin @Inject constructor( } else { return PumpEnactResult(injector) } - } } else { preferenceManager.getNormalBasalManager().setNormalBasal(profile) preferenceManager.flushNormalBasalManager() @@ -479,7 +484,7 @@ class EopatchPumpPlugin @Inject constructor( .map { PumpEnactResult(injector).success(true).enacted(true).isTempCancel(true) } .onErrorReturnItem( PumpEnactResult(injector).success(false).enacted(false) - .comment(rh.gs(info.nightscout.core.ui.R.string.error)) + .comment(rh.gs(info.nightscout.core.ui.R.string.canceling_eb_failed)) ) .blockingGet() } else {