From 843fccb86cc413bb88004fe0c2f3cb1f17f56777 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 22 Mar 2020 11:54:31 +0100 Subject: [PATCH 1/3] SmsCommunicatorPlugin.processCARBS: set source on record. --- .../plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index 0021574812..41c28bbf21 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -713,6 +713,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() override fun run() { val detailedBolusInfo = DetailedBolusInfo() detailedBolusInfo.carbs = anInteger().toDouble() + detailedBolusInfo.source = Source.USER detailedBolusInfo.date = secondLong() ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() { override fun run() { From e7c7ce32bb085ed228cc0663b58061dd0d7aa4d0 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 22 Mar 2020 11:57:29 +0100 Subject: [PATCH 2/3] TreatmentService.createOrUpdate: log invalid argument. --- .../androidaps/plugins/treatments/TreatmentService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java index 1b118da1d3..eae623267e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java @@ -280,6 +280,10 @@ public class TreatmentService extends OrmLiteBaseService { // return true if new record is created public UpdateReturn createOrUpdate(Treatment treatment) { + if (treatment != null && treatment.source == Source.NONE) { + log.error("Coder error: source is not set for treatment: " + treatment, new Exception()); + FabricPrivacy.logException(new Exception("Coder error: source is not set for treatment: " + treatment)); + } try { Treatment old; treatment.date = DatabaseHelper.roundDateToSec(treatment.date); From fce6ec8d2581ed3becfa82a6c17ab3c42a0c88cf Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 24 Mar 2020 21:27:38 +0100 Subject: [PATCH 3/3] SmsCommunicator: only ask pump with support to add carbs. This aligns with how this is generally handles elsewhere: check if a pump supports carbs and if not, don't bother the driver but add the carbs directly via TreatmentsPlugin. --- .../smsCommunicator/SmsCommunicatorPlugin.kt | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index 41c28bbf21..433acf9403 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -715,19 +715,26 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() detailedBolusInfo.carbs = anInteger().toDouble() detailedBolusInfo.source = Source.USER detailedBolusInfo.date = secondLong() - ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() { - override fun run() { - if (result.success) { - var replyText = String.format(MainApp.gs(R.string.smscommunicator_carbsset), anInteger) - replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true) - sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) - } else { - var replyText = MainApp.gs(R.string.smscommunicator_carbsfailed) - replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true) - sendSMS(Sms(receivedSms.phoneNumber, replyText)) + if (ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription?.storesCarbInfo == true) { + ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() { + override fun run() { + if (result.success) { + var replyText = String.format(MainApp.gs(R.string.smscommunicator_carbsset), anInteger) + replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true) + sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + } else { + var replyText = MainApp.gs(R.string.smscommunicator_carbsfailed) + replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true) + sendSMS(Sms(receivedSms.phoneNumber, replyText)) + } } - } - }) + }) + } else { + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true) + var replyText = String.format(MainApp.gs(R.string.smscommunicator_carbsset), anInteger) + replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true) + sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) + } } }) }