diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/CarbsGenerator.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/CarbsGenerator.java index 90436f5eb2..9eae9b9d07 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/CarbsGenerator.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/CarbsGenerator.java @@ -11,6 +11,7 @@ import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.queue.Callback; +import info.nightscout.utils.T; import static info.nightscout.utils.DateUtil.now; @@ -35,7 +36,7 @@ public class CarbsGenerator { carbInfo.context = MainApp.instance(); carbInfo.source = Source.USER; carbInfo.notes = notes; - if (ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().storesCarbInfo && carbInfo.date <= now()) { + if (ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().storesCarbInfo && carbInfo.date <= now() && carbInfo.date > now()- T.mins(2).msecs()) { ConfigBuilderPlugin.getPlugin().getCommandQueue().bolus(carbInfo, new Callback() { @Override public void run() { @@ -50,6 +51,8 @@ public class CarbsGenerator { } }); } else { + // Don't send to pump if it is in the future or more than 5 minutes in the past + // as pumps might return those as as "now" when reading the history. TreatmentsPlugin.getPlugin().addToHistoryTreatment(carbInfo, false); } }