SMS HELP command
This commit is contained in:
parent
e9aa4835ed
commit
17ea3843ae
2 changed files with 48 additions and 6 deletions
|
@ -46,9 +46,6 @@ import org.slf4j.LoggerFactory
|
||||||
import java.text.Normalizer
|
import java.text.Normalizer
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 05.08.2016.
|
|
||||||
*/
|
|
||||||
object SmsCommunicatorPlugin : PluginBase(PluginDescription()
|
object SmsCommunicatorPlugin : PluginBase(PluginDescription()
|
||||||
.mainType(PluginType.GENERAL)
|
.mainType(PluginType.GENERAL)
|
||||||
.fragmentClass(SmsCommunicatorFragment::class.java.name)
|
.fragmentClass(SmsCommunicatorFragment::class.java.name)
|
||||||
|
@ -64,6 +61,23 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
|
||||||
var lastRemoteBolusTime: Long = 0
|
var lastRemoteBolusTime: Long = 0
|
||||||
var messages = ArrayList<Sms>()
|
var messages = ArrayList<Sms>()
|
||||||
|
|
||||||
|
val commands = mapOf(
|
||||||
|
"BG" to "BG",
|
||||||
|
"LOOP" to "LOOP STOP/DISABLE/START/ENABLE/RESUME/STATUS\nLOOP SUSPEND 20",
|
||||||
|
"TREATMENTS" to "TREATMENTS REFRESH",
|
||||||
|
"NSCLIENT" to "NSCLIENT RESTART",
|
||||||
|
"PUMP" to "PUMP",
|
||||||
|
"BASAL" to "BASAL STOP/CANCEL\nBASAL 0.3\nBASAL 0.3 20\nBASAL 30%\nBASAL 30% 20\n",
|
||||||
|
"BOLUS" to "BOLUS 1.2\nBOLUS 1.2 MEAL",
|
||||||
|
"EXTENDED" to "EXTENDED STOP/CANCEL\nEXTENDED 2 120",
|
||||||
|
"CAL" to "CAL 5.6",
|
||||||
|
"PROFILE" to "PROFILE STATUS/LIST\nPROFILE 1\nPROFILE 2 30",
|
||||||
|
"TARGET" to "TARGET MEAL/ACTIVITY/HYPO/STOP",
|
||||||
|
"SMS" to "SMS DISABLE/STOP",
|
||||||
|
"CARBS" to "CARBS 12\nCARBS 12 23:05\nCARBS 12 11:05PM",
|
||||||
|
"HELP" to "HELP\nHELP command"
|
||||||
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
processSettings(null)
|
processSettings(null)
|
||||||
}
|
}
|
||||||
|
@ -135,10 +149,11 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isCommand(command: String, number: String): Boolean {
|
fun isCommand(command: String, number: String): Boolean {
|
||||||
when (command.toUpperCase(Locale.getDefault())) {
|
var found = false
|
||||||
"BG", "LOOP", "TREATMENTS", "NSCLIENT", "PUMP", "BASAL", "BOLUS", "EXTENDED", "CAL", "PROFILE", "TARGET", "SMS", "CARBS" -> return true
|
commands.forEach { (k, _) ->
|
||||||
|
if (k == command) found = true
|
||||||
}
|
}
|
||||||
return messageToConfirm?.requester?.phoneNumber == number
|
return found || messageToConfirm?.requester?.phoneNumber == number
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isAllowedNumber(number: String): Boolean {
|
fun isAllowedNumber(number: String): Boolean {
|
||||||
|
@ -226,6 +241,9 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
|
||||||
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed))
|
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed))
|
||||||
else if (splitted.size == 2) processSMS(splitted, receivedSms)
|
else if (splitted.size == 2) processSMS(splitted, receivedSms)
|
||||||
else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
||||||
|
"HELP" ->
|
||||||
|
if (splitted.size == 1 || splitted.size == 2) processHELP(splitted, receivedSms)
|
||||||
|
else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
||||||
else ->
|
else ->
|
||||||
if (messageToConfirm?.requester?.phoneNumber == receivedSms.phoneNumber) {
|
if (messageToConfirm?.requester?.phoneNumber == receivedSms.phoneNumber) {
|
||||||
messageToConfirm?.action(splitted[0])
|
messageToConfirm?.action(splitted[0])
|
||||||
|
@ -365,6 +383,17 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
|
||||||
sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun processHELP(splitted: Array<String>, receivedSms: Sms) {
|
||||||
|
if (splitted.size == 1) {
|
||||||
|
sendSMS(Sms(receivedSms.phoneNumber, commands.keys.toString().replace("[", "").replace("]", "")))
|
||||||
|
receivedSms.processed = true
|
||||||
|
} else if (isCommand(splitted[1].toUpperCase(Locale.getDefault()), receivedSms.phoneNumber)) {
|
||||||
|
sendSMS(Sms(receivedSms.phoneNumber, commands[splitted[1].toUpperCase(Locale.getDefault())]))
|
||||||
|
receivedSms.processed = true
|
||||||
|
} else
|
||||||
|
sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
||||||
|
}
|
||||||
|
|
||||||
private fun processPUMP(receivedSms: Sms) {
|
private fun processPUMP(receivedSms: Sms) {
|
||||||
ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("SMS", object : Callback() {
|
ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("SMS", object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
|
|
|
@ -348,6 +348,19 @@ public class SmsCommunicatorPluginTest {
|
||||||
Assert.assertEquals("PUMP", smsCommunicatorPlugin.getMessages().get(0).text);
|
Assert.assertEquals("PUMP", smsCommunicatorPlugin.getMessages().get(0).text);
|
||||||
Assert.assertEquals("Virtual Pump", smsCommunicatorPlugin.getMessages().get(1).text);
|
Assert.assertEquals("Virtual Pump", smsCommunicatorPlugin.getMessages().get(1).text);
|
||||||
|
|
||||||
|
//HELP
|
||||||
|
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
||||||
|
sms = new Sms("1234", "HELP");
|
||||||
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
|
Assert.assertEquals("HELP", smsCommunicatorPlugin.getMessages().get(0).text);
|
||||||
|
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("PUMP"));
|
||||||
|
|
||||||
|
//HELP PUMP
|
||||||
|
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
||||||
|
sms = new Sms("1234", "HELP PUMP");
|
||||||
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
|
Assert.assertEquals("HELP PUMP", smsCommunicatorPlugin.getMessages().get(0).text);
|
||||||
|
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("PUMP"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue