SMS PROFILE command
This commit is contained in:
parent
f30f4cbee2
commit
c7c3506b53
7 changed files with 130 additions and 45 deletions
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||||
import info.nightscout.androidaps.events.EventProfileSwitchChange;
|
import info.nightscout.androidaps.events.EventProfileSwitchChange;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
|
@ -139,4 +140,44 @@ public class ProfileFunctions {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ProfileSwitch prepareProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift, long date) {
|
||||||
|
ProfileSwitch profileSwitch = new ProfileSwitch();
|
||||||
|
profileSwitch.date = date;
|
||||||
|
profileSwitch.source = Source.USER;
|
||||||
|
profileSwitch.profileName = profileName;
|
||||||
|
profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString();
|
||||||
|
profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName();
|
||||||
|
profileSwitch.durationInMinutes = duration;
|
||||||
|
profileSwitch.isCPP = percentage != 100 || timeshift != 0;
|
||||||
|
profileSwitch.timeshift = timeshift;
|
||||||
|
profileSwitch.percentage = percentage;
|
||||||
|
return profileSwitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift) {
|
||||||
|
ProfileSwitch profileSwitch = prepareProfileSwitch(profileStore, profileName, duration, percentage, timeshift, System.currentTimeMillis());
|
||||||
|
TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch);
|
||||||
|
FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void doProfileSwitch(final int duration, final int percentage, final int timeshift) {
|
||||||
|
ProfileSwitch profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(System.currentTimeMillis());
|
||||||
|
if (profileSwitch != null) {
|
||||||
|
profileSwitch = new ProfileSwitch();
|
||||||
|
profileSwitch.date = System.currentTimeMillis();
|
||||||
|
profileSwitch.source = Source.USER;
|
||||||
|
profileSwitch.profileName = getInstance().getProfileName(System.currentTimeMillis(), false);
|
||||||
|
profileSwitch.profileJson = getInstance().getProfile().getData().toString();
|
||||||
|
profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName();
|
||||||
|
profileSwitch.durationInMinutes = duration;
|
||||||
|
profileSwitch.isCPP = percentage != 100 || timeshift != 0;
|
||||||
|
profileSwitch.timeshift = timeshift;
|
||||||
|
profileSwitch.percentage = percentage;
|
||||||
|
TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch);
|
||||||
|
FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
||||||
|
} else {
|
||||||
|
log.error("No profile switch existing");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -722,7 +722,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
public void createNSTreatment(JSONObject data) {
|
public void createNSTreatment(JSONObject data) {
|
||||||
if (options.executeProfileSwitch) {
|
if (options.executeProfileSwitch) {
|
||||||
if (data.has("profile")) {
|
if (data.has("profile")) {
|
||||||
doProfileSwitch(profileStore, JsonHelper.safeGetString(data, "profile"), JsonHelper.safeGetInt(data, "duration"), JsonHelper.safeGetInt(data, "percentage"), JsonHelper.safeGetInt(data, "timeshift"));
|
ProfileFunctions.doProfileSwitch(profileStore, JsonHelper.safeGetString(data, "profile"), JsonHelper.safeGetInt(data, "duration"), JsonHelper.safeGetInt(data, "percentage"), JsonHelper.safeGetInt(data, "timeshift"));
|
||||||
}
|
}
|
||||||
} else if (options.executeTempTarget) {
|
} else if (options.executeTempTarget) {
|
||||||
final int duration = JsonHelper.safeGetInt(data, "duration");
|
final int duration = JsonHelper.safeGetInt(data, "duration");
|
||||||
|
@ -746,7 +746,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (JsonHelper.safeGetString(data, "eventType").equals(CareportalEvent.PROFILESWITCH)) {
|
if (JsonHelper.safeGetString(data, "eventType").equals(CareportalEvent.PROFILESWITCH)) {
|
||||||
ProfileSwitch profileSwitch = prepareProfileSwitch(
|
ProfileSwitch profileSwitch = ProfileFunctions.prepareProfileSwitch(
|
||||||
profileStore,
|
profileStore,
|
||||||
JsonHelper.safeGetString(data, "profile"),
|
JsonHelper.safeGetString(data, "profile"),
|
||||||
JsonHelper.safeGetInt(data, "duration"),
|
JsonHelper.safeGetInt(data, "duration"),
|
||||||
|
@ -762,46 +762,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProfileSwitch prepareProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift, long date) {
|
|
||||||
ProfileSwitch profileSwitch = new ProfileSwitch();
|
|
||||||
profileSwitch.date = date;
|
|
||||||
profileSwitch.source = Source.USER;
|
|
||||||
profileSwitch.profileName = profileName;
|
|
||||||
profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString();
|
|
||||||
profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName();
|
|
||||||
profileSwitch.durationInMinutes = duration;
|
|
||||||
profileSwitch.isCPP = percentage != 100 || timeshift != 0;
|
|
||||||
profileSwitch.timeshift = timeshift;
|
|
||||||
profileSwitch.percentage = percentage;
|
|
||||||
return profileSwitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift) {
|
|
||||||
ProfileSwitch profileSwitch = prepareProfileSwitch(profileStore, profileName, duration, percentage, timeshift, System.currentTimeMillis());
|
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch);
|
|
||||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void doProfileSwitch(final int duration, final int percentage, final int timeshift) {
|
|
||||||
ProfileSwitch profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(System.currentTimeMillis());
|
|
||||||
if (profileSwitch != null) {
|
|
||||||
profileSwitch = new ProfileSwitch();
|
|
||||||
profileSwitch.date = System.currentTimeMillis();
|
|
||||||
profileSwitch.source = Source.USER;
|
|
||||||
profileSwitch.profileName = ProfileFunctions.getInstance().getProfileName(System.currentTimeMillis(), false);
|
|
||||||
profileSwitch.profileJson = ProfileFunctions.getInstance().getProfile().getData().toString();
|
|
||||||
profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName();
|
|
||||||
profileSwitch.durationInMinutes = duration;
|
|
||||||
profileSwitch.isCPP = percentage != 100 || timeshift != 0;
|
|
||||||
profileSwitch.timeshift = timeshift;
|
|
||||||
profileSwitch.percentage = percentage;
|
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch);
|
|
||||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
|
||||||
} else {
|
|
||||||
log.error("No profile switch existing");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(Bundle savedInstanceState) {
|
public void onSaveInstanceState(Bundle savedInstanceState) {
|
||||||
savedInstanceState.putString("notesEdit", notesEdit.getText().toString());
|
savedInstanceState.putString("notesEdit", notesEdit.getText().toString());
|
||||||
|
|
|
@ -4,6 +4,7 @@ abstract class SmsAction implements Runnable {
|
||||||
Double aDouble;
|
Double aDouble;
|
||||||
Integer anInteger;
|
Integer anInteger;
|
||||||
Integer secondInteger;
|
Integer secondInteger;
|
||||||
|
String aString;
|
||||||
|
|
||||||
SmsAction() {}
|
SmsAction() {}
|
||||||
|
|
||||||
|
@ -16,6 +17,11 @@ abstract class SmsAction implements Runnable {
|
||||||
this.secondInteger = secondInteger;
|
this.secondInteger = secondInteger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SmsAction(String aString, Integer secondInteger) {
|
||||||
|
this.aString = aString;
|
||||||
|
this.secondInteger = secondInteger;
|
||||||
|
}
|
||||||
|
|
||||||
SmsAction(Integer anInteger) {
|
SmsAction(Integer anInteger) {
|
||||||
this.anInteger = anInteger;
|
this.anInteger = anInteger;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
|
@ -34,6 +35,7 @@ import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
|
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||||
|
@ -184,6 +186,14 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
case "PUMP":
|
case "PUMP":
|
||||||
processPUMP(splitted, receivedSms);
|
processPUMP(splitted, receivedSms);
|
||||||
break;
|
break;
|
||||||
|
case "PROFILE":
|
||||||
|
if (!remoteCommandsAllowed)
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
|
||||||
|
else if (splitted.length == 2 || splitted.length == 3)
|
||||||
|
processPROFILE(splitted, receivedSms);
|
||||||
|
else
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
break;
|
||||||
case "BASAL":
|
case "BASAL":
|
||||||
if (!remoteCommandsAllowed)
|
if (!remoteCommandsAllowed)
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
|
||||||
|
@ -409,6 +419,72 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void processPROFILE(String[] splitted, Sms receivedSms) {
|
||||||
|
// load profiles
|
||||||
|
ProfileInterface anInterface = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface();
|
||||||
|
if (anInterface == null) {
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.notconfigured));
|
||||||
|
receivedSms.processed = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ProfileStore store = anInterface.getProfile();
|
||||||
|
if (store == null) {
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.notconfigured));
|
||||||
|
receivedSms.processed = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final ArrayList<CharSequence> list = store.getProfileList();
|
||||||
|
|
||||||
|
if (splitted[1].toUpperCase().equals("STATUS")) {
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, ProfileFunctions.getInstance().getProfileName()));
|
||||||
|
} else if (splitted[1].toUpperCase().equals("LIST")) {
|
||||||
|
if (list.isEmpty())
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.invalidprofile));
|
||||||
|
else {
|
||||||
|
String reply = "";
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
if (i > 0)
|
||||||
|
reply += "\n";
|
||||||
|
reply += (i + 1) + ". ";
|
||||||
|
reply += list.get(i);
|
||||||
|
}
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
int pindex = SafeParse.stringToInt(splitted[1]);
|
||||||
|
int percentage = 100;
|
||||||
|
if (splitted.length > 2)
|
||||||
|
percentage = SafeParse.stringToInt(splitted[2]);
|
||||||
|
|
||||||
|
if (pindex > list.size())
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
else if (percentage == 0)
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
else if (pindex == 0)
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
else {
|
||||||
|
final Profile profile = store.getSpecificProfile((String) list.get(pindex - 1));
|
||||||
|
if (profile == null)
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.noprofile));
|
||||||
|
else {
|
||||||
|
String passCode = generatePasscode();
|
||||||
|
String reply = String.format(MainApp.gs(R.string.smscommunicator_profilereplywithcode), list.get(pindex - 1), percentage, passCode);
|
||||||
|
receivedSms.processed = true;
|
||||||
|
int finalPercentage = percentage;
|
||||||
|
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction((String) list.get(pindex - 1), finalPercentage) {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ProfileFunctions.doProfileSwitch(store, (String) list.get(pindex - 1), 0, finalPercentage, 0);
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.profileswitchcreated));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
receivedSms.processed = true;
|
||||||
|
}
|
||||||
|
|
||||||
private void processBASAL(String[] splitted, Sms receivedSms) {
|
private void processBASAL(String[] splitted, Sms receivedSms) {
|
||||||
if (splitted[1].toUpperCase().equals("CANCEL") || splitted[1].toUpperCase().equals("STOP")) {
|
if (splitted[1].toUpperCase().equals("CANCEL") || splitted[1].toUpperCase().equals("STOP")) {
|
||||||
String passCode = generatePasscode();
|
String passCode = generatePasscode();
|
||||||
|
|
|
@ -693,7 +693,7 @@ public class ActionStringHandler {
|
||||||
|
|
||||||
//send profile to pumpe
|
//send profile to pumpe
|
||||||
new NewNSTreatmentDialog(); //init
|
new NewNSTreatmentDialog(); //init
|
||||||
NewNSTreatmentDialog.doProfileSwitch(0, percentage, timeshift);
|
ProfileFunctions.doProfileSwitch(0, percentage, timeshift);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void generateTempTarget(int duration, double low, double high) {
|
private static void generateTempTarget(int duration, double low, double high) {
|
||||||
|
|
|
@ -22,7 +22,6 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
|
|
||||||
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.profile.ns.events.EventNSProfileUpdateGUI;
|
import info.nightscout.androidaps.plugins.profile.ns.events.EventNSProfileUpdateGUI;
|
||||||
|
@ -157,7 +156,7 @@ public class NSProfileFragment extends SubscriberFragment {
|
||||||
Profile profile = store.getSpecificProfile(name);
|
Profile profile = store.getSpecificProfile(name);
|
||||||
if (profile != null) {
|
if (profile != null) {
|
||||||
OKDialog.showConfirmation(getActivity(), MainApp.gs(R.string.activate_profile) + ": " + name + " ?", () ->
|
OKDialog.showConfirmation(getActivity(), MainApp.gs(R.string.activate_profile) + ": " + name + " ?", () ->
|
||||||
NewNSTreatmentDialog.doProfileSwitch(store, name, 0, 100, 0)
|
ProfileFunctions.doProfileSwitch(store, name, 0, 100, 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -368,6 +368,7 @@
|
||||||
<string name="smscommunicator_remotecommandnotallowed">Remote command is not allowed</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_remotebolusnotallowed">Remote bolus not available. Try again later.</string>
|
||||||
<string name="smscommunicator_basalreplywithcode">To start basal %1$.2fU/h reply with code %2$s</string>
|
<string name="smscommunicator_basalreplywithcode">To start basal %1$.2fU/h reply with code %2$s</string>
|
||||||
|
<string name="smscommunicator_profilereplywithcode">To switch profile to %1$s %2$d%% reply with code %3$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_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_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_suspendreplywithcode">To suspend loop for %1$d minutes reply with code %2$s</string>
|
||||||
|
@ -1322,6 +1323,8 @@
|
||||||
<string name="diskfull">Free at least %1$d MB from internal storage! Loop disabled!</string>
|
<string name="diskfull">Free at least %1$d MB from internal storage! Loop disabled!</string>
|
||||||
<string name="wrongformat">Wrong format</string>
|
<string name="wrongformat">Wrong format</string>
|
||||||
<string name="sms_wrongcode">Wrong code. Command cancelled.</string>
|
<string name="sms_wrongcode">Wrong code. Command cancelled.</string>
|
||||||
|
<string name="notconfigured">Not configured</string>
|
||||||
|
<string name="profileswitchcreated">Profile switch created</string>
|
||||||
<plurals name="objective_days">
|
<plurals name="objective_days">
|
||||||
<item quantity="one">%1$d day</item>
|
<item quantity="one">%1$d day</item>
|
||||||
<item quantity="other">%1$d days</item>
|
<item quantity="other">%1$d days</item>
|
||||||
|
|
Loading…
Reference in a new issue