diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 0802c31e4c..baaca002a8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -819,11 +819,40 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf checkForUnsafeUsage(preCheckResult); checkAndResolveTbrMismatch(preCheckResult.state); checkPumpTime(preCheckResult.state); + checkBasalRate(preCheckResult.state); checkHistory(); return null; } + + private void checkBasalRate(PumpState state) { + if (!pump.initialized) { + // no cached profile to compare against + return; + } + if (state.tbrActive && state.tbrPercent == 0) { + // can't infer base basal rate if TBR is 0 + return; + } + double pumpBasalRate = state.tbrActive + ? state.basalRate * 100 / state.tbrPercent + : state.basalRate; + int pumpHour = new Date(state.pumpTime).getHours(); + int phoneHour = new Date().getHours(); + if (pumpHour != phoneHour) { + // only check if clocks are close + return; + } + + if (pumpBasalRate != getBaseBasalRate()) { + CommandResult readBasalResult = runCommand(MainApp.gs(R.string.combo_actvity_reading_basal_profile), 2, ruffyScripter::readBasalProfile); + if (readBasalResult.success) { + pump.basalProfile = readBasalResult.basalProfile; + } + } + } + /** Check pump time (on the main menu) and raise notification if time is off. * (setting clock is not supported by ruffy) */ private void checkPumpTime(PumpState state) { @@ -1082,7 +1111,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf extendedJson.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName()); PumpState ps = pump.state; if (ps.tbrActive) { - extendedJson.put("TempBasalAbsoluteRate", ps.tbrRate); + extendedJson.put("TempBasalAbsoluteRate", ps.basalRate); extendedJson.put("TempBasalPercent", ps.tbrPercent); extendedJson.put("TempBasalRemaining", ps.tbrRemainingDuration); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java index c6f08ed136..963cdd8b4c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/PumpState.java @@ -13,8 +13,8 @@ public class PumpState { public boolean tbrActive = false; /** TBR percentage. 100% means no TBR active, just the normal basal rate running. */ public int tbrPercent = -1; - /** The absolute rate the TBR is running, e.g. 0.80U/h. */ - public double tbrRate = -1; + /** The absolute rate the pump is running (regular basal rate or TBR), e.g. 0.80U/h. */ + public double basalRate = -1; /** Remaining time of an active TBR. Note that 0:01 is te lowest displayed, the pump * jumps from that to TBR end, skipping 0:00(xx). */ public int tbrRemainingDuration = -1; @@ -52,8 +52,8 @@ public class PumpState { return this; } - public PumpState tbrRate(double tbrRate) { - this.tbrRate = tbrRate; + public PumpState basalRate(double basalRate) { + this.basalRate = basalRate; return this; } @@ -91,7 +91,7 @@ public class PumpState { ", suspended=" + suspended + ", tbrActive=" + tbrActive + ", tbrPercent=" + tbrPercent + - ", tbrRate=" + tbrRate + + ", basalRate=" + basalRate + ", tbrRemainingDuration=" + tbrRemainingDuration + ", activeAlert=" + activeAlert + ", batteryState=" + batteryState + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java index d63c8b165e..9606c2c933 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ruffyscripter/RuffyScripter.java @@ -520,7 +520,7 @@ public class RuffyScripter implements RuffyCommands { state.tbrPercent = displayedTbr.intValue(); MenuTime durationMenuTime = ((MenuTime) menu.getAttribute(MenuAttribute.RUNTIME)); state.tbrRemainingDuration = durationMenuTime.getHour() * 60 + durationMenuTime.getMinute(); - state.tbrRate = ((double) menu.getAttribute(MenuAttribute.BASAL_RATE)); + state.basalRate = ((double) menu.getAttribute(MenuAttribute.BASAL_RATE)); } if (menu.attributes().contains(MenuAttribute.BATTERY_STATE)) { state.batteryState = ((int) menu.getAttribute(MenuAttribute.BATTERY_STATE));