Removed + control for Phone Numbers, Added Tests for TT, Added TARGET STOP/CANCEL command

This commit is contained in:
fabriziocasellato 2019-11-22 15:58:03 +01:00
parent aab9d695fe
commit f26e683dbe
4 changed files with 48 additions and 3 deletions

View file

@ -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<String>, receivedSms: Sms) {

View file

@ -294,6 +294,7 @@
<string name="smscommunicator_bolusreplywithcode">To deliver bolus %1$.2fU reply with code %2$s</string>
<string name="smscommunicator_mealbolusreplywithcode">To deliver meal bolus %1$.2fU reply with code %2$s</string>
<string name="smscommunicator_temptargetwithcode">To set the Temp Target %1$s reply with code %2$s</string>
<string name="smscommunicator_temptargetcancel">To cancel Temp Target reply with code %1$s</string>
<string name="smscommunicator_stopsmswithcode">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.</string>
<string name="smscommunicator_stoppedsms">SMS Remote Service stopped. To reactivate it, use AAPS on master smartphone.</string>
<string name="smscommunicator_calibrationreplywithcode">To send calibration %1$.2f reply with code %2$s</string>
@ -308,6 +309,7 @@
<string name="smscommunicator_mealbolusdelivered">Meal Bolus %1$.2fU delivered successfully</string>
<string name="smscommunicator_mealbolusdelivered_tt">Target %1$s for %2$d minutes</string>
<string name="smscommunicator_tt_set">Target %1$s for %2$d minutes set successfully</string>
<string name="smscommunicator_tt_canceled">Temp Target canceled successfully</string>
<string name="bolusdelivering">Delivering %1$.2fU</string>
<string name="smscommunicator_remotecommandsallowed">Allow remote commands via SMS</string>
<string name="glucosetype_finger">Finger</string>

View file

@ -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");

View file

@ -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