diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index ca288da057..63848dd915 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -39,6 +39,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorP import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.* +import info.nightscout.androidaps.utils.DateUtil.now import io.reactivex.disposables.CompositeDisposable import io.reactivex.schedulers.Schedulers import org.apache.commons.lang3.StringUtils @@ -725,6 +726,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() val isMeal = splitted[1].equals("MEAL", ignoreCase = true) val isActivity = splitted[1].equals("ACTIVITY", ignoreCase = true) val isHypo = splitted[1].equals("HYPO", ignoreCase = true) + val isStop = splitted[1].equals("STOP", ignoreCase = true) || splitted[1].equals("CANCEL", ignoreCase = true) if (isMeal || isActivity || isHypo) { val passCode = generatePasscode() val reply = String.format(MainApp.gs(R.string.smscommunicator_temptargetwithcode), splitted[1].toUpperCase(Locale.getDefault()), passCode) @@ -777,7 +779,30 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() } } }) - } else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) + } else if (isStop) { + val passCode = generatePasscode() + val reply = String.format(MainApp.gs(R.string.smscommunicator_temptargetcancel), passCode) + receivedSms.processed = true + messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction() { + override fun run() { + val currentProfile = ProfileFunctions.getInstance().profile + if (currentProfile != null) { + val tempTarget = TempTarget() + .source(Source.USER) + .date(now()) + .duration(0) + .low(0.0) + .high(0.0) + TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget) + val replyText = String.format(MainApp.gs(R.string.smscommunicator_tt_canceled)) + sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + } else { + sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_unknowncommand)) + } + } + }) + } else + sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) } private fun processSMS(splitted: Array, receivedSms: Sms) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e0b9170631..f65eadd13f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -294,6 +294,7 @@ To deliver bolus %1$.2fU reply with code %2$s To deliver meal bolus %1$.2fU reply with code %2$s To set the Temp Target %1$s reply with code %2$s + To cancel Temp Target reply with code %1$s To disable the SMS Remote Service reply with code %1$s.\n\nKeep in mind that you\'ll able to reactivate it directly from the AAPS master smartphone only. SMS Remote Service stopped. To reactivate it, use AAPS on master smartphone. To send calibration %1$.2f reply with code %2$s @@ -308,6 +309,7 @@ Meal Bolus %1$.2fU delivered successfully Target %1$s for %2$d minutes Target %1$s for %2$d minutes set successfully + Temp Target canceled successfully Delivering %1$.2fU Allow remote commands via SMS Finger diff --git a/app/src/test/java/info/AAPSMocker.java b/app/src/test/java/info/AAPSMocker.java index 510ff09c2b..8385b27701 100644 --- a/app/src/test/java/info/AAPSMocker.java +++ b/app/src/test/java/info/AAPSMocker.java @@ -115,6 +115,13 @@ public class AAPSMocker { when(MainApp.gs(R.string.sms_lastbg)).thenReturn("Last BG:"); when(MainApp.gs(R.string.sms_minago)).thenReturn("%1$dmin ago"); when(MainApp.gs(R.string.smscommunicator_remotecommandnotallowed)).thenReturn("Remote command is not allowed"); + when(MainApp.gs(R.string.smscommunicator_stopsmswithcode)).thenReturn("To disable the SMS Remote Service reply with code %1$s.\\n\\nKeep in mind that you\\'ll able to reactivate it directly from the AAPS master smartphone only."); + when(MainApp.gs(R.string.smscommunicator_mealbolusreplywithcode)).thenReturn("To deliver meal bolus %1$.2fU reply with code %2$s."); + when(MainApp.gs(R.string.smscommunicator_temptargetwithcode)).thenReturn("To set the Temp Target %1$s reply with code %2$s"); + when(MainApp.gs(R.string.smscommunicator_temptargetcancel)).thenReturn("To cancel Temp Target reply with code %1$s"); + when(MainApp.gs(R.string.smscommunicator_stoppedsms)).thenReturn("SMS Remote Service stopped. To reactivate it, use AAPS on master smartphone."); + when(MainApp.gs(R.string.smscommunicator_tt_set)).thenReturn("Target %1$s for %2$d minutes set successfully"); + when(MainApp.gs(R.string.smscommunicator_tt_canceled)).thenReturn("Temp Target canceled successfully"); when(MainApp.gs(R.string.loopsuspendedfor)).thenReturn("Suspended (%1$d m)"); when(MainApp.gs(R.string.smscommunicator_loopisdisabled)).thenReturn("Loop is disabled"); when(MainApp.gs(R.string.smscommunicator_loopisenabled)).thenReturn("Loop is enabled"); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.java index ef43609026..2076991c89 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.java @@ -394,11 +394,22 @@ public class SmsCommunicatorPluginTest { sms = new Sms("1234", "TARGET MEAL"); smsCommunicatorPlugin.processSms(sms); Assert.assertEquals("TARGET MEAL", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To set the Temp Target MEAL reply with code")); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To set the Temp Target")); passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Target MEAL for 45 minutes set successfully")); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("set successfully")); + + //TARGET STOP/CANCEL + smsCommunicatorPlugin.setMessages(new ArrayList<>()); + sms = new Sms("1234", "TARGET STOP"); + smsCommunicatorPlugin.processSms(sms); + Assert.assertEquals("TARGET STOP", smsCommunicatorPlugin.getMessages().get(0).text); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To cancel Temp Target reply with code")); + passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); + Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Temp Target canceled successfully")); } @Test