Preliminary cleanup in OmnipodPumpStatus
This commit is contained in:
parent
155460c8c0
commit
d9891f2427
7 changed files with 64 additions and 94 deletions
|
@ -25,6 +25,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity
|
||||
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.events.EventOmnipodAcknowledgeAlertsChanged
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState
|
||||
|
@ -66,6 +67,7 @@ class OmnipodFragment : DaggerFragment() {
|
|||
@Inject lateinit var omnipodUtil: OmnipodUtil
|
||||
@Inject lateinit var rileyLinkServiceData: RileyLinkServiceData
|
||||
@Inject lateinit var dateUtil: DateUtil
|
||||
@Inject lateinit var aapsOmnipodManager: AapsOmnipodManager
|
||||
|
||||
// TODO somehow obtain the pumpUnreachableThreshold in order to display last connection time red or white
|
||||
// @Inject lateinit var localAlertUtils: LocalAlertUtils
|
||||
|
@ -181,7 +183,7 @@ class OmnipodFragment : DaggerFragment() {
|
|||
}
|
||||
|
||||
fun setVisibilityOfPodDebugButton() {
|
||||
val isEnabled = sp.getBoolean(OmnipodConst.Prefs.PodDebuggingOptionsEnabled, false)
|
||||
val isEnabled = aapsOmnipodManager.isPodDebuggingOptionsEnabled
|
||||
|
||||
if (isEnabled)
|
||||
omnipod_pod_debug.visibility = View.VISIBLE
|
||||
|
|
|
@ -201,7 +201,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
|
|||
(event.isChanged(getResourceHelper(), R.string.key_omnipod_pod_debugging_options_enabled)) ||
|
||||
(event.isChanged(getResourceHelper(), R.string.key_omnipod_beep_smb_enabled)) ||
|
||||
(event.isChanged(getResourceHelper(), R.string.key_omnipod_timechange_enabled)))
|
||||
rileyLinkOmnipodService.verifyConfiguration();
|
||||
aapsOmnipodManager.reloadSettings();
|
||||
}, fabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(rxBus
|
||||
|
@ -837,9 +837,9 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
|
|||
|
||||
@Override
|
||||
public void timezoneOrDSTChanged(TimeChangeType timeChangeType) {
|
||||
aapsLogger.warn(LTag.PUMP, getLogPrefix() + "Time, Date and/or TimeZone changed. [changeType=" + timeChangeType.name() + ", eventHandlingEnabled=" + omnipodPumpStatus.timeChangeEventEnabled + "]");
|
||||
aapsLogger.warn(LTag.PUMP, getLogPrefix() + "Time, Date and/or TimeZone changed. [changeType=" + timeChangeType.name() + ", eventHandlingEnabled=" + aapsOmnipodManager.isTimeChangeEventEnabled() + "]");
|
||||
|
||||
if (omnipodPumpStatus.timeChangeEventEnabled && podStateManager.isPodRunning()) {
|
||||
if (aapsOmnipodManager.isTimeChangeEventEnabled() && podStateManager.isPodRunning()) {
|
||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "Time,and/or TimeZone changed event received and will be consumed by driver.");
|
||||
this.hasTimeDateOrTimeZoneChanged = true;
|
||||
}
|
||||
|
|
|
@ -92,7 +92,8 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
|
|||
|
||||
@Override
|
||||
public void setPumpDeviceState(PumpDeviceState pumpDeviceState) {
|
||||
this.omnipodPumpStatus.setPumpDeviceState(pumpDeviceState);
|
||||
// Intentionally left blank
|
||||
// We don't use PumpDeviceState in the Omnipod driver
|
||||
}
|
||||
|
||||
public <T extends MessageBlock> T sendCommand(Class<T> responseClass, PodStateManager podStateManager, MessageBlock command) {
|
||||
|
|
|
@ -487,10 +487,6 @@ public class OmnipodManager {
|
|||
return podStateManager.getTime();
|
||||
}
|
||||
|
||||
public boolean isPodRunning() {
|
||||
return podStateManager.isPodRunning();
|
||||
}
|
||||
|
||||
public boolean hasActiveBolus() {
|
||||
synchronized (bolusDataMutex) {
|
||||
return activeBolusData != null;
|
||||
|
@ -501,8 +497,11 @@ public class OmnipodManager {
|
|||
return bolusCommandExecutionSubject;
|
||||
}
|
||||
|
||||
private boolean isPodRunning() {
|
||||
return podStateManager.isPodRunning();
|
||||
}
|
||||
|
||||
// Only works for commands with nonce resyncable message blocks
|
||||
// FIXME method is too big, needs refactoring
|
||||
private StatusResponse executeAndVerify(Supplier<StatusResponse> supplier) {
|
||||
try {
|
||||
return supplier.get();
|
||||
|
|
|
@ -5,15 +5,9 @@ import java.util.Arrays;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
|
||||
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||
|
||||
|
@ -27,8 +21,6 @@ public class OmnipodPumpStatus extends PumpStatus {
|
|||
// We can probably get rid of this class altogether
|
||||
|
||||
private final SP sp;
|
||||
private final RileyLinkUtil rileyLinkUtil;
|
||||
private final RxBusWrapper rxBus;
|
||||
|
||||
public String rileyLinkErrorDescription = null;
|
||||
public String rileyLinkAddress = null;
|
||||
|
@ -43,25 +35,10 @@ public class OmnipodPumpStatus extends PumpStatus {
|
|||
public long tempBasalPumpId;
|
||||
public PumpType pumpType;
|
||||
|
||||
public String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
|
||||
|
||||
public boolean beepBolusEnabled = true;
|
||||
public boolean beepBasalEnabled = true;
|
||||
public boolean beepSMBEnabled = true;
|
||||
public boolean beepTBREnabled = true;
|
||||
public boolean podDebuggingOptionsEnabled = false;
|
||||
public boolean timeChangeEventEnabled = true;
|
||||
|
||||
private PumpDeviceState pumpDeviceState;
|
||||
|
||||
@Inject
|
||||
public OmnipodPumpStatus(SP sp,
|
||||
RxBusWrapper rxBus,
|
||||
RileyLinkUtil rileyLinkUtil) {
|
||||
public OmnipodPumpStatus(SP sp) {
|
||||
super(PumpType.Insulet_Omnipod);
|
||||
this.sp = sp;
|
||||
this.rxBus = rxBus;
|
||||
this.rileyLinkUtil = rileyLinkUtil;
|
||||
initSettings();
|
||||
}
|
||||
|
||||
|
@ -80,13 +57,6 @@ public class OmnipodPumpStatus extends PumpStatus {
|
|||
return this.rileyLinkErrorDescription;
|
||||
}
|
||||
|
||||
// public boolean setNotInPreInit() {
|
||||
// this.inPreInit = false;
|
||||
//
|
||||
// return reconfigureService();
|
||||
// }
|
||||
|
||||
|
||||
public void clearTemporaryBasal() {
|
||||
this.tempBasalStart = 0L;
|
||||
this.tempBasalEnd = 0L;
|
||||
|
@ -96,7 +66,6 @@ public class OmnipodPumpStatus extends PumpStatus {
|
|||
|
||||
|
||||
public TempBasalPair getTemporaryBasal() {
|
||||
|
||||
TempBasalPair tbr = new TempBasalPair();
|
||||
tbr.setDurationMinutes(tempBasalLength);
|
||||
tbr.setInsulinRate(tempBasalAmount);
|
||||
|
@ -116,7 +85,6 @@ public class OmnipodPumpStatus extends PumpStatus {
|
|||
", tempBasalEnd=" + tempBasalEnd +
|
||||
", tempBasalAmount=" + tempBasalAmount +
|
||||
", tempBasalLength=" + tempBasalLength +
|
||||
", regexMac='" + regexMac + '\'' +
|
||||
", lastDataTime=" + lastDataTime +
|
||||
", lastConnection=" + lastConnection +
|
||||
", previousConnection=" + previousConnection +
|
||||
|
@ -144,19 +112,4 @@ public class OmnipodPumpStatus extends PumpStatus {
|
|||
", pumpType=" + pumpType +
|
||||
"} ";
|
||||
}
|
||||
|
||||
|
||||
public PumpDeviceState getPumpDeviceState() {
|
||||
return pumpDeviceState;
|
||||
}
|
||||
|
||||
|
||||
public void setPumpDeviceState(PumpDeviceState pumpDeviceState) {
|
||||
this.pumpDeviceState = pumpDeviceState;
|
||||
|
||||
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(pumpDeviceState, RileyLinkTargetDevice.Omnipod));
|
||||
|
||||
rxBus.send(new EventRileyLinkDeviceStatusChange(pumpDeviceState));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -91,9 +91,15 @@ public class AapsOmnipodManager implements IOmnipodManager {
|
|||
private final OmnipodPumpStatus pumpStatus;
|
||||
private final Context context;
|
||||
private final SP sp;
|
||||
|
||||
private final OmnipodManager delegate;
|
||||
private DatabaseHelperInterface databaseHelper;
|
||||
private final DatabaseHelperInterface databaseHelper;
|
||||
|
||||
private boolean basalBeepsEnabled;
|
||||
private boolean bolusBeepsEnabled;
|
||||
private boolean smbBeepsEnabled;
|
||||
private boolean tbrBeepsEnabled;
|
||||
private boolean podDebuggingOptionsEnabled;
|
||||
private boolean timeChangeEventEnabled;
|
||||
|
||||
@Inject
|
||||
public AapsOmnipodManager(OmnipodCommunicationManager communicationService,
|
||||
|
@ -126,8 +132,19 @@ public class AapsOmnipodManager implements IOmnipodManager {
|
|||
delegate = new OmnipodManager(aapsLogger, sp, communicationService, podStateManager);
|
||||
}
|
||||
|
||||
public PodStateManager getPodStateManager() {
|
||||
return podStateManager;
|
||||
@Inject
|
||||
void onInit() {
|
||||
// this cannot be done in the constructor, as sp is not populated at that time
|
||||
reloadSettings();
|
||||
}
|
||||
|
||||
public void reloadSettings() {
|
||||
basalBeepsEnabled = sp.getBoolean(OmnipodConst.Prefs.BeepBasalEnabled, true);
|
||||
bolusBeepsEnabled = sp.getBoolean(OmnipodConst.Prefs.BeepBolusEnabled, true);
|
||||
smbBeepsEnabled = sp.getBoolean(OmnipodConst.Prefs.BeepSMBEnabled, true);
|
||||
tbrBeepsEnabled = sp.getBoolean(OmnipodConst.Prefs.BeepTBREnabled, true);
|
||||
podDebuggingOptionsEnabled = sp.getBoolean(OmnipodConst.Prefs.PodDebuggingOptionsEnabled, false);
|
||||
timeChangeEventEnabled = sp.getBoolean(OmnipodConst.Prefs.TimeChangeEventEnabled, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -236,7 +253,7 @@ public class AapsOmnipodManager implements IOmnipodManager {
|
|||
|
||||
@Override
|
||||
public PumpEnactResult resetPodStatus() {
|
||||
getPodStateManager().removeState();
|
||||
podStateManager.removeState();
|
||||
|
||||
reportImplicitlyCanceledTbr();
|
||||
|
||||
|
@ -355,7 +372,7 @@ public class AapsOmnipodManager implements IOmnipodManager {
|
|||
|
||||
@Override
|
||||
public PumpEnactResult setTemporaryBasal(TempBasalPair tempBasalPair) {
|
||||
boolean beepsEnabled = isTempBasalBeepsEnabled();
|
||||
boolean beepsEnabled = isTbrBeepsEnabled();
|
||||
long time = System.currentTimeMillis();
|
||||
try {
|
||||
delegate.setTemporaryBasal(PumpType.Insulet_Omnipod.determineCorrectBasalSize(tempBasalPair.getInsulinRate()), Duration.standardMinutes(tempBasalPair.getDurationMinutes()), beepsEnabled, beepsEnabled);
|
||||
|
@ -396,7 +413,7 @@ public class AapsOmnipodManager implements IOmnipodManager {
|
|||
public PumpEnactResult cancelTemporaryBasal() {
|
||||
long time = System.currentTimeMillis();
|
||||
try {
|
||||
delegate.cancelTemporaryBasal(isTempBasalBeepsEnabled());
|
||||
delegate.cancelTemporaryBasal(isTbrBeepsEnabled());
|
||||
addSuccessToHistory(time, PodHistoryEntryType.CancelTemporaryBasalForce, null);
|
||||
} catch (Exception ex) {
|
||||
String comment = handleAndTranslateException(ex);
|
||||
|
@ -498,8 +515,28 @@ public class AapsOmnipodManager implements IOmnipodManager {
|
|||
return delegate.getTime();
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
return delegate.isPodRunning();
|
||||
public boolean isBasalBeepsEnabled() {
|
||||
return basalBeepsEnabled;
|
||||
}
|
||||
|
||||
public boolean isBolusBeepsEnabled() {
|
||||
return bolusBeepsEnabled;
|
||||
}
|
||||
|
||||
public boolean isSmbBeepsEnabled() {
|
||||
return smbBeepsEnabled;
|
||||
}
|
||||
|
||||
public boolean isTbrBeepsEnabled() {
|
||||
return tbrBeepsEnabled;
|
||||
}
|
||||
|
||||
public boolean isPodDebuggingOptionsEnabled() {
|
||||
return podDebuggingOptionsEnabled;
|
||||
}
|
||||
|
||||
public boolean isTimeChangeEventEnabled() {
|
||||
return timeChangeEventEnabled;
|
||||
}
|
||||
|
||||
public void addBolusToHistory(DetailedBolusInfo detailedBolusInfo) {
|
||||
|
@ -675,22 +712,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
|
|||
sendEvent(new EventNewNotification(notification));
|
||||
}
|
||||
|
||||
private boolean isBolusBeepsEnabled() {
|
||||
return this.pumpStatus.beepBolusEnabled;
|
||||
}
|
||||
|
||||
private boolean isSmbBeepsEnabled() {
|
||||
return this.pumpStatus.beepSMBEnabled;
|
||||
}
|
||||
|
||||
private boolean isBasalBeepsEnabled() {
|
||||
return this.pumpStatus.beepBasalEnabled;
|
||||
}
|
||||
|
||||
private boolean isTempBasalBeepsEnabled() {
|
||||
return this.pumpStatus.beepTBREnabled;
|
||||
}
|
||||
|
||||
private String getStringResource(int id, Object... args) {
|
||||
return resourceHelper.gs(id, args);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodMa
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIPostprocessor;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
|
||||
|
||||
|
||||
|
@ -37,6 +36,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
|
|||
*/
|
||||
public class RileyLinkOmnipodService extends RileyLinkService {
|
||||
|
||||
private static final String REGEX_MAC = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
|
||||
|
||||
@Inject OmnipodPumpPlugin omnipodPumpPlugin;
|
||||
@Inject OmnipodPumpStatus omnipodPumpStatus;
|
||||
@Inject OmnipodUtil omnipodUtil;
|
||||
|
@ -110,7 +111,8 @@ public class RileyLinkOmnipodService extends RileyLinkService {
|
|||
|
||||
@Override
|
||||
public void setPumpDeviceState(PumpDeviceState pumpDeviceState) {
|
||||
this.omnipodPumpStatus.setPumpDeviceState(pumpDeviceState);
|
||||
// Intentionally left blank
|
||||
// We don't use PumpDeviceState in the Omnipod driver
|
||||
}
|
||||
|
||||
public class LocalBinder extends Binder {
|
||||
|
@ -139,7 +141,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
|
|||
omnipodPumpStatus.rileyLinkErrorDescription = resourceHelper.gs(R.string.omnipod_error_rileylink_address_invalid);
|
||||
return false;
|
||||
} else {
|
||||
if (!rileyLinkAddress.matches(omnipodPumpStatus.regexMac)) {
|
||||
if (!rileyLinkAddress.matches(REGEX_MAC)) {
|
||||
omnipodPumpStatus.rileyLinkErrorDescription = resourceHelper.gs(R.string.omnipod_error_rileylink_address_invalid);
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "RileyLink address invalid: {}", rileyLinkAddress);
|
||||
} else {
|
||||
|
@ -150,16 +152,8 @@ public class RileyLinkOmnipodService extends RileyLinkService {
|
|||
}
|
||||
}
|
||||
|
||||
this.omnipodPumpStatus.beepBasalEnabled = sp.getBoolean(OmnipodConst.Prefs.BeepBasalEnabled, true);
|
||||
this.omnipodPumpStatus.beepBolusEnabled = sp.getBoolean(OmnipodConst.Prefs.BeepBolusEnabled, true);
|
||||
this.omnipodPumpStatus.beepSMBEnabled = sp.getBoolean(OmnipodConst.Prefs.BeepSMBEnabled, true);
|
||||
this.omnipodPumpStatus.beepTBREnabled = sp.getBoolean(OmnipodConst.Prefs.BeepTBREnabled, true);
|
||||
this.omnipodPumpStatus.podDebuggingOptionsEnabled = sp.getBoolean(OmnipodConst.Prefs.PodDebuggingOptionsEnabled, false);
|
||||
this.omnipodPumpStatus.timeChangeEventEnabled = sp.getBoolean(OmnipodConst.Prefs.TimeChangeEventEnabled, true);
|
||||
rileyLinkServiceData.rileyLinkTargetFrequency = RileyLinkTargetFrequency.Omnipod;
|
||||
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Beeps [basal={}, bolus={}, SMB={}, TBR={}]", this.omnipodPumpStatus.beepBasalEnabled, this.omnipodPumpStatus.beepBolusEnabled, this.omnipodPumpStatus.beepSMBEnabled, this.omnipodPumpStatus.beepTBREnabled);
|
||||
|
||||
reconfigureService();
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Add table
Reference in a new issue