Make sure that after restart, bolus treatment is added when the app is killed during a bolus

This commit is contained in:
Bart Sopers 2020-08-20 02:20:05 +02:00
parent 557e5ee0e9
commit 0e9adda3a4
5 changed files with 79 additions and 64 deletions

View file

@ -30,6 +30,7 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventAppInitialized;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.ActivePluginProvider;
@ -61,12 +62,14 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInt
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodStatusRequest; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodStatusRequest;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm; import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUITask; import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUITask;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState;
import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService; import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.Round;
@ -87,6 +90,8 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
private final RileyLinkServiceData rileyLinkServiceData; private final RileyLinkServiceData rileyLinkServiceData;
private final ServiceTaskExecutor serviceTaskExecutor; private final ServiceTaskExecutor serviceTaskExecutor;
private final OmnipodPumpStatus omnipodPumpStatus; private final OmnipodPumpStatus omnipodPumpStatus;
private final AapsOmnipodManager aapsOmnipodManager;
private final OmnipodUtil omnipodUtil;
private CompositeDisposable disposable = new CompositeDisposable(); private CompositeDisposable disposable = new CompositeDisposable();
@ -95,7 +100,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
protected boolean isRefresh = false; protected boolean isRefresh = false;
private boolean isInitialized = false; private boolean isInitialized = false;
private RileyLinkOmnipodService rileyLinkOmnipodService; private RileyLinkOmnipodService rileyLinkOmnipodService;
private boolean isBusy = false; private boolean isBusy = false;
@ -119,13 +123,14 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
SP sp, SP sp,
OmnipodPumpStatus omnipodPumpStatus, OmnipodPumpStatus omnipodPumpStatus,
PodStateManager podStateManager, PodStateManager podStateManager,
AapsOmnipodManager aapsOmnipodManager,
CommandQueueProvider commandQueue, CommandQueueProvider commandQueue,
FabricPrivacy fabricPrivacy, FabricPrivacy fabricPrivacy,
RileyLinkServiceData rileyLinkServiceData, RileyLinkServiceData rileyLinkServiceData,
ServiceTaskExecutor serviceTaskExecutor, ServiceTaskExecutor serviceTaskExecutor,
DateUtil dateUtil DateUtil dateUtil,
OmnipodUtil omnipodUtil
) { ) {
super(new PluginDescription() // super(new PluginDescription() //
.mainType(PluginType.PUMP) // .mainType(PluginType.PUMP) //
.fragmentClass(OmnipodFragment.class.getName()) // .fragmentClass(OmnipodFragment.class.getName()) //
@ -134,26 +139,25 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
.preferencesId(R.xml.pref_omnipod) // .preferencesId(R.xml.pref_omnipod) //
.description(R.string.description_pump_omnipod), // .description(R.string.description_pump_omnipod), //
PumpType.Insulet_Omnipod, PumpType.Insulet_Omnipod,
injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy, dateUtil injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy, dateUtil);
);
this.podStateManager = podStateManager; this.podStateManager = podStateManager;
this.rileyLinkServiceData = rileyLinkServiceData; this.rileyLinkServiceData = rileyLinkServiceData;
this.serviceTaskExecutor = serviceTaskExecutor; this.serviceTaskExecutor = serviceTaskExecutor;
this.omnipodPumpStatus = omnipodPumpStatus; this.omnipodPumpStatus = omnipodPumpStatus;
this.aapsOmnipodManager = aapsOmnipodManager;
this.omnipodUtil = omnipodUtil;
displayConnectionMessages = false; displayConnectionMessages = false;
this.serviceConnection = new ServiceConnection() { this.serviceConnection = new ServiceConnection() {
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
aapsLogger.debug(LTag.PUMP, "RileyLinkOmnipodService is disconnected"); aapsLogger.debug(LTag.PUMP, "RileyLinkOmnipodService is disconnected");
rileyLinkOmnipodService = null; rileyLinkOmnipodService = null;
} }
@Override @Override
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
aapsLogger.debug(LTag.PUMP, "RileyLinkOmnipodService is connected"); aapsLogger.debug(LTag.PUMP, "RileyLinkOmnipodService is connected");
RileyLinkOmnipodService.LocalBinder mLocalBinder = (RileyLinkOmnipodService.LocalBinder) service; RileyLinkOmnipodService.LocalBinder mLocalBinder = (RileyLinkOmnipodService.LocalBinder) service;
rileyLinkOmnipodService = mLocalBinder.getServiceInstance(); rileyLinkOmnipodService = mLocalBinder.getServiceInstance();
@ -172,7 +176,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
}).start(); }).start();
} }
}; };
} }
public PodStateManager getPodStateManager() { public PodStateManager getPodStateManager() {
@ -199,6 +202,27 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
rileyLinkOmnipodService.verifyConfiguration(); rileyLinkOmnipodService.verifyConfiguration();
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
); );
disposable.add(rxBus
.toObservable(EventAppInitialized.class)
.observeOn(Schedulers.io())
.subscribe(event -> {
// See if a bolus was active before the app previously exited
// If so, add it to history
// Needs to be done after EventAppInitialized because otherwise, TreatmentsPlugin.onStart() hasn't been called yet
// so it didn't initialize a TreatmentService yet, resulting in a NullPointerException
if (sp.contains(OmnipodConst.Prefs.CurrentBolus)) {
String currentBolusString = sp.getString(OmnipodConst.Prefs.CurrentBolus, "");
aapsLogger.warn(LTag.PUMP, "Found active bolus in SP. Adding Treatment: {}", currentBolusString);
try {
DetailedBolusInfo detailedBolusInfo = omnipodUtil.getGsonInstance().fromJson(currentBolusString, DetailedBolusInfo.class);
aapsOmnipodManager.addBolusToHistory(detailedBolusInfo);
} catch (Exception ex) {
aapsLogger.error(LTag.PUMP, "Failed to add active bolus to history", ex);
}
sp.remove(OmnipodConst.Prefs.CurrentBolus);
}
}, fabricPrivacy::logException)
);
super.onStart(); super.onStart();
} }
@ -215,7 +239,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override @Override
public void initPumpStatusData() { public void initPumpStatusData() {
omnipodPumpStatus.lastConnection = sp.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L); omnipodPumpStatus.lastConnection = sp.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
omnipodPumpStatus.lastDataTime = omnipodPumpStatus.lastConnection; omnipodPumpStatus.lastDataTime = omnipodPumpStatus.lastConnection;
omnipodPumpStatus.previousConnection = omnipodPumpStatus.lastConnection; omnipodPumpStatus.previousConnection = omnipodPumpStatus.lastConnection;
@ -267,7 +290,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
} }
} }
@Override @Override
public Class getServiceClass() { public Class getServiceClass() {
return RileyLinkOmnipodService.class; return RileyLinkOmnipodService.class;
@ -278,20 +300,17 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return this.omnipodPumpStatus; return this.omnipodPumpStatus;
} }
@Override @Override
public String deviceID() { public String deviceID() {
return "Omnipod"; return "Omnipod";
} }
// Pump Plugin // Pump Plugin
private boolean isServiceSet() { private boolean isServiceSet() {
return rileyLinkOmnipodService != null; return rileyLinkOmnipodService != null;
} }
@Override @Override
public boolean isInitialized() { public boolean isInitialized() {
if (displayConnectionMessages) if (displayConnectionMessages)
@ -299,7 +318,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return isServiceSet() && isInitialized; return isServiceSet() && isInitialized;
} }
@Override @Override
public boolean isBusy() { public boolean isBusy() {
if (displayConnectionMessages) if (displayConnectionMessages)
@ -321,19 +339,16 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return false; return false;
} }
@Override @Override
public void resetRileyLinkConfiguration() { public void resetRileyLinkConfiguration() {
rileyLinkOmnipodService.resetRileyLinkConfiguration(); rileyLinkOmnipodService.resetRileyLinkConfiguration();
} }
@Override @Override
public boolean hasTuneUp() { public boolean hasTuneUp() {
return false; return false;
} }
@Override @Override
public void doTuneUpDevice() { public void doTuneUpDevice() {
//rileyLinkOmnipodService.doTuneUpDevice(); //rileyLinkOmnipodService.doTuneUpDevice();
@ -344,7 +359,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
rxBus.send(new EventOmnipodPumpValuesChanged()); rxBus.send(new EventOmnipodPumpValuesChanged());
} }
@Override @Override
public RileyLinkOmnipodService getRileyLinkService() { public RileyLinkOmnipodService getRileyLinkService() {
return rileyLinkOmnipodService; return rileyLinkOmnipodService;
@ -354,7 +368,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return rileyLinkOmnipodService.getDeviceCommandExecutor(); return rileyLinkOmnipodService.getDeviceCommandExecutor();
} }
private synchronized void clearBusyQueue() { private synchronized void clearBusyQueue() {
if (busyTimestamps.size() == 0) { if (busyTimestamps.size() == 0) {
@ -381,7 +394,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
} }
@Override @Override
public boolean isConnected() { public boolean isConnected() {
if (displayConnectionMessages) if (displayConnectionMessages)
@ -389,7 +401,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return isServiceSet() && rileyLinkOmnipodService.isInitialized(); return isServiceSet() && rileyLinkOmnipodService.isInitialized();
} }
@Override @Override
public boolean isConnecting() { public boolean isConnecting() {
if (displayConnectionMessages) if (displayConnectionMessages)
@ -397,7 +408,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return !isServiceSet() || !rileyLinkOmnipodService.isInitialized(); return !isServiceSet() || !rileyLinkOmnipodService.isInitialized();
} }
@Override @Override
public boolean isSuspended() { public boolean isSuspended() {
return !podStateManager.isPodRunning() || podStateManager.isSuspended(); return !podStateManager.isPodRunning() || podStateManager.isSuspended();
@ -405,10 +415,10 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override @Override
public void getPumpStatus() { public void getPumpStatus() {
if (firstRun) { if (firstRun) {
initializePump(!isRefresh); initializePump(!isRefresh);
triggerUIChange(); triggerUIChange();
} else if (!omnipodStatusRequestList.isEmpty()) { } else if (!omnipodStatusRequestList.isEmpty()) {
List<OmnipodStatusRequest> removeList = new ArrayList<>(); List<OmnipodStatusRequest> removeList = new ArrayList<>();
@ -492,14 +502,12 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
isRefresh = true; isRefresh = true;
} }
// FIXME do we actually need this? If a user presses refresh during an action, // FIXME do we actually need this? If a user presses refresh during an action,
// I suppose the GetStatusCommand would just be queued? // I suppose the GetStatusCommand would just be queued?
private void setRefreshButtonEnabled(boolean enabled) { private void setRefreshButtonEnabled(boolean enabled) {
rxBus.send(new EventOmnipodRefreshButtonState(enabled)); rxBus.send(new EventOmnipodRefreshButtonState(enabled));
} }
private void initializePump(boolean realInit) { private void initializePump(boolean realInit) {
aapsLogger.info(LTag.PUMP, getLogPrefix() + "initializePump - start"); aapsLogger.info(LTag.PUMP, getLogPrefix() + "initializePump - start");
@ -532,7 +540,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
this.firstRun = false; this.firstRun = false;
} }
@Override @Override
public boolean isThisProfileSet(Profile profile) { public boolean isThisProfileSet(Profile profile) {
@ -546,7 +553,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return (currentProfile.areProfileBasalPatternsSame(profile)); return (currentProfile.areProfileBasalPatternsSame(profile));
} }
@Override @Override
public long lastDataTime() { public long lastDataTime() {
if (omnipodPumpStatus.lastConnection != 0) { if (omnipodPumpStatus.lastConnection != 0) {
@ -556,7 +562,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return System.currentTimeMillis(); return System.currentTimeMillis();
} }
@Override @Override
public double getBaseBasalRate() { public double getBaseBasalRate() {
@ -568,35 +573,29 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
} }
} }
@Override @Override
public double getReservoirLevel() { public double getReservoirLevel() {
return omnipodPumpStatus.reservoirRemainingUnits; return omnipodPumpStatus.reservoirRemainingUnits;
} }
@Override @Override
public int getBatteryLevel() { public int getBatteryLevel() {
return 75; return 75;
} }
@Override @Override
protected void triggerUIChange() { protected void triggerUIChange() {
rxBus.send(new EventOmnipodPumpValuesChanged()); rxBus.send(new EventOmnipodPumpValuesChanged());
} }
@Override @Override
public boolean isFakingTempsByExtendedBoluses() { public boolean isFakingTempsByExtendedBoluses() {
return false; return false;
} }
@Override @Override
@NonNull @NonNull
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) { protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
aapsLogger.info(LTag.PUMP, getLogPrefix() + "deliverBolus - {}", detailedBolusInfo); aapsLogger.info(LTag.PUMP, getLogPrefix() + "deliverBolus - {}", detailedBolusInfo);
setRefreshButtonEnabled(false); setRefreshButtonEnabled(false);
@ -647,20 +646,17 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
//finishAction("Bolus"); //finishAction("Bolus");
} }
private void incrementStatistics(String statsKey) { private void incrementStatistics(String statsKey) {
long currentCount = sp.getLong(statsKey, 0L); long currentCount = sp.getLong(statsKey, 0L);
currentCount++; currentCount++;
sp.putLong(statsKey, currentCount); sp.putLong(statsKey, currentCount);
} }
// if enforceNew===true current temp basal is canceled and new TBR set (duration is prolonged), // if enforceNew===true current temp basal is canceled and new TBR set (duration is prolonged),
// if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed // if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed
@Override @Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile,
boolean enforceNew) { boolean enforceNew) {
setRefreshButtonEnabled(false); setRefreshButtonEnabled(false);
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes); aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes);
@ -709,7 +705,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return omnipodPumpStatus.getTemporaryBasal(); return omnipodPumpStatus.getTemporaryBasal();
} }
protected void finishAction(String overviewKey) { protected void finishAction(String overviewKey) {
if (overviewKey != null) if (overviewKey != null)
rxBus.send(new EventRefreshOverview(overviewKey, false)); rxBus.send(new EventRefreshOverview(overviewKey, false));
@ -719,7 +714,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
setRefreshButtonEnabled(true); setRefreshButtonEnabled(true);
} }
@Override @Override
public PumpEnactResult cancelTempBasal(boolean enforceNew) { public PumpEnactResult cancelTempBasal(boolean enforceNew) {
@ -802,7 +796,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return result; return result;
} }
// OPERATIONS not supported by Pump or Plugin // OPERATIONS not supported by Pump or Plugin
protected List<CustomAction> customActions = null; protected List<CustomAction> customActions = null;
@ -813,7 +806,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override @Override
public List<CustomAction> getCustomActions() { public List<CustomAction> getCustomActions() {
if (customActions == null) { if (customActions == null) {
this.customActions = Arrays.asList( this.customActions = Arrays.asList(
customActionResetRLConfig //, customActionResetRLConfig //,
@ -829,7 +821,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
OmnipodCustomActionType mcat = (OmnipodCustomActionType) customActionType; OmnipodCustomActionType mcat = (OmnipodCustomActionType) customActionType;
switch (mcat) { switch (mcat) {
case ResetRileyLinkConfiguration: { case ResetRileyLinkConfiguration: {
serviceTaskExecutor.startTask(new ResetRileyLinkConfigurationTask(getInjector())); serviceTaskExecutor.startTask(new ResetRileyLinkConfigurationTask(getInjector()));
} }

View file

@ -71,6 +71,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManage
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodHistoryEntryType; import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodHistoryEntryType;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException; import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -89,6 +90,7 @@ public class AapsOmnipodManager implements IOmnipodManager {
private final ActivePluginProvider activePlugin; private final ActivePluginProvider activePlugin;
private final OmnipodPumpStatus pumpStatus; private final OmnipodPumpStatus pumpStatus;
private final Context context; private final Context context;
private final SP sp;
private final OmnipodManager delegate; private final OmnipodManager delegate;
private DatabaseHelperInterface databaseHelper; private DatabaseHelperInterface databaseHelper;
@ -119,6 +121,7 @@ public class AapsOmnipodManager implements IOmnipodManager {
this.pumpStatus = pumpStatus; this.pumpStatus = pumpStatus;
this.context = context; this.context = context;
this.databaseHelper = databaseHelper; this.databaseHelper = databaseHelper;
this.sp = sp;
delegate = new OmnipodManager(aapsLogger, sp, communicationService, podStateManager); delegate = new OmnipodManager(aapsLogger, sp, communicationService, podStateManager);
} }
@ -271,26 +274,43 @@ public class AapsOmnipodManager implements IOmnipodManager {
showErrorDialog(getStringResource(R.string.omnipod_bolus_failed_uncertain), R.raw.boluserror); showErrorDialog(getStringResource(R.string.omnipod_bolus_failed_uncertain), R.raw.boluserror);
} }
detailedBolusInfo.date = bolusStarted.getTime();
detailedBolusInfo.source = Source.PUMP;
// Store the current bolus for in case the app crashes, gets killed, the phone dies or whatever before the bolus finishes
// If we have a stored value for the current bolus on startup, we'll create a Treatment for it
// However this can potentially be hours later if for example your phone died and you can't charge it
// FIXME !!!
// The proper solution here would be to create a treatment right after the bolus started,
// and update that treatment after the bolus has finished in case the actual units delivered don't match the requested bolus units
// That way, the bolus would immediately be sent to NS so in case the phone dies you could still see the bolus
// Unfortunately this doesn't work because
// a) when cancelling a bolus within a few seconds of starting it, after updating the Treatment,
// we get a new treatment event from NS containing the originally created treatment with the original insulin amount.
// This event is processed in TreatmentService.createTreatmentFromJsonIfNotExists().
// Opposed to what the name of this method suggests, it does createOrUpdate,
// overwriting the insulin delivered with the original value.
// So practically it seems impossible to update a Treatment when using NS
// b) we only send newly created treatments to NS, so the insulin amount in NS would never be updated
//
// I discussed this with the AAPS team but nobody seems to care so we're stuck with this ugly workaround for now
try {
sp.putString(OmnipodConst.Prefs.CurrentBolus, omnipodUtil.getGsonInstance().toJson(detailedBolusInfo));
} catch (Exception ex) {
aapsLogger.error(LTag.PUMP, "Failed to store current bolus to SP", ex);
}
// Wait for the bolus to finish // Wait for the bolus to finish
OmnipodManager.BolusDeliveryResult bolusDeliveryResult = OmnipodManager.BolusDeliveryResult bolusDeliveryResult =
bolusCommandResult.getDeliveryResultSubject().blockingGet(); bolusCommandResult.getDeliveryResultSubject().blockingGet();
double unitsDelivered = bolusDeliveryResult.getUnitsDelivered(); detailedBolusInfo.insulin = bolusDeliveryResult.getUnitsDelivered();
long pumpId = addSuccessToHistory(bolusStarted.getTime(), PodHistoryEntryType.SetBolus, unitsDelivered + ";" + detailedBolusInfo.carbs); addBolusToHistory(detailedBolusInfo);
detailedBolusInfo.date = bolusStarted.getTime(); sp.remove(OmnipodConst.Prefs.CurrentBolus);
detailedBolusInfo.insulin = unitsDelivered;
detailedBolusInfo.pumpId = pumpId;
detailedBolusInfo.source = Source.PUMP;
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false); return new PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(detailedBolusInfo.insulin);
if (podStateManager.hasFaultEvent()) {
showPodFaultErrorDialog(podStateManager.getFaultEvent().getFaultEventCode());
}
return new PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(unitsDelivered);
} }
@Override @Override
@ -310,19 +330,18 @@ public class AapsOmnipodManager implements IOmnipodManager {
} }
} }
long time = System.currentTimeMillis();
String comment = null; String comment = null;
for (int i = 1; delegate.hasActiveBolus(); i++) { for (int i = 1; delegate.hasActiveBolus(); i++) {
aapsLogger.debug(LTag.PUMP, "Attempting to cancel bolus (#{})", i); aapsLogger.debug(LTag.PUMP, "Attempting to cancel bolus (#{})", i);
try { try {
delegate.cancelBolus(isBolusBeepsEnabled()); delegate.cancelBolus(isBolusBeepsEnabled());
aapsLogger.debug(LTag.PUMP, "Successfully cancelled bolus", i); aapsLogger.debug(LTag.PUMP, "Successfully cancelled bolus", i);
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null); addSuccessToHistory(System.currentTimeMillis(), PodHistoryEntryType.CancelBolus, null);
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} catch (PodFaultException ex) { } catch (PodFaultException ex) {
aapsLogger.debug(LTag.PUMP, "Successfully cancelled bolus (implicitly because of a Pod Fault)"); aapsLogger.debug(LTag.PUMP, "Successfully cancelled bolus (implicitly because of a Pod Fault)");
showPodFaultErrorDialog(ex.getFaultEvent().getFaultEventCode(), null); showPodFaultErrorDialog(ex.getFaultEvent().getFaultEventCode(), null);
addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null); addSuccessToHistory(System.currentTimeMillis(), PodHistoryEntryType.CancelBolus, null);
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} catch (Exception ex) { } catch (Exception ex) {
aapsLogger.debug(LTag.PUMP, "Failed to cancel bolus", ex); aapsLogger.debug(LTag.PUMP, "Failed to cancel bolus", ex);
@ -330,7 +349,7 @@ public class AapsOmnipodManager implements IOmnipodManager {
} }
} }
addFailureToHistory(time, PodHistoryEntryType.CancelBolus, comment); addFailureToHistory(System.currentTimeMillis(), PodHistoryEntryType.CancelBolus, comment);
return new PumpEnactResult(injector).success(false).enacted(false).comment(comment); return new PumpEnactResult(injector).success(false).enacted(false).comment(comment);
} }
@ -483,6 +502,12 @@ public class AapsOmnipodManager implements IOmnipodManager {
return delegate.isPodRunning(); return delegate.isPodRunning();
} }
public void addBolusToHistory(DetailedBolusInfo detailedBolusInfo) {
long pumpId = addSuccessToHistory(detailedBolusInfo.date, PodHistoryEntryType.SetBolus, detailedBolusInfo.insulin + ";" + detailedBolusInfo.carbs);
detailedBolusInfo.pumpId = pumpId;
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false);
}
private void reportImplicitlyCanceledTbr() { private void reportImplicitlyCanceledTbr() {
//TreatmentsPlugin plugin = TreatmentsPlugin.getPlugin(); //TreatmentsPlugin plugin = TreatmentsPlugin.getPlugin();
TreatmentsInterface plugin = activePlugin.getActiveTreatments(); TreatmentsInterface plugin = activePlugin.getActiveTreatments();

View file

@ -14,6 +14,7 @@ public class OmnipodConst {
public static class Prefs { public static class Prefs {
public static final String PodState = Prefix + "pod_state"; public static final String PodState = Prefix + "pod_state";
public static final String CurrentBolus = Prefix + "current_bolus";
public static final int BeepBasalEnabled = R.string.key_omnipod_beep_basal_enabled; public static final int BeepBasalEnabled = R.string.key_omnipod_beep_basal_enabled;
public static final int BeepBolusEnabled = R.string.key_omnipod_beep_bolus_enabled; public static final int BeepBolusEnabled = R.string.key_omnipod_beep_bolus_enabled;
public static final int BeepSMBEnabled = R.string.key_omnipod_beep_smb_enabled; public static final int BeepSMBEnabled = R.string.key_omnipod_beep_smb_enabled;
@ -26,11 +27,9 @@ public class OmnipodConst {
public static final String StatsPrefix = "omnipod_"; public static final String StatsPrefix = "omnipod_";
public static final String FirstPumpStart = Prefix + "first_pump_use"; public static final String FirstPumpStart = Prefix + "first_pump_use";
public static final String LastGoodPumpCommunicationTime = Prefix + "lastGoodPumpCommunicationTime"; public static final String LastGoodPumpCommunicationTime = Prefix + "lastGoodPumpCommunicationTime";
//public static final String LastGoodPumpFrequency = Prefix + "LastGoodPumpFrequency";
public static final String TBRsSet = StatsPrefix + "tbrs_set"; public static final String TBRsSet = StatsPrefix + "tbrs_set";
public static final String StandardBoluses = StatsPrefix + "std_boluses_delivered"; public static final String StandardBoluses = StatsPrefix + "std_boluses_delivered";
public static final String SMBBoluses = StatsPrefix + "smb_boluses_delivered"; public static final String SMBBoluses = StatsPrefix + "smb_boluses_delivered";
//public static final String LastPumpHistoryEntry = StatsPrefix + "pump_history_entry";
} }
public static final double POD_PULSE_SIZE = 0.05; public static final double POD_PULSE_SIZE = 0.05;

View file

@ -93,9 +93,9 @@
<string name="omnipod_cmd_suspend_delivery">Suspend Delivery</string> <string name="omnipod_cmd_suspend_delivery">Suspend Delivery</string>
<string name="omnipod_cmd_resume_delivery">Resume Delivery</string> <string name="omnipod_cmd_resume_delivery">Resume Delivery</string>
<string name="omnipod_cmd_unknown_entry">Unknown Entry</string> <string name="omnipod_cmd_unknown_entry">Unknown Entry</string>
<string name="omnipod_cmd_bolus_value">%1$.1f U</string> <string name="omnipod_cmd_bolus_value">%1$.2f U</string>
<string name="omnipod_cmd_bolus_value_with_carbs">%1$.1f U, CH=%2$.1f g</string> <string name="omnipod_cmd_bolus_value_with_carbs">%1$.2f U, CH=%2$.1f g</string>
<string name="omnipod_cmd_tbr_value">Rate: %1$.1f U, Duration: %2$d min</string> <string name="omnipod_cmd_tbr_value">Rate: %1$.2f U, Duration: %2$d min</string>
<string name="omnipod_cmd_reset_pod_desc">If you press <b>OK</b>, the Pod state will be forcibly reset and you will not be able to communicate with the Pod anymore. Do this only if you can not communicate with the Pod anymore. If you can still communicate with the Pod, please use the <b>Deactivate Pod</b> option.</string> <string name="omnipod_cmd_reset_pod_desc">If you press <b>OK</b>, the Pod state will be forcibly reset and you will not be able to communicate with the Pod anymore. Do this only if you can not communicate with the Pod anymore. If you can still communicate with the Pod, please use the <b>Deactivate Pod</b> option.</string>
<string name="omnipod_cmd_pod_history_na">Pod History not available at the moment.</string> <string name="omnipod_cmd_pod_history_na">Pod History not available at the moment.</string>
<string name="omnipod_init_pod_wizard_step1_title">Fill the Pod</string> <string name="omnipod_init_pod_wizard_step1_title">Fill the Pod</string>