send sms notification when profile received from NS

This commit is contained in:
Milos Kozak 2016-12-25 14:26:41 +01:00
parent 61720a74ec
commit 46be73d187
6 changed files with 37 additions and 16 deletions

View file

@ -33,12 +33,14 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.DanaR.History.DanaRNSHistorySync;
import info.nightscout.androidaps.plugins.NSProfile.NSProfilePlugin;
import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
@ -250,8 +252,15 @@ public class DataService extends IntentService {
PumpInterface pump = MainApp.getConfigBuilder();
if (pump != null) {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (SP.getBoolean("syncprofiletopump", false))
pump.setNewBasalProfile(nsProfile);
if (SP.getBoolean("syncprofiletopump", false)) {
if (pump.setNewBasalProfile(nsProfile) == PumpInterface.SUCCESS) {
SmsCommunicatorPlugin smsCommunicatorPlugin = (SmsCommunicatorPlugin) MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class);
if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginBase.GENERAL)) {
smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok));
}
}
}
} else {
log.error("No active pump selected");
}
@ -414,7 +423,8 @@ public class DataService extends IntentService {
if (trJson.has("eventType")) {
treatment.mealBolus = true;
if (trJson.get("eventType").equals("Correction Bolus")) treatment.mealBolus = false;
if (trJson.get("eventType").equals("Bolus Wizard") && treatment.carbs <= 0) treatment.mealBolus = false;
if (trJson.get("eventType").equals("Bolus Wizard") && treatment.carbs <= 0)
treatment.mealBolus = false;
}
treatment.setTimeIndex(treatment.getTimeIndex());
try {
@ -464,7 +474,8 @@ public class DataService extends IntentService {
if (trJson.has("eventType")) {
treatment.mealBolus = true;
if (trJson.get("eventType").equals("Correction Bolus")) treatment.mealBolus = false;
if (trJson.get("eventType").equals("Bolus Wizard") && treatment.carbs <= 0) treatment.mealBolus = false;
if (trJson.get("eventType").equals("Bolus Wizard") && treatment.carbs <= 0)
treatment.mealBolus = false;
}
treatment.setTimeIndex(treatment.getTimeIndex());
try {

View file

@ -22,7 +22,10 @@ public interface PumpInterface {
boolean isExtendedBoluslInProgress();
// Upload to pump new basal profile
void setNewBasalProfile(NSProfile profile);
int SUCCESS = 0;
int FAILED = 1;
int NOT_NEEDED = 2;
int setNewBasalProfile(NSProfile profile);
boolean isThisProfileSet(NSProfile profile);
double getBaseBasalRate(); // base basal rate, not temp basal

View file

@ -49,6 +49,7 @@ import info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
import info.nightscout.client.data.DbLogger;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DateUtil;
@ -334,7 +335,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
}
@Override
public void setNewBasalProfile(NSProfile profile) {
public int setNewBasalProfile(NSProfile profile) {
// Compare with pump limits
NSProfile.BasalValue[] basalValues = profile.getBasalValues();
@ -342,7 +343,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
if (basalValues[index].value < getPumpDescription().basalMinimumRate) {
Notification notification = new Notification(Notification.BASAL_VALUE_BELOW_MINIMUM, MainApp.sResources.getString(R.string.basalvaluebelowminimum), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
return;
return FAILED;
}
}
@ -350,8 +351,9 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
if (isThisProfileSet(profile)) {
log.debug("Correct profile already set");
return NOT_NEEDED;
} else {
activePump.setNewBasalProfile(profile);
return activePump.setNewBasalProfile(profile);
}
}

View file

@ -218,25 +218,27 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
@Override
public void setNewBasalProfile(NSProfile profile) {
public int setNewBasalProfile(NSProfile profile) {
if (sExecutionService == null) {
log.error("setNewBasalProfile sExecutionService is null");
return;
return FAILED;
}
if (!isInitialized()) {
log.error("setNewBasalProfile not initialized");
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
return;
return FAILED;
} else {
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
}
if (!sExecutionService.updateBasalsInPump(profile)) {
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
return FAILED;
} else {
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
return SUCCESS;
}
}

View file

@ -218,25 +218,27 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
}
@Override
public void setNewBasalProfile(NSProfile profile) {
public int setNewBasalProfile(NSProfile profile) {
if (sExecutionService == null) {
log.error("setNewBasalProfile sExecutionService is null");
return;
return FAILED;
}
if (!isInitialized()) {
log.error("setNewBasalProfile not initialized");
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
return;
return FAILED;
} else {
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
}
if (!sExecutionService.updateBasalsInPump(profile)) {
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
return FAILED;
} else {
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
return SUCCESS;
}
}

View file

@ -124,8 +124,9 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
}
@Override
public void setNewBasalProfile(NSProfile profile) {
public int setNewBasalProfile(NSProfile profile) {
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
return SUCCESS;
}
@Override