From 3887cc90ae040a59fa36676ab4a0e1e9cc9a73f3 Mon Sep 17 00:00:00 2001 From: Carlos Rafael Giani Date: Wed, 28 Dec 2022 22:52:40 +0100 Subject: [PATCH] combov2: Set enacted to true even if the basal profiles are identical Signed-off-by: Carlos Rafael Giani --- .../nightscout/pump/combov2/ComboV2Plugin.kt | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/ComboV2Plugin.kt b/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/ComboV2Plugin.kt index 6b38b859a9..341ac5323e 100644 --- a/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/ComboV2Plugin.kt +++ b/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/ComboV2Plugin.kt @@ -786,17 +786,25 @@ class ComboV2Plugin @Inject constructor ( Notification.INFO, 60 ) - - pumpEnactResult.apply { - success = true - enacted = true - } } else { aapsLogger.debug(LTag.PUMP, "Basal profiles are equal; did not have to set anything") - pumpEnactResult.apply { - success = true - enacted = false - } + // Treat this as if the command had been enacted. Setting a basal profile is + // an idempotent operation, meaning that setting the exact same profile factors + // twice in a row does not actually change anything. Therefore, we can just + // completely skip such a redundant set basal profile operation and still get + // the exact same result. + // Furthermore, it is actually important to also set enacted to true in this case + // because even though this _driver_ might know that the Combo uses this profile + // already, _AAPS_ might not. A good example is when AAPS is set up the first time + // and no profile has been activated. If in this case the profile happens to be + // identical to what's already in the Combo, then enacted=false would cause errors, + // because AAPS expects the driver to always enact the profile change in this case + // (since it thinks that no profile is set yet). + } + + pumpEnactResult.apply { + success = true + enacted = true } } } catch (e: CancellationException) {