Merge branch 'dev' of https://github.com/MilosKozak/AndroidAPS into dev
This commit is contained in:
commit
6826bed92f
3 changed files with 140 additions and 14 deletions
|
@ -85,7 +85,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
"LOOP" to "LOOP STOP/DISABLE/START/ENABLE/RESUME/STATUS\nLOOP SUSPEND 20",
|
||||
"TREATMENTS" to "TREATMENTS REFRESH",
|
||||
"NSCLIENT" to "NSCLIENT RESTART",
|
||||
"PUMP" to "PUMP",
|
||||
"PUMP" to "PUMP\nPUMP CONNECT\nPUMP DISCONNECT 30\n",
|
||||
"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",
|
||||
|
@ -228,7 +228,8 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
if (splitted.size == 2) processNSCLIENT(splitted, receivedSms)
|
||||
else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
|
||||
"PUMP" ->
|
||||
if (splitted.size == 1) processPUMP(receivedSms)
|
||||
if (!remoteCommandsAllowed && splitted.size > 1) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_remotecommandnotallowed)))
|
||||
else if (splitted.size <= 3) processPUMP(splitted, receivedSms)
|
||||
else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
|
||||
"PROFILE" ->
|
||||
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_remotecommandnotallowed)))
|
||||
|
@ -441,7 +442,8 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
|
||||
}
|
||||
|
||||
private fun processPUMP(receivedSms: Sms) {
|
||||
private fun processPUMP(splitted: Array<String>, receivedSms: Sms) {
|
||||
if (splitted.size == 1) {
|
||||
commandQueue.readStatus("SMS", object : Callback() {
|
||||
override fun run() {
|
||||
val pump = activePlugin.activePump
|
||||
|
@ -455,6 +457,51 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
}
|
||||
})
|
||||
receivedSms.processed = true
|
||||
} else if ((splitted.size == 2) && (splitted[1].equals("CONNECT", ignoreCase = true))) {
|
||||
val passCode = generatePasscode()
|
||||
val reply = String.format(resourceHelper.gs(R.string.smscommunicator_pumpconnectwithcode), passCode)
|
||||
receivedSms.processed = true
|
||||
messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() {
|
||||
override fun run() {
|
||||
commandQueue.cancelTempBasal(true, object : Callback() {
|
||||
override fun run() {
|
||||
if (!result.success) {
|
||||
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_pumpconnectfail)))
|
||||
} else {
|
||||
loopPlugin.suspendTo(0L)
|
||||
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_reconnect)))
|
||||
rxBus.send(EventRefreshOverview("SMS_PUMP_START"))
|
||||
loopPlugin.createOfflineEvent(0)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
} else if ((splitted.size == 3) && (splitted[1].equals("DISCONNECT", ignoreCase = true))) {
|
||||
var duration = SafeParse.stringToInt(splitted[2])
|
||||
duration = Math.max(0, duration)
|
||||
duration = Math.min(120, duration)
|
||||
if (duration == 0) {
|
||||
receivedSms.processed = true
|
||||
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_wrongduration)))
|
||||
return
|
||||
} else {
|
||||
val passCode = generatePasscode()
|
||||
val reply = String.format(resourceHelper.gs(R.string.smscommunicator_pumpdisconnectwithcode), duration, passCode)
|
||||
receivedSms.processed = true
|
||||
messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() {
|
||||
override fun run() {
|
||||
val profile = profileFunction.getProfile()
|
||||
loopPlugin.disconnectPump(duration, profile)
|
||||
rxBus.send(EventRefreshOverview("SMS_PUMP_DISCONNECT"))
|
||||
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_pumpdisconnected)))
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat)))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
private fun processPROFILE(splitted: Array<String>, receivedSms: Sms) { // load profiles
|
||||
|
|
|
@ -300,6 +300,11 @@
|
|||
<string name="smscommunicator_loopisenabled">Loop is enabled</string>
|
||||
<string name="valuelimitedto">%1$.2f limited to %2$.2f</string>
|
||||
<string name="valueoutofrange">Value %1$s is out of hard limits</string>
|
||||
<string name="smscommunicator_pumpconnectwithcode">To connect pump reply with code %1$s</string>
|
||||
<string name="smscommunicator_pumpconnectfail">Connection to pump failed</string>
|
||||
<string name="smscommunicator_pumpdisconnectwithcode">To disconnect pump for %1d minutes reply with code %2$s</string>
|
||||
<string name="smscommunicator_pumpdisconnected">Pump disconnected</string>
|
||||
<string name="smscommunicator_reconnect">Pump reconnected</string>
|
||||
<string name="smscommunicator_remotecommandnotallowed">Remote command is not allowed</string>
|
||||
<string name="smscommunicator_remotebolusnotallowed">Remote bolus not available. Try again later.</string>
|
||||
<string name="smscommunicator_basalreplywithcode">To start basal %1$.2fU/h for %2$d min reply with code %3$s</string>
|
||||
|
|
|
@ -226,6 +226,12 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
`when`(resourceHelper.gs(R.string.smscommunicator_loopdisablereplywithcode)).thenReturn("To disable loop reply with code %1\$s")
|
||||
`when`(resourceHelper.gs(R.string.smscommunicator_loopenablereplywithcode)).thenReturn("To enable loop reply with code %1\$s")
|
||||
`when`(resourceHelper.gs(R.string.smscommunicator_loopresumereplywithcode)).thenReturn("To resume loop reply with code %1\$s")
|
||||
`when`(resourceHelper.gs(R.string.smscommunicator_pumpdisconnectwithcode)).thenReturn("To disconnect pump for %1d minutes reply with code %2\$s")
|
||||
`when`(resourceHelper.gs(R.string.smscommunicator_pumpconnectwithcode)).thenReturn("To connect pump reply with code %1\$s")
|
||||
`when`(resourceHelper.gs(R.string.smscommunicator_reconnect)).thenReturn("Pump reconnected")
|
||||
`when`(resourceHelper.gs(R.string.smscommunicator_pumpconnectfail)).thenReturn("Connection to pump failed")
|
||||
`when`(resourceHelper.gs(R.string.smscommunicator_pumpdisconnected)).thenReturn("Pump disconnected")
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -515,6 +521,74 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
Assert.assertEquals("PUMP", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertEquals("Virtual Pump", smsCommunicatorPlugin.messages[1].text)
|
||||
|
||||
//PUMP CONNECT 1 2: wrong format
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "PUMP CONNECT 1 2")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertFalse(sms.ignored)
|
||||
Assert.assertEquals("PUMP CONNECT 1 2", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text)
|
||||
|
||||
//PUMP CONNECT BLABLA
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "PUMP BLABLA")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertFalse(sms.ignored)
|
||||
Assert.assertEquals("PUMP BLABLA", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text)
|
||||
|
||||
//PUMP CONNECT
|
||||
PowerMockito.`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true)
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "PUMP CONNECT")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertFalse(sms.ignored)
|
||||
Assert.assertEquals("PUMP CONNECT", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertTrue(smsCommunicatorPlugin.messages[1].text.contains("To connect pump reply with code "))
|
||||
passCode = smsCommunicatorPlugin.messageToConfirm?.confirmCode!!
|
||||
smsCommunicatorPlugin.processSms(Sms("1234", passCode))
|
||||
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages[2].text)
|
||||
Assert.assertEquals("Pump reconnected", smsCommunicatorPlugin.messages[3].text)
|
||||
|
||||
//PUMP DISCONNECT 1 2: wrong format
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "PUMP DISCONNECT 1 2")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertFalse(sms.ignored)
|
||||
Assert.assertEquals("PUMP DISCONNECT 1 2", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text)
|
||||
|
||||
//PUMP DISCONNECT 0
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "PUMP DISCONNECT 0")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertFalse(sms.ignored)
|
||||
Assert.assertEquals("Wrong duration", smsCommunicatorPlugin.messages[1].text)
|
||||
|
||||
//PUMP DISCONNECT 30
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "PUMP DISCONNECT 30")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertFalse(sms.ignored)
|
||||
Assert.assertEquals("PUMP DISCONNECT 30", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertTrue(smsCommunicatorPlugin.messages[1].text.contains("To disconnect pump for"))
|
||||
passCode = smsCommunicatorPlugin.messageToConfirm?.confirmCode!!
|
||||
smsCommunicatorPlugin.processSms(Sms("1234", passCode))
|
||||
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages[2].text)
|
||||
Assert.assertEquals("Pump disconnected", smsCommunicatorPlugin.messages[3].text)
|
||||
|
||||
//PUMP DISCONNECT 30
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "PUMP DISCONNECT 200")
|
||||
smsCommunicatorPlugin.processSms(sms)
|
||||
Assert.assertFalse(sms.ignored)
|
||||
Assert.assertEquals("PUMP DISCONNECT 200", smsCommunicatorPlugin.messages[0].text)
|
||||
Assert.assertTrue(smsCommunicatorPlugin.messages[1].text.contains("To disconnect pump for"))
|
||||
passCode = smsCommunicatorPlugin.messageToConfirm?.confirmCode!!
|
||||
smsCommunicatorPlugin.processSms(Sms("1234", passCode))
|
||||
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages[2].text)
|
||||
Assert.assertEquals("Pump disconnected", smsCommunicatorPlugin.messages[3].text)
|
||||
|
||||
//HELP
|
||||
smsCommunicatorPlugin.messages = ArrayList()
|
||||
sms = Sms("1234", "HELP")
|
||||
|
|
Loading…
Reference in a new issue