From 53721d5d2c96f7fa5b47c99368c1f20217aa344a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 9 Mar 2019 09:52:58 +0100 Subject: [PATCH] SMS Plugin extended bolus support --- .../SmsCommunicatorPlugin.java | 83 +++++++++++++++++-- app/src/main/res/values/strings.xml | 9 +- 2 files changed, 82 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java index 6ff70602fc..19b62132f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java @@ -358,11 +358,11 @@ public class SmsCommunicatorPlugin extends PluginBase { } }); } else { - reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed); + reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed); sendSMS(new Sms(receivedSms.phoneNumber, reply)); } } else if (splited[1].endsWith("%")) { - int tempBasalPct = SafeParse.stringToInt(StringUtils.removeEnd(splited[1],"%")); + int tempBasalPct = SafeParse.stringToInt(StringUtils.removeEnd(splited[1], "%")); int duration = 30; if (splited.length > 2) duration = SafeParse.stringToInt(splited[2]); @@ -405,7 +405,7 @@ public class SmsCommunicatorPlugin extends PluginBase { } }); } else { - reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed); + reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed); sendSMS(new Sms(receivedSms.phoneNumber, reply)); } } @@ -450,7 +450,76 @@ public class SmsCommunicatorPlugin extends PluginBase { } }); } else { - reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed); + reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } + } + } + break; + case "EXTENDED": + if (splited.length > 1) { + if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) { + if (remoteCommandsAllowed) { + passCode = generatePasscode(); + reply = String.format(MainApp.gs(R.string.smscommunicator_extendedstopreplywithcode), passCode); + receivedSms.processed = true; + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() { + @Override + public void run() { + ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelExtended(new Callback() { + @Override + public void run() { + if (result.success) { + String reply = MainApp.gs(R.string.smscommunicator_extendedcanceled); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply)); + } else { + String reply = MainApp.gs(R.string.smscommunicator_extendedcancelfailed); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } + }); + } + }); + } else { + reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } else { + if (splited.length < 3) { + reply = MainApp.gs(R.string.wrongformat); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } else { + Double extended = SafeParse.stringToDouble(splited[1]); + int duration = SafeParse.stringToInt(splited[2]); + extended = MainApp.getConstraintChecker().applyExtendedBolusConstraints(new Constraint<>(extended)).value(); + if (remoteCommandsAllowed) { + passCode = generatePasscode(); + reply = String.format(MainApp.gs(R.string.smscommunicator_extendedreplywithcode), extended, duration, passCode); + receivedSms.processed = true; + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(extended, duration) { + @Override + public void run() { + ConfigBuilderPlugin.getPlugin().getCommandQueue().extendedBolus(aDouble, secondInteger, new Callback() { + @Override + public void run() { + if (result.success) { + String reply = String.format(MainApp.gs(R.string.smscommunicator_extendedset), aDouble, duration); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply)); + } else { + String reply = MainApp.gs(R.string.smscommunicator_extendedfailed); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } + }); + } + }); + } else { + reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed); sendSMS(new Sms(receivedSms.phoneNumber, reply)); } } @@ -459,7 +528,7 @@ public class SmsCommunicatorPlugin extends PluginBase { break; case "BOLUS": if (System.currentTimeMillis() - lastRemoteBolusTime.getTime() < Constants.remoteBolusMinDistance) { - reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed); + reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed); sendSMS(new Sms(receivedSms.phoneNumber, reply)); } else if (ConfigBuilderPlugin.getPlugin().getActivePump().isSuspended()) { reply = MainApp.gs(R.string.pumpsuspended); @@ -500,7 +569,7 @@ public class SmsCommunicatorPlugin extends PluginBase { } }); } else { - reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed); + reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed); sendSMS(new Sms(receivedSms.phoneNumber, reply)); } } @@ -526,7 +595,7 @@ public class SmsCommunicatorPlugin extends PluginBase { } }); } else { - reply = MainApp.gs(R.string.smscommunicator_remotecalibrationnotallowed); + reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed); sendSMS(new Sms(receivedSms.phoneNumber, reply)); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2974ee86d3..0acebd1ae6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -298,7 +298,6 @@ Bolus %.2fU delivered successfully Delivering %.2fU Allow remote commands via SMS - Remote bolus not allowed Finger Sensor Manual @@ -366,17 +365,22 @@ Loop is enabled %1$.2f limited to %2$.2f Value %s is out of hard limits - Remote basal setting is not allowed Remote command is not allowed To start basal %1$.2fU/h reply with code %2$s + To start extended bolus %1$.2fU for %2$d min reply with code %3$s To start basal %1$d%% reply with code %2$s To suspend loop for %1$d minutes reply with code %2$s Temp basal %1$.2fU/h for %2$d min started successfully + Extended bolus %1$.2fU for %2$d min started successfully Temp basal %1$d %% for %2$d min started successfully Temp basal start failed + Extended bolus start failed To stop temp basal reply with code %s + To stop extended bolus reply with code %s Temp basal canceled + Extended bolus canceled Canceling temp basal failed + Canceling extended bolus failed Uknown command or wrong reply QuickWizard @@ -510,7 +514,6 @@ Send calibration %.1f to xDrip? xDrip+ not installed Calibration sent to xDrip - Remote calibration not allowed Calibration sent. Receiving must be enabled in xDrip. xDrip is not receiving calibrations Pump suspended