From 491caadd71a5f713ab3e9d927d04caf5d60356dd Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Fri, 20 Oct 2017 15:23:16 +0200 Subject: [PATCH] Check for active alerts on the pump, confirm and re-raise in AAPS. --- .../plugins/PumpCombo/ComboPlugin.java | 14 ++++++++++++- .../de/jotomo/ruffy/spi/RuffyCommands.java | 5 +++++ .../ruffyscripter/RuffyCommandsV1Impl.java | 5 +++++ .../jotomo/ruffyscripter/RuffyScripter.java | 21 +++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) 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 195217eed6..2e78dd8020 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 @@ -34,6 +34,8 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI; import info.nightscout.utils.DateUtil; @@ -560,8 +562,18 @@ public class ComboPlugin implements PluginBase, PumpInterface { private CommandResult runCommand(String status, CommandExecution commandExecution) { MainApp.bus().post(new EventComboPumpUpdateGUI(status)); - // TODO handle running into WARNING_OR_ERROR ... or scripter? purge it CommandResult commandResult = commandExecution.execute(); + + if (commandResult.state.errorMsg != null) { + CommandResult takeOverAlarmResult = ruffyScripter.takeOverAlarm(); + + Notification notification = new Notification(Notification.IC_MISSING, "Pump alarm: " + takeOverAlarmResult.message + /*ainApp.sResources.getString(R.string.icmissing)*/, Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + + commandResult.state = takeOverAlarmResult.state; + } + pump.lastCmdResult = commandResult; pump.state = commandResult.state; // TOOD diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java index de030a1a40..1adf301228 100644 --- a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java +++ b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java @@ -13,6 +13,11 @@ public interface RuffyCommands { CommandResult cancelTbr(); + /** Confirms an active alarm on the pump. The state returned is the state after the alarm + * has been confirmed. The message field contains the displayed error message that was + * confirmed. */ + CommandResult takeOverAlarm(); + boolean isPumpAvailable(); boolean isPumpBusy(); diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java index 6f29433dd5..12cd48602f 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java @@ -22,6 +22,11 @@ public class RuffyCommandsV1Impl implements RuffyCommands { private RuffyCommandsV1Impl() { } + @Override + public CommandResult takeOverAlarm() { + return delegate.takeOverAlarm(); + } + @Override public CommandResult deliverBolus(double amount, BolusProgressReporter bolusProgressReporter) { return delegate.deliverBolus(amount, bolusProgressReporter); diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index abf3a6cea6..abf9e128ab 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -764,6 +764,27 @@ public class RuffyScripter implements RuffyCommands { return runCommand(new CancelTbrCommand()); } + @Override + public CommandResult takeOverAlarm() { + if (getCurrentMenu().getType() != MenuType.WARNING_OR_ERROR) { + return new CommandResult().success(false).enacted(false).message("No alarm active on the pump"); + } + // confirm alert + verifyMenuIsDisplayed(MenuType.WARNING_OR_ERROR); + pressCheckKey(); + // dismiss alert + verifyMenuIsDisplayed(MenuType.WARNING_OR_ERROR); + pressCheckKey(); + waitForMenuToBeLeft(MenuType.WARNING_OR_ERROR); + + PumpState pumpState = readPumpStateInternal(); + return new CommandResult() + .success(true) + .enacted(false /* well, no treatments were enacted ... */) + .message(pumpState.errorMsg) // todo yikes? + .state(pumpState); + } + @Override public CommandResult readHistory(PumpHistoryRequest request) { return runCommand(new ReadHistoryCommand(request));