From e800bd5092ffff117dc33b9136f71a3d3e5cde84 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 25 Oct 2017 15:09:50 +0200 Subject: [PATCH] Add Command.getReconnectAlarm() to safely confirm alerts caused by an interrupted command. --- .../java/de/jotomo/ruffyscripter/commands/BaseCommand.java | 7 +++++++ .../de/jotomo/ruffyscripter/commands/BolusCommand.java | 7 ++++++- .../de/jotomo/ruffyscripter/commands/CancelTbrCommand.java | 2 +- .../java/de/jotomo/ruffyscripter/commands/Command.java | 1 + .../de/jotomo/ruffyscripter/commands/SetTbrCommand.java | 5 +++++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java index 4d8935bf93..63d6de0d4c 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BaseCommand.java @@ -15,4 +15,11 @@ public abstract class BaseCommand implements Command { public boolean needsRunMode() { return false; } + + // TODO i18n; can we work with error codes instead of messages? Like W07? that way we're language agnostic + // error message ist still needed to cancel TBR though, let next-gen ruffy take care of that? + /** An alarm (or null) caused by a disconnect we can safely confirm on reconnect, + * knowing it's not severe as it was caused by this command. */ + @Override + public String getReconnectAlarm() { return null; } } 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 151ee00e85..b6517af2d6 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/BolusCommand.java @@ -42,6 +42,11 @@ public class BolusCommand extends BaseCommand { return violations; } + @Override + public String getReconnectAlarm() { + return "BOLUS CANCELLED"; + } + @Override public CommandResult execute() { try { @@ -184,7 +189,7 @@ public class BolusCommand extends BaseCommand { } // TODO check date so we don't pick a false record if the previous bolus had the same amount; - // also, report back partial bolus. Just call ReadHsstory(timestamp, boluses=true) cmd ... + // also, report back partial bolus. Just call ReadHistory(timestamp, boluses=true) cmd ... double lastBolusInHistory = (double) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS); if (Math.abs(bolus - lastBolusInHistory) > 0.05) { throw new CommandException().success(false).enacted(true) 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 32d82ea436..d45d84d9d0 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/CancelTbrCommand.java @@ -22,7 +22,7 @@ public class CancelTbrCommand extends BaseCommand { } @Override - public String reconnectAlarm() { + public String getReconnectAlarm() { return "TBR CANCELLED"; } diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/Command.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/Command.java index 267e267659..64a10b6dc5 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/Command.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/Command.java @@ -17,4 +17,5 @@ public interface Command { List validateArguments(); void setScripter(RuffyScripter scripter); boolean needsRunMode(); + String getReconnectAlarm(); } diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java index fd0016533b..d6c0c6aff2 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java @@ -52,6 +52,11 @@ public class SetTbrCommand extends BaseCommand { return violations; } + @Override + public String getReconnectAlarm() { + return "TBR CANCELLED"; + } + @Override public CommandResult execute() { try {