Check pump basal rate matches cached profile, force re-read otherwise.
This commit is contained in:
parent
9f5ffc6646
commit
262fdf92c8
3 changed files with 36 additions and 7 deletions
|
@ -819,11 +819,40 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
checkForUnsafeUsage(preCheckResult);
|
checkForUnsafeUsage(preCheckResult);
|
||||||
checkAndResolveTbrMismatch(preCheckResult.state);
|
checkAndResolveTbrMismatch(preCheckResult.state);
|
||||||
checkPumpTime(preCheckResult.state);
|
checkPumpTime(preCheckResult.state);
|
||||||
|
checkBasalRate(preCheckResult.state);
|
||||||
checkHistory();
|
checkHistory();
|
||||||
|
|
||||||
return null;
|
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.
|
/** Check pump time (on the main menu) and raise notification if time is off.
|
||||||
* (setting clock is not supported by ruffy) */
|
* (setting clock is not supported by ruffy) */
|
||||||
private void checkPumpTime(PumpState state) {
|
private void checkPumpTime(PumpState state) {
|
||||||
|
@ -1082,7 +1111,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
extendedJson.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
|
extendedJson.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
|
||||||
PumpState ps = pump.state;
|
PumpState ps = pump.state;
|
||||||
if (ps.tbrActive) {
|
if (ps.tbrActive) {
|
||||||
extendedJson.put("TempBasalAbsoluteRate", ps.tbrRate);
|
extendedJson.put("TempBasalAbsoluteRate", ps.basalRate);
|
||||||
extendedJson.put("TempBasalPercent", ps.tbrPercent);
|
extendedJson.put("TempBasalPercent", ps.tbrPercent);
|
||||||
extendedJson.put("TempBasalRemaining", ps.tbrRemainingDuration);
|
extendedJson.put("TempBasalRemaining", ps.tbrRemainingDuration);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ public class PumpState {
|
||||||
public boolean tbrActive = false;
|
public boolean tbrActive = false;
|
||||||
/** TBR percentage. 100% means no TBR active, just the normal basal rate running. */
|
/** TBR percentage. 100% means no TBR active, just the normal basal rate running. */
|
||||||
public int tbrPercent = -1;
|
public int tbrPercent = -1;
|
||||||
/** The absolute rate the TBR is running, e.g. 0.80U/h. */
|
/** The absolute rate the pump is running (regular basal rate or TBR), e.g. 0.80U/h. */
|
||||||
public double tbrRate = -1;
|
public double basalRate = -1;
|
||||||
/** Remaining time of an active TBR. Note that 0:01 is te lowest displayed, the pump
|
/** 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). */
|
* jumps from that to TBR end, skipping 0:00(xx). */
|
||||||
public int tbrRemainingDuration = -1;
|
public int tbrRemainingDuration = -1;
|
||||||
|
@ -52,8 +52,8 @@ public class PumpState {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PumpState tbrRate(double tbrRate) {
|
public PumpState basalRate(double basalRate) {
|
||||||
this.tbrRate = tbrRate;
|
this.basalRate = basalRate;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ public class PumpState {
|
||||||
", suspended=" + suspended +
|
", suspended=" + suspended +
|
||||||
", tbrActive=" + tbrActive +
|
", tbrActive=" + tbrActive +
|
||||||
", tbrPercent=" + tbrPercent +
|
", tbrPercent=" + tbrPercent +
|
||||||
", tbrRate=" + tbrRate +
|
", basalRate=" + basalRate +
|
||||||
", tbrRemainingDuration=" + tbrRemainingDuration +
|
", tbrRemainingDuration=" + tbrRemainingDuration +
|
||||||
", activeAlert=" + activeAlert +
|
", activeAlert=" + activeAlert +
|
||||||
", batteryState=" + batteryState +
|
", batteryState=" + batteryState +
|
||||||
|
|
|
@ -520,7 +520,7 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
state.tbrPercent = displayedTbr.intValue();
|
state.tbrPercent = displayedTbr.intValue();
|
||||||
MenuTime durationMenuTime = ((MenuTime) menu.getAttribute(MenuAttribute.RUNTIME));
|
MenuTime durationMenuTime = ((MenuTime) menu.getAttribute(MenuAttribute.RUNTIME));
|
||||||
state.tbrRemainingDuration = durationMenuTime.getHour() * 60 + durationMenuTime.getMinute();
|
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)) {
|
if (menu.attributes().contains(MenuAttribute.BATTERY_STATE)) {
|
||||||
state.batteryState = ((int) menu.getAttribute(MenuAttribute.BATTERY_STATE));
|
state.batteryState = ((int) menu.getAttribute(MenuAttribute.BATTERY_STATE));
|
||||||
|
|
Loading…
Reference in a new issue