From 56f977df3c3c331b5d1a2abf36fbb97ce7393375 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 8 Mar 2019 23:48:41 +0100 Subject: [PATCH] SMS Plugin allow basal in % --- .../SmsCommunicatorPlugin.java | 46 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 + 2 files changed, 48 insertions(+) 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 daf07f9e2f..0b3f66ea97 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 @@ -9,6 +9,7 @@ import android.telephony.SmsMessage; import com.squareup.otto.Subscribe; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -360,6 +361,51 @@ public class SmsCommunicatorPlugin extends PluginBase { reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed); sendSMS(new Sms(receivedSms.phoneNumber, reply)); } + } else if (splited[1].endsWith("%")) { + int tempBasalPct = SafeParse.stringToInt(StringUtils.removeEnd(splited[1],"%")); + Profile profile = ProfileFunctions.getInstance().getProfile(); + if (profile == null) { + reply = MainApp.gs(R.string.noprofile); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } else if (tempBasalPct == 0 && !splited[1].equals("0%")) { + reply = MainApp.gs(R.string.wrongformat); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } else { + tempBasalPct = MainApp.getConstraintChecker().applyBasalPercentConstraints(new Constraint<>(tempBasalPct), profile).value(); + if (remoteCommandsAllowed) { + passCode = generatePasscode(); + reply = String.format(MainApp.gs(R.string.smscommunicator_basalpctreplywithcode), tempBasalPct, passCode); + receivedSms.processed = true; + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(tempBasalPct) { + @Override + public void run() { + Profile profile = ProfileFunctions.getInstance().getProfile(); + if (profile != null) + ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalPercent(anInteger, 30, true, profile, new Callback() { + @Override + public void run() { + if (result.success) { + String reply; + if (result.isPercent) + reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration); + else + reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply)); + } else { + String reply = MainApp.gs(R.string.smscommunicator_tempbasalfailed); + reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } + }); + } + }); + } else { + reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed); + sendSMS(new Sms(receivedSms.phoneNumber, reply)); + } + } } else { Double tempBasal = SafeParse.stringToDouble(splited[1]); Profile profile = ProfileFunctions.getInstance().getProfile(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b97adda5c7..2974ee86d3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -369,6 +369,7 @@ Remote basal setting is not allowed Remote command is not allowed To start basal %1$.2fU/h reply with code %2$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 Temp basal %1$d %% for %2$d min started successfully @@ -1315,6 +1316,7 @@ Dayligh Saving time change in less than 3 hours - Closed loop diabled internal storage constraint Free at least %1$d MB from internal storage! Loop disabled! + Wrong format %1$d day %1$d days