From 501ca5c597911ab6d4bbe701902ae169bd67b162 Mon Sep 17 00:00:00 2001 From: Jamorham Date: Sun, 4 Feb 2018 12:57:10 +0000 Subject: [PATCH] Fix for some TBR cancels getting through --- .../PumpInsight/InsightPumpPlugin.java | 29 ++++++++++++++----- .../plugins/PumpInsight/Mstatus.java | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java index fa84960717..5dd449f8f1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPumpPlugin.java @@ -499,6 +499,12 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints @Override public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) { log("Set TBR %"); + + if (percent == 100) { + // This would cause a cancel if a tbr is in progress so treat as a cancel + return cancelTempBasal(false); + } + final UUID cmd = aSyncTaskRunner(new SetTBRTaskRunner(connector.getServiceConnector(), percent, durationInMinutes), "Set TBR " + percent + "%" + " " + durationInMinutes + "m"); if (cmd == null) { @@ -787,11 +793,14 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints (batteryPercent < 70 ? (StatusItem.Highlight.BAD) : StatusItem.Highlight.NOTICE) : StatusItem.Highlight.NORMAL) : StatusItem.Highlight.GOOD)); l.add(new StatusItem(gs(R.string.pump_reservoir_label), reservoirInUnits + "U")); - - if (statusResult.getCurrentTBRMessage().getPercentage() != 100) { - l.add(new StatusItem(gs(R.string.insight_active_tbr), statusResult.getCurrentTBRMessage().getPercentage() + "% " + gs(R.string.with) + " " - + Helpers.qs(statusResult.getCurrentTBRMessage().getLeftoverTime() - offset_minutes, 0) - + " " + gs(R.string.insight_min_left), StatusItem.Highlight.NOTICE)); + try { + if (statusResult.getCurrentTBRMessage().getPercentage() != 100) { + l.add(new StatusItem(gs(R.string.insight_active_tbr), statusResult.getCurrentTBRMessage().getPercentage() + "% " + gs(R.string.with) + " " + + Helpers.qs(statusResult.getCurrentTBRMessage().getLeftoverTime() - offset_minutes, 0) + + " " + gs(R.string.insight_min_left), StatusItem.Highlight.NOTICE)); + } + } catch (NullPointerException e) { + // currentTBRMessage may be null } } @@ -805,9 +814,13 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints } if (statusResult != null) { - statusActiveBolus(statusResult.getActiveBolusesMessage().getBolus1(), offset_minutes, l); - statusActiveBolus(statusResult.getActiveBolusesMessage().getBolus2(), offset_minutes, l); - statusActiveBolus(statusResult.getActiveBolusesMessage().getBolus3(), offset_minutes, l); + try { + statusActiveBolus(statusResult.getActiveBolusesMessage().getBolus1(), offset_minutes, l); + statusActiveBolus(statusResult.getActiveBolusesMessage().getBolus2(), offset_minutes, l); + statusActiveBolus(statusResult.getActiveBolusesMessage().getBolus3(), offset_minutes, l); + } catch (NullPointerException e) { + // getActiveBolusesMessage() may be null + } } if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/Mstatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/Mstatus.java index aceb172914..57e6da7f2a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/Mstatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/Mstatus.java @@ -18,7 +18,7 @@ class Mstatus { if (success()) { return "OK"; } else { - return (event == null) ? "EVENT IS NULL" : event.message; + return (event == null) ? "EVENT DATA IS NULL - ERROR OR FIREWALL ENABLED?" : event.message; } }