Merge branch 'omnipod_eros_dev' into omnipod_eros_dev_upstream_merge
This commit is contained in:
commit
4a266f9956
5 changed files with 55 additions and 46 deletions
|
@ -7,6 +7,7 @@ import android.content.ServiceConnection;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.Looper;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -34,9 +35,7 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.Source;
|
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventAppInitialized;
|
import info.nightscout.androidaps.events.EventAppInitialized;
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
|
@ -56,7 +55,6 @@ import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
|
||||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
|
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
|
@ -140,9 +138,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
private long nextPodCheck;
|
private long nextPodCheck;
|
||||||
private boolean sentIdToFirebase;
|
private boolean sentIdToFirebase;
|
||||||
private long lastConnectionTimeMillis;
|
private long lastConnectionTimeMillis;
|
||||||
private final Handler loopHandler = new Handler();
|
private final Handler loopHandler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
private final Runnable statusChecker;
|
private final Runnable statusChecker;
|
||||||
|
private OmnipodCommandType currentCommand;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public OmnipodPumpPlugin(
|
public OmnipodPumpPlugin(
|
||||||
|
@ -322,8 +321,11 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
// But it doesn't tell us the duration or amount, so we can only update TBR status in AAPS if
|
// But it doesn't tell us the duration or amount, so we can only update TBR status in AAPS if
|
||||||
// The pod is not running a TBR, while AAPS thinks it is
|
// The pod is not running a TBR, while AAPS thinks it is
|
||||||
if (!podStateManager.isTempBasalRunning()) {
|
if (!podStateManager.isTempBasalRunning()) {
|
||||||
if (activePlugin.getActiveTreatments().isTempBasalInProgress() && !aapsOmnipodManager.hasSuspendedFakeTbr()) {
|
// Only report TBR cancellations if they haven't been explicitly requested
|
||||||
aapsOmnipodManager.reportCancelledTbr();
|
if (currentCommand != OmnipodCommandType.CANCEL_TEMPORARY_BASAL) {
|
||||||
|
if (activePlugin.getActiveTreatments().isTempBasalInProgress() && !aapsOmnipodManager.hasSuspendedFakeTbr()) {
|
||||||
|
aapsOmnipodManager.reportCancelledTbr();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -596,7 +598,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
if (detailedBolusInfo.insulin == 0 && detailedBolusInfo.carbs == 0) {
|
if (detailedBolusInfo.insulin == 0 && detailedBolusInfo.carbs == 0) {
|
||||||
// neither carbs nor bolus requested
|
// neither carbs nor bolus requested
|
||||||
aapsLogger.error("deliverTreatment: Invalid input");
|
aapsLogger.error("deliverTreatment: Invalid input: neither carbs nor insulin are set in treatment");
|
||||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).bolusDelivered(0d).carbsDelivered(0d)
|
return new PumpEnactResult(getInjector()).success(false).enacted(false).bolusDelivered(0d).carbsDelivered(0d)
|
||||||
.comment(getResourceHelper().gs(info.nightscout.androidaps.core.R.string.invalidinput));
|
.comment(getResourceHelper().gs(info.nightscout.androidaps.core.R.string.invalidinput));
|
||||||
} else if (detailedBolusInfo.insulin > 0) {
|
} else if (detailedBolusInfo.insulin > 0) {
|
||||||
|
@ -606,15 +608,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
// no bolus required, carb only treatment
|
// no bolus required, carb only treatment
|
||||||
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
|
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
|
||||||
|
|
||||||
// FIXME do we need this??
|
|
||||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
|
||||||
bolusingEvent.setT(new Treatment());
|
|
||||||
bolusingEvent.getT().isSMB = detailedBolusInfo.isSMB;
|
|
||||||
bolusingEvent.setPercent(100);
|
|
||||||
rxBus.send(bolusingEvent);
|
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, "deliverTreatment: Carb only treatment.");
|
|
||||||
|
|
||||||
return new PumpEnactResult(getInjector()).success(true).enacted(true).bolusDelivered(0d)
|
return new PumpEnactResult(getInjector()).success(true).enacted(true).bolusDelivered(0d)
|
||||||
.carbsDelivered(detailedBolusInfo.carbs).comment(getResourceHelper().gs(info.nightscout.androidaps.core.R.string.common_resultok));
|
.carbsDelivered(detailedBolusInfo.carbs).comment(getResourceHelper().gs(info.nightscout.androidaps.core.R.string.common_resultok));
|
||||||
}
|
}
|
||||||
|
@ -643,7 +636,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
if (tbrCurrent != null && !enforceNew) {
|
if (tbrCurrent != null && !enforceNew) {
|
||||||
if (Round.isSame(tbrCurrent.absoluteRate, absoluteRate)) {
|
if (Round.isSame(tbrCurrent.absoluteRate, absoluteRate)) {
|
||||||
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - No enforceNew and same rate. Exiting.");
|
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - No enforceNew and same rate. Exiting.");
|
||||||
rxBus.send(new EventRefreshOverview("Omnipod command: SetTemporaryBasal", false));
|
|
||||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -665,23 +657,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
if (tbrCurrent == null) {
|
if (tbrCurrent == null) {
|
||||||
aapsLogger.info(LTag.PUMP, "cancelTempBasal - TBR already cancelled.");
|
aapsLogger.info(LTag.PUMP, "cancelTempBasal - TBR already cancelled.");
|
||||||
rxBus.send(new EventRefreshOverview("Omnipod command: CancelTemporaryBasal", false));
|
|
||||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
PumpEnactResult result = executeCommand(OmnipodCommandType.CANCEL_TEMPORARY_BASAL, aapsOmnipodManager::cancelTemporaryBasal);
|
return executeCommand(OmnipodCommandType.CANCEL_TEMPORARY_BASAL, aapsOmnipodManager::cancelTemporaryBasal);
|
||||||
|
|
||||||
if (result.success) {
|
|
||||||
// TODO is this necessary?
|
|
||||||
TemporaryBasal tempBasal = new TemporaryBasal(getInjector()) //
|
|
||||||
.date(System.currentTimeMillis()) //
|
|
||||||
.duration(0) //
|
|
||||||
.source(Source.USER);
|
|
||||||
|
|
||||||
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempBasal);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO improve (i8n and more)
|
// TODO improve (i8n and more)
|
||||||
|
@ -934,17 +913,21 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> T executeCommand(OmnipodCommandType commandType, Supplier<T> supplier) {
|
private <T> T executeCommand(OmnipodCommandType commandType, Supplier<T> supplier) {
|
||||||
aapsLogger.debug(LTag.PUMP, "Executing command: {}", commandType);
|
try {
|
||||||
|
currentCommand = commandType;
|
||||||
|
aapsLogger.debug(LTag.PUMP, "Executing command: {}", commandType);
|
||||||
|
|
||||||
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItemOmnipod(getInjector(), commandType));
|
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItemOmnipod(getInjector(), commandType));
|
||||||
|
|
||||||
T pumpEnactResult = supplier.get();
|
T pumpEnactResult = supplier.get();
|
||||||
|
|
||||||
rxBus.send(new EventRefreshOverview("Omnipod command: " + commandType.name(), false));
|
rxBus.send(new EventRefreshOverview("Omnipod command: " + commandType.name(), false));
|
||||||
|
rxBus.send(new EventOmnipodPumpValuesChanged());
|
||||||
|
|
||||||
rxBus.send(new EventOmnipodPumpValuesChanged());
|
return pumpEnactResult;
|
||||||
|
} finally {
|
||||||
return pumpEnactResult;
|
currentCommand = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean verifyPodAlertConfiguration() {
|
private boolean verifyPodAlertConfiguration() {
|
||||||
|
|
|
@ -12,7 +12,7 @@ public class OmnipodStorageKeys {
|
||||||
public static final int BOLUS_BEEPS_ENABLED = R.string.key_omnipod_bolus_beeps_enabled;
|
public static final int BOLUS_BEEPS_ENABLED = R.string.key_omnipod_bolus_beeps_enabled;
|
||||||
public static final int SMB_BEEPS_ENABLED = R.string.key_omnipod_smb_beeps_enabled;
|
public static final int SMB_BEEPS_ENABLED = R.string.key_omnipod_smb_beeps_enabled;
|
||||||
public static final int TBR_BEEPS_ENABLED = R.string.key_omnipod_tbr_beeps_enabled;
|
public static final int TBR_BEEPS_ENABLED = R.string.key_omnipod_tbr_beeps_enabled;
|
||||||
public static final int SUSPEND_DELIVERY_BUTTON_ENABLED = R.string.key_omnipod_pulse_log_button_enabled;
|
public static final int SUSPEND_DELIVERY_BUTTON_ENABLED = R.string.key_omnipod_suspend_delivery_button_enabled;
|
||||||
public static final int PULSE_LOG_BUTTON_ENABLED = R.string.key_omnipod_pulse_log_button_enabled;
|
public static final int PULSE_LOG_BUTTON_ENABLED = R.string.key_omnipod_pulse_log_button_enabled;
|
||||||
public static final int TIME_CHANGE_EVENT_ENABLED = R.string.key_omnipod_time_change_event_enabled;
|
public static final int TIME_CHANGE_EVENT_ENABLED = R.string.key_omnipod_time_change_event_enabled;
|
||||||
public static final int EXPIRATION_REMINDER_ENABLED = R.string.key_omnipod_expiration_reminder_enabled;
|
public static final int EXPIRATION_REMINDER_ENABLED = R.string.key_omnipod_expiration_reminder_enabled;
|
||||||
|
|
|
@ -46,8 +46,8 @@ public class BolusAction implements OmnipodAction<StatusResponse> {
|
||||||
podStateManager.getCurrentNonce(), bolusDeliverySchedule);
|
podStateManager.getCurrentNonce(), bolusDeliverySchedule);
|
||||||
BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(units, timeBetweenPulses,
|
BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(units, timeBetweenPulses,
|
||||||
acknowledgementBeep, completionBeep);
|
acknowledgementBeep, completionBeep);
|
||||||
OmnipodMessage primeBolusMessage = new OmnipodMessage(podStateManager.getAddress(),
|
OmnipodMessage bolusMessage = new OmnipodMessage(podStateManager.getAddress(),
|
||||||
Arrays.asList(setInsulinScheduleCommand, bolusExtraCommand), podStateManager.getMessageNumber());
|
Arrays.asList(setInsulinScheduleCommand, bolusExtraCommand), podStateManager.getMessageNumber());
|
||||||
return communicationService.exchangeMessages(StatusResponse.class, podStateManager, primeBolusMessage);
|
return communicationService.exchangeMessages(StatusResponse.class, podStateManager, bolusMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -374,7 +374,7 @@ public class AapsOmnipodManager {
|
||||||
|
|
||||||
sp.remove(OmnipodStorageKeys.Preferences.ACTIVE_BOLUS);
|
sp.remove(OmnipodStorageKeys.Preferences.ACTIVE_BOLUS);
|
||||||
|
|
||||||
return new PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(detailedBolusInfo.insulin);
|
return new PumpEnactResult(injector).success(true).enacted(true).carbsDelivered(detailedBolusInfo.carbs).bolusDelivered(detailedBolusInfo.insulin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PumpEnactResult cancelBolus() {
|
public PumpEnactResult cancelBolus() {
|
||||||
|
@ -464,13 +464,22 @@ public class AapsOmnipodManager {
|
||||||
public PumpEnactResult cancelTemporaryBasal() {
|
public PumpEnactResult cancelTemporaryBasal() {
|
||||||
try {
|
try {
|
||||||
delegate.cancelTemporaryBasal(isTbrBeepsEnabled());
|
delegate.cancelTemporaryBasal(isTbrBeepsEnabled());
|
||||||
addSuccessToHistory(PodHistoryEntryType.CANCEL_TEMPORARY_BASAL, null);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
String comment = handleAndTranslateException(ex);
|
String comment = handleAndTranslateException(ex);
|
||||||
addFailureToHistory(PodHistoryEntryType.CANCEL_TEMPORARY_BASAL, comment);
|
addFailureToHistory(PodHistoryEntryType.CANCEL_TEMPORARY_BASAL, comment);
|
||||||
return new PumpEnactResult(injector).success(false).enacted(false).comment(comment);
|
return new PumpEnactResult(injector).success(false).enacted(false).comment(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long pumpId = addSuccessToHistory(PodHistoryEntryType.CANCEL_TEMPORARY_BASAL, null);
|
||||||
|
|
||||||
|
TemporaryBasal tempBasal = new TemporaryBasal(injector) //
|
||||||
|
.date(System.currentTimeMillis()) //
|
||||||
|
.duration(0) //
|
||||||
|
.pumpId(pumpId) //
|
||||||
|
.source(Source.PUMP);
|
||||||
|
|
||||||
|
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempBasal);
|
||||||
|
|
||||||
return new PumpEnactResult(injector).success(true).enacted(true);
|
return new PumpEnactResult(injector).success(true).enacted(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,9 +577,25 @@ public class AapsOmnipodManager {
|
||||||
return timeChangeEventEnabled;
|
return timeChangeEventEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBolusToHistory(DetailedBolusInfo detailedBolusInfo) {
|
public void addBolusToHistory(DetailedBolusInfo originalDetailedBolusInfo) {
|
||||||
|
DetailedBolusInfo detailedBolusInfo = originalDetailedBolusInfo.copy();
|
||||||
|
|
||||||
long pumpId = addSuccessToHistory(detailedBolusInfo.date, PodHistoryEntryType.SET_BOLUS, detailedBolusInfo.insulin + ";" + detailedBolusInfo.carbs);
|
long pumpId = addSuccessToHistory(detailedBolusInfo.date, PodHistoryEntryType.SET_BOLUS, detailedBolusInfo.insulin + ";" + detailedBolusInfo.carbs);
|
||||||
detailedBolusInfo.pumpId = pumpId;
|
detailedBolusInfo.pumpId = pumpId;
|
||||||
|
|
||||||
|
if (detailedBolusInfo.carbs > 0 && detailedBolusInfo.carbTime > 0) {
|
||||||
|
// split out a separate carbs record without a pumpId
|
||||||
|
DetailedBolusInfo carbInfo = new DetailedBolusInfo();
|
||||||
|
carbInfo.date = detailedBolusInfo.date + detailedBolusInfo.carbTime * 60L * 1000L;
|
||||||
|
carbInfo.carbs = detailedBolusInfo.carbs;
|
||||||
|
carbInfo.source = Source.USER;
|
||||||
|
activePlugin.getActiveTreatments().addToHistoryTreatment(carbInfo, false);
|
||||||
|
|
||||||
|
// remove carbs from bolusInfo to not trigger any unwanted code paths in
|
||||||
|
// TreatmentsPlugin.addToHistoryTreatment() method
|
||||||
|
detailedBolusInfo.carbTime = 0;
|
||||||
|
detailedBolusInfo.carbs = 0;
|
||||||
|
}
|
||||||
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false);
|
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,7 +659,7 @@ public class AapsOmnipodManager {
|
||||||
.date(time) //
|
.date(time) //
|
||||||
.duration(tempBasalPair.getDurationMinutes()) //
|
.duration(tempBasalPair.getDurationMinutes()) //
|
||||||
.absolute(tempBasalPair.getInsulinRate()) //
|
.absolute(tempBasalPair.getInsulinRate()) //
|
||||||
.pumpId(pumpId)
|
.pumpId(pumpId) //
|
||||||
.source(Source.PUMP);
|
.source(Source.PUMP);
|
||||||
|
|
||||||
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempStart);
|
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempStart);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -71,7 +72,7 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
|
|
||||||
private var disposables: CompositeDisposable = CompositeDisposable()
|
private var disposables: CompositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
private val loopHandler = Handler()
|
private val loopHandler = Handler(Looper.getMainLooper())
|
||||||
private lateinit var refreshLoop: Runnable
|
private lateinit var refreshLoop: Runnable
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
Loading…
Reference in a new issue