diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index 3202b77c96..920a29ab23 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -153,11 +153,12 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis Bolus bolus = plugin.getPump().lastBolus; if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) { long agoMsc = System.currentTimeMillis() - bolus.timestamp; - double agoHours = agoMsc / 60d / 60d / 1000d; + double bolusMinAgo = agoMsc / 60d / 1000d; + double bolusHoursAgo = agoMsc / 60d / 60d / 1000d; lastBolusView.setText(getString(R.string.combo_last_bolus, bolus.amount, - agoHours, - getString(R.string.hoursago), + bolusMinAgo < 60 ? bolusMinAgo : bolusHoursAgo, + bolusMinAgo < 60 ? getString(R.string.minago) : getString(R.string.hoursago), DateUtil.timeString(bolus.timestamp))); } else { lastBolusView.setText(""); 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 52b62434ff..3fefbf9f0a 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 @@ -542,7 +542,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf log.debug("cancelTempBasal: hard-cancelling TBR since user requested"); commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_cancelling_tbr), 2, ruffyScripter::cancelTbr); - if (commandResult.enacted) { + if (!commandResult.state.tbrActive) { tempBasal = new TemporaryBasal(System.currentTimeMillis()); tempBasal.durationInMinutes = 0; tempBasal.source = Source.USER; @@ -565,7 +565,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf log.debug("cancelTempBasal: changing TBR to " + percentage + "% for 15 mins."); commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_cancelling_tbr), 2, () -> ruffyScripter.setTbr(percentage, 15)); - if (commandResult.enacted) { + if (!commandResult.state.tbrActive) { tempBasal = new TemporaryBasal(System.currentTimeMillis()); tempBasal.durationInMinutes = 15; tempBasal.source = Source.USER; @@ -584,7 +584,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (commandResult != null) { pumpEnactResult.success = commandResult.success; - pumpEnactResult.enacted = commandResult.enacted; + pumpEnactResult.enacted = true; } return pumpEnactResult; } @@ -599,6 +599,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf * NO history, reservoir level fields are updated, this make be done separately if desired. */ private synchronized CommandResult runCommand(String activity, int retries, CommandExecution commandExecution) { + // TODO keep stats of how many commansd failed; if >50% fail raise an alert; + // otherwise all commands could fail, but since we can connect to the pump no 'pump unrechable alert' would be raised. + CommandResult commandResult; try { if (activity != null) { @@ -622,6 +625,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf pump.lastCmdResult = commandResult; pump.lastConnectionAttempt = System.currentTimeMillis(); if (commandResult.success) { + // TOdO is this valid? saying a successful command execution means a successful connect? + // or is the distinction between being able to connect and execute a command successfuly not really meaningful here? pump.lastSuccessfulConnection = pump.lastConnectionAttempt; } } finally { diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java index 7e81b950c7..9dc8c04a35 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -13,6 +13,7 @@ import android.content.SharedPreferences; import android.os.PowerManager; import android.preference.PreferenceManager; +import org.mozilla.javascript.ast.Loop; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,6 +26,7 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Overview.Notification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.utils.SP; @@ -67,7 +69,8 @@ public class KeepAliveReceiver extends BroadcastReceiver { private void checkPump() { final PumpInterface pump = MainApp.getConfigBuilder(); final Profile profile = MainApp.getConfigBuilder().getProfile(); - if (pump != null && profile != null && profile.getBasal() != null) { + // TODO suspended? + if (pump != null && profile != null && profile.getBasal() != null && !LoopPlugin.getPlugin().isSuspended()) { Date lastConnection = pump.lastDataTime(); boolean isStatusOutdated = lastConnection.getTime() + STATUS_UPDATE_FREQUENCY < System.currentTimeMillis(); diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/CommandResult.java b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/CommandResult.java index c564c6112e..8da9a0be0e 100644 --- a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/CommandResult.java +++ b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/CommandResult.java @@ -8,11 +8,6 @@ import de.jotomo.ruffy.spi.history.PumpHistory; public class CommandResult { /** Whether the command was executed successfully. */ public boolean success; - /** Whether any changes were made, e.g. if a the request was to cancel a running TBR, - * but not TBR was active, this will be false. - * @deprecated for bolus, set tbr, set basal profile, set time: check with a second command, don't rely on this*/ - @Deprecated - public boolean enacted; /** Null unless an unhandled exception was raised. */ public Exception exception; /** State of the pump *after* command execution. */ @@ -46,11 +41,6 @@ public class CommandResult { return this; } - public CommandResult enacted(boolean enacted) { - this.enacted = enacted; - return this; - } - public CommandResult duration(String duration) { this.duration = duration; return this; @@ -80,7 +70,6 @@ public class CommandResult { public String toString() { return "CommandResult{" + ", success=" + success + - ", enacted=" + enacted + ", exception=" + exception + ", state=" + state + ", history=" + history + diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index 59529ffcea..a98f6b22fd 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -728,13 +728,13 @@ public class RuffyScripter implements RuffyCommands { @Override public CommandResult getDateAndTime() { - return new CommandResult().success(false).enacted(false); + return new CommandResult().success(false); } @Override public CommandResult setDateAndTime(Date date) { // TODO - return new CommandResult().success(false).enacted(false); + return new CommandResult().success(false); } @Override diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java index d1115f0b1d..b046c4ac2a 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java @@ -78,7 +78,6 @@ public class BolusCommand extends BaseCommand { // confirm bolus scripter.verifyMenuIsDisplayed(MenuType.BOLUS_ENTER); scripter.pressCheckKey(); - result.enacted = true; // the pump displays the entered bolus and waits a few seconds to let user check and cancel while (scripter.getCurrentMenu().getType() == MenuType.BOLUS_ENTER) { diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java index c8a04f33ad..fd21f3fbf0 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java @@ -26,7 +26,6 @@ public class CancelTbrCommand extends BaseCommand { // This is non-critical; when cancelling a TBR and the connection was interrupted // the TBR was cancelled by that. In that case not cancelling anything is fine. result.success = true; - result.enacted = false; return; }