SMSCommunicator LOOP command auth
This commit is contained in:
parent
c1c87b2e30
commit
8a731a9187
3 changed files with 55 additions and 16 deletions
|
@ -308,6 +308,11 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
when (splitted[1].toUpperCase(Locale.getDefault())) {
|
when (splitted[1].toUpperCase(Locale.getDefault())) {
|
||||||
"DISABLE", "STOP" -> {
|
"DISABLE", "STOP" -> {
|
||||||
if (loopPlugin.isEnabled(PluginType.LOOP)) {
|
if (loopPlugin.isEnabled(PluginType.LOOP)) {
|
||||||
|
val passCode = generatePasscode()
|
||||||
|
val reply = String.format(resourceHelper.gs(R.string.smscommunicator_loopdisablereplywithcode), passCode)
|
||||||
|
receivedSms.processed = true
|
||||||
|
messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() {
|
||||||
|
override fun run() {
|
||||||
loopPlugin.setPluginEnabled(PluginType.LOOP, false)
|
loopPlugin.setPluginEnabled(PluginType.LOOP, false)
|
||||||
commandQueue.cancelTempBasal(true, object : Callback() {
|
commandQueue.cancelTempBasal(true, object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
|
@ -317,6 +322,8 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
sendSMS(Sms(receivedSms.phoneNumber, replyText))
|
sendSMS(Sms(receivedSms.phoneNumber, replyText))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
} else
|
} else
|
||||||
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_loopisdisabled)))
|
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_loopisdisabled)))
|
||||||
receivedSms.processed = true
|
receivedSms.processed = true
|
||||||
|
@ -324,9 +331,16 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
|
|
||||||
"ENABLE", "START" -> {
|
"ENABLE", "START" -> {
|
||||||
if (!loopPlugin.isEnabled(PluginType.LOOP)) {
|
if (!loopPlugin.isEnabled(PluginType.LOOP)) {
|
||||||
|
val passCode = generatePasscode()
|
||||||
|
val reply = String.format(resourceHelper.gs(R.string.smscommunicator_loopenablereplywithcode), passCode)
|
||||||
|
receivedSms.processed = true
|
||||||
|
messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() {
|
||||||
|
override fun run() {
|
||||||
loopPlugin.setPluginEnabled(PluginType.LOOP, true)
|
loopPlugin.setPluginEnabled(PluginType.LOOP, true)
|
||||||
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_loophasbeenenabled)))
|
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_loophasbeenenabled)))
|
||||||
rxBus.send(EventRefreshOverview("SMS_LOOP_START"))
|
rxBus.send(EventRefreshOverview("SMS_LOOP_START"))
|
||||||
|
}
|
||||||
|
})
|
||||||
} else
|
} else
|
||||||
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_loopisenabled)))
|
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_loopisenabled)))
|
||||||
receivedSms.processed = true
|
receivedSms.processed = true
|
||||||
|
@ -343,10 +357,17 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
"RESUME" -> {
|
"RESUME" -> {
|
||||||
|
val passCode = generatePasscode()
|
||||||
|
val reply = String.format(resourceHelper.gs(R.string.smscommunicator_loopresumereplywithcode), passCode)
|
||||||
|
receivedSms.processed = true
|
||||||
|
messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction() {
|
||||||
|
override fun run() {
|
||||||
rxBus.send(EventRefreshOverview("SMS_LOOP_RESUME"))
|
rxBus.send(EventRefreshOverview("SMS_LOOP_RESUME"))
|
||||||
loopPlugin.createOfflineEvent(0)
|
loopPlugin.createOfflineEvent(0)
|
||||||
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_loopresumed)))
|
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_loopresumed)))
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
"SUSPEND" -> {
|
"SUSPEND" -> {
|
||||||
var duration = 0
|
var duration = 0
|
||||||
|
|
|
@ -308,6 +308,9 @@
|
||||||
<string name="smscommunicator_carbsreplywithcode">To enter %1$dg at %2$s reply with code %3$s</string>
|
<string name="smscommunicator_carbsreplywithcode">To enter %1$dg at %2$s reply with code %3$s</string>
|
||||||
<string name="smscommunicator_basalpctreplywithcode">To start basal %1$d%% for %2$d min reply with code %3$s</string>
|
<string name="smscommunicator_basalpctreplywithcode">To start basal %1$d%% for %2$d min reply with code %3$s</string>
|
||||||
<string name="smscommunicator_suspendreplywithcode">To suspend loop for %1$d minutes reply with code %2$s</string>
|
<string name="smscommunicator_suspendreplywithcode">To suspend loop for %1$d minutes reply with code %2$s</string>
|
||||||
|
<string name="smscommunicator_loopresumereplywithcode">To resume loop reply with code %1$s</string>
|
||||||
|
<string name="smscommunicator_loopenablereplywithcode">To enable loop reply with code %1$s</string>
|
||||||
|
<string name="smscommunicator_loopdisablereplywithcode">To disable loop reply with code %1$s</string>
|
||||||
<string name="smscommunicator_tempbasalset">Temp basal %1$.2fU/h for %2$d min started successfully</string>
|
<string name="smscommunicator_tempbasalset">Temp basal %1$.2fU/h for %2$d min started successfully</string>
|
||||||
<string name="smscommunicator_extendedset">Extended bolus %1$.2fU for %2$d min started successfully</string>
|
<string name="smscommunicator_extendedset">Extended bolus %1$.2fU for %2$d min started successfully</string>
|
||||||
<string name="smscommunicator_carbsset">Carbs %1$dg entered successfully</string>
|
<string name="smscommunicator_carbsset">Carbs %1$dg entered successfully</string>
|
||||||
|
|
|
@ -223,6 +223,9 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
`when`(resourceHelper.gs(R.string.smscommunicator_mealbolusdelivered_tt)).thenReturn("Target %1\$s for %2\$d minutes")
|
`when`(resourceHelper.gs(R.string.smscommunicator_mealbolusdelivered_tt)).thenReturn("Target %1\$s for %2\$d minutes")
|
||||||
`when`(resourceHelper.gs(R.string.sms_actualbg)).thenReturn("BG:")
|
`when`(resourceHelper.gs(R.string.sms_actualbg)).thenReturn("BG:")
|
||||||
`when`(resourceHelper.gs(R.string.sms_lastbg)).thenReturn("Last BG:")
|
`when`(resourceHelper.gs(R.string.sms_lastbg)).thenReturn("Last BG:")
|
||||||
|
`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")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -344,7 +347,11 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertFalse(sms.ignored)
|
Assert.assertFalse(sms.ignored)
|
||||||
Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Loop has been disabled Temp basal canceled", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertTrue(smsCommunicatorPlugin.messages[1].text.contains("To disable loop reply with code "))
|
||||||
|
var passCode: String = smsCommunicatorPlugin.messageToConfirm?.confirmCode!!
|
||||||
|
smsCommunicatorPlugin.processSms(Sms("1234", passCode))
|
||||||
|
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages[2].text)
|
||||||
|
Assert.assertEquals("Loop has been disabled Temp basal canceled", smsCommunicatorPlugin.messages[3].text)
|
||||||
Assert.assertTrue(hasBeenRun)
|
Assert.assertTrue(hasBeenRun)
|
||||||
|
|
||||||
//LOOP ENABLE : already enabled
|
//LOOP ENABLE : already enabled
|
||||||
|
@ -368,7 +375,11 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertFalse(sms.ignored)
|
Assert.assertFalse(sms.ignored)
|
||||||
Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Loop has been enabled", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertTrue(smsCommunicatorPlugin.messages[1].text.contains("To enable loop reply with code "))
|
||||||
|
passCode = smsCommunicatorPlugin.messageToConfirm?.confirmCode!!
|
||||||
|
smsCommunicatorPlugin.processSms(Sms("1234", passCode))
|
||||||
|
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages[2].text)
|
||||||
|
Assert.assertEquals("Loop has been enabled", smsCommunicatorPlugin.messages[3].text)
|
||||||
Assert.assertTrue(hasBeenRun)
|
Assert.assertTrue(hasBeenRun)
|
||||||
|
|
||||||
//LOOP RESUME : already enabled
|
//LOOP RESUME : already enabled
|
||||||
|
@ -377,7 +388,11 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assert.assertFalse(sms.ignored)
|
Assert.assertFalse(sms.ignored)
|
||||||
Assert.assertEquals("LOOP RESUME", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("LOOP RESUME", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertEquals("Loop resumed", smsCommunicatorPlugin.messages[1].text)
|
Assert.assertTrue(smsCommunicatorPlugin.messages[1].text.contains("To resume loop reply with code "))
|
||||||
|
passCode = smsCommunicatorPlugin.messageToConfirm?.confirmCode!!
|
||||||
|
smsCommunicatorPlugin.processSms(Sms("1234", passCode))
|
||||||
|
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages[2].text)
|
||||||
|
Assert.assertEquals("Loop resumed", smsCommunicatorPlugin.messages[3].text)
|
||||||
|
|
||||||
//LOOP SUSPEND 1 2: wrong format
|
//LOOP SUSPEND 1 2: wrong format
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
@ -402,7 +417,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
Assert.assertFalse(sms.ignored)
|
Assert.assertFalse(sms.ignored)
|
||||||
Assert.assertEquals("LOOP SUSPEND 100", smsCommunicatorPlugin.messages[0].text)
|
Assert.assertEquals("LOOP SUSPEND 100", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assert.assertTrue(smsCommunicatorPlugin.messages[1].text.contains("To suspend loop for 100 minutes reply with code "))
|
Assert.assertTrue(smsCommunicatorPlugin.messages[1].text.contains("To suspend loop for 100 minutes reply with code "))
|
||||||
var passCode: String = smsCommunicatorPlugin.messageToConfirm?.confirmCode!!
|
passCode = smsCommunicatorPlugin.messageToConfirm?.confirmCode!!
|
||||||
smsCommunicatorPlugin.processSms(Sms("1234", passCode))
|
smsCommunicatorPlugin.processSms(Sms("1234", passCode))
|
||||||
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages[2].text)
|
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages[2].text)
|
||||||
Assert.assertEquals("Loop suspended Temp basal canceled", smsCommunicatorPlugin.messages[3].text)
|
Assert.assertEquals("Loop suspended Temp basal canceled", smsCommunicatorPlugin.messages[3].text)
|
||||||
|
|
Loading…
Reference in a new issue