From 46be73d187b3aed2ac7093a61819e164d8ed5a25 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 25 Dec 2016 14:26:41 +0100 Subject: [PATCH] send sms notification when profile received from NS --- .../androidaps/Services/DataService.java | 21 ++++++++++++++----- .../androidaps/interfaces/PumpInterface.java | 5 ++++- .../ConfigBuilder/ConfigBuilderPlugin.java | 8 ++++--- .../androidaps/plugins/DanaR/DanaRPlugin.java | 8 ++++--- .../DanaRKorean/DanaRKoreanPlugin.java | 8 ++++--- .../VirtualPump/VirtualPumpPlugin.java | 3 ++- 6 files changed, 37 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index 4c7f237feb..a2cadd544c 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -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; @@ -91,7 +93,7 @@ public class DataService extends IntentService { // Objectives 0 ObjectivesPlugin.bgIsAvailableInNS = true; ObjectivesPlugin.saveProgress(); - } else if (isNSProfile && Intents.ACTION_NEW_PROFILE.equals(action)){ + } else if (isNSProfile && Intents.ACTION_NEW_PROFILE.equals(action)) { // always handle Profile if NSProfile is enabled without looking at nsUploadOnly handleNewDataFromNSClient(intent); } else if (!nsUploadOnly && @@ -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 { diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java index 107d7ad372..cde760fc28 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -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 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 0cfdd6b8b2..ccbec0581f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -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); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java index e80c0110db..021372f0b7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java @@ -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; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java index 42dd2e59f9..e4a3d06959 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java @@ -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; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java index df94d1168a..743b7b576a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java @@ -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