SMS Plugin extended bolus support

This commit is contained in:
Milos Kozak 2019-03-09 09:52:58 +01:00
parent 79b6bc6c43
commit 53721d5d2c
2 changed files with 82 additions and 10 deletions

View file

@ -358,11 +358,11 @@ public class SmsCommunicatorPlugin extends PluginBase {
}
});
} else {
reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed);
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
}
} else if (splited[1].endsWith("%")) {
int tempBasalPct = SafeParse.stringToInt(StringUtils.removeEnd(splited[1],"%"));
int tempBasalPct = SafeParse.stringToInt(StringUtils.removeEnd(splited[1], "%"));
int duration = 30;
if (splited.length > 2)
duration = SafeParse.stringToInt(splited[2]);
@ -405,7 +405,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
}
});
} else {
reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed);
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
}
}
@ -450,7 +450,76 @@ public class SmsCommunicatorPlugin extends PluginBase {
}
});
} else {
reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed);
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
}
}
}
}
break;
case "EXTENDED":
if (splited.length > 1) {
if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) {
if (remoteCommandsAllowed) {
passCode = generatePasscode();
reply = String.format(MainApp.gs(R.string.smscommunicator_extendedstopreplywithcode), passCode);
receivedSms.processed = true;
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() {
@Override
public void run() {
ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelExtended(new Callback() {
@Override
public void run() {
if (result.success) {
String reply = MainApp.gs(R.string.smscommunicator_extendedcanceled);
reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply));
} else {
String reply = MainApp.gs(R.string.smscommunicator_extendedcancelfailed);
reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
}
}
});
}
});
} else {
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
}
} else {
if (splited.length < 3) {
reply = MainApp.gs(R.string.wrongformat);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
} else {
Double extended = SafeParse.stringToDouble(splited[1]);
int duration = SafeParse.stringToInt(splited[2]);
extended = MainApp.getConstraintChecker().applyExtendedBolusConstraints(new Constraint<>(extended)).value();
if (remoteCommandsAllowed) {
passCode = generatePasscode();
reply = String.format(MainApp.gs(R.string.smscommunicator_extendedreplywithcode), extended, duration, passCode);
receivedSms.processed = true;
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(extended, duration) {
@Override
public void run() {
ConfigBuilderPlugin.getPlugin().getCommandQueue().extendedBolus(aDouble, secondInteger, new Callback() {
@Override
public void run() {
if (result.success) {
String reply = String.format(MainApp.gs(R.string.smscommunicator_extendedset), aDouble, duration);
reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply));
} else {
String reply = MainApp.gs(R.string.smscommunicator_extendedfailed);
reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
}
}
});
}
});
} else {
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
}
}
@ -459,7 +528,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
break;
case "BOLUS":
if (System.currentTimeMillis() - lastRemoteBolusTime.getTime() < Constants.remoteBolusMinDistance) {
reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed);
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
} else if (ConfigBuilderPlugin.getPlugin().getActivePump().isSuspended()) {
reply = MainApp.gs(R.string.pumpsuspended);
@ -500,7 +569,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
}
});
} else {
reply = MainApp.gs(R.string.smscommunicator_remotebolusnotallowed);
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
}
}
@ -526,7 +595,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
}
});
} else {
reply = MainApp.gs(R.string.smscommunicator_remotecalibrationnotallowed);
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
}
}

View file

@ -298,7 +298,6 @@
<string name="smscommunicator_bolusdelivered" formatted="false">Bolus %.2fU delivered successfully</string>
<string name="bolusdelivering" formatted="false">Delivering %.2fU</string>
<string name="smscommunicator_remotecommandsallowed">Allow remote commands via SMS</string>
<string name="smscommunicator_remotebolusnotallowed">Remote bolus not allowed</string>
<string name="glucosetype_finger">Finger</string>
<string name="glucosetype_sensor">Sensor</string>
<string name="manual">Manual</string>
@ -366,17 +365,22 @@
<string name="smscommunicator_loopisenabled">Loop is enabled</string>
<string name="valuelimitedto">%1$.2f limited to %2$.2f</string>
<string name="valueoutofrange" formatted="false">Value %s is out of hard limits</string>
<string name="smscommunicator_remotebasalnotallowed">Remote basal setting is not allowed</string>
<string name="smscommunicator_remotecommandnotallowed">Remote command is not allowed</string>
<string name="smscommunicator_basalreplywithcode">To start basal %1$.2fU/h reply with code %2$s</string>
<string name="smscommunicator_extendedreplywithcode">To start extended bolus %1$.2fU for %2$d min reply with code %3$s</string>
<string name="smscommunicator_basalpctreplywithcode">To start basal %1$d%% 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_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_tempbasalset_percent">Temp basal %1$d %% for %2$d min started successfully</string>
<string name="smscommunicator_tempbasalfailed">Temp basal start failed</string>
<string name="smscommunicator_extendedfailed">Extended bolus start failed</string>
<string name="smscommunicator_basalstopreplywithcode" formatted="false">To stop temp basal reply with code %s</string>
<string name="smscommunicator_extendedstopreplywithcode" formatted="false">To stop extended bolus reply with code %s</string>
<string name="smscommunicator_tempbasalcanceled">Temp basal canceled</string>
<string name="smscommunicator_extendedcanceled">Extended bolus canceled</string>
<string name="smscommunicator_tempbasalcancelfailed">Canceling temp basal failed</string>
<string name="smscommunicator_extendedcancelfailed">Canceling extended bolus failed</string>
<string name="smscommunicator_unknowncommand">Uknown command or wrong reply</string>
<string name="quickwizard">QuickWizard</string>
@ -510,7 +514,6 @@
<string name="send_calibration" formatted="false">Send calibration %.1f to xDrip?</string>
<string name="xdripnotinstalled">xDrip+ not installed</string>
<string name="calibrationsent">Calibration sent to xDrip</string>
<string name="smscommunicator_remotecalibrationnotallowed">Remote calibration not allowed</string>
<string name="smscommunicator_calibrationsent">Calibration sent. Receiving must be enabled in xDrip.</string>
<string name="smscommunicator_calibrationfailed">xDrip is not receiving calibrations</string>
<string name="pumpsuspended">Pump suspended</string>