Small cleanup in OmnipodPumpPlugin
This commit is contained in:
parent
f0041c2776
commit
fef12ae06b
|
@ -291,13 +291,13 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
// last bolus
|
// last bolus
|
||||||
if (podStateManager.lastBolusStartTime != null && podStateManager.lastBolusAmount != null) {
|
if (podStateManager.lastBolusStartTime != null && podStateManager.lastBolusAmount != null) {
|
||||||
val ago = readableDuration(podStateManager.lastBolusStartTime)
|
val ago = readableDuration(podStateManager.lastBolusStartTime)
|
||||||
omnipod_lastbolus.text = resourceHelper.gs(R.string.omnipod_last_bolus, omnipodPumpPlugin.pumpType.determineCorrectBolusSize(podStateManager.lastBolusAmount), resourceHelper.gs(R.string.insulin_unit_shortname), ago)
|
omnipod_lastbolus.text = resourceHelper.gs(R.string.omnipod_last_bolus, omnipodPumpPlugin.model().determineCorrectBolusSize(podStateManager.lastBolusAmount), resourceHelper.gs(R.string.insulin_unit_shortname), ago)
|
||||||
} else {
|
} else {
|
||||||
omnipod_lastbolus.text = "-"
|
omnipod_lastbolus.text = "-"
|
||||||
}
|
}
|
||||||
|
|
||||||
// base basal rate
|
// base basal rate
|
||||||
omnipod_basabasalrate.text = resourceHelper.gs(R.string.pump_basebasalrate, omnipodPumpPlugin.pumpType.determineCorrectBasalSize(omnipodPumpPlugin.baseBasalRate))
|
omnipod_basabasalrate.text = resourceHelper.gs(R.string.pump_basebasalrate, omnipodPumpPlugin.model().determineCorrectBasalSize(omnipodPumpPlugin.baseBasalRate))
|
||||||
|
|
||||||
omnipod_tempbasal.text = activePlugin.activeTreatments
|
omnipod_tempbasal.text = activePlugin.activeTreatments
|
||||||
.getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "-"
|
.getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "-"
|
||||||
|
|
|
@ -222,6 +222,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
// TODO either find a more elegant solution, or at least make sure this is the right place to do this
|
// TODO either find a more elegant solution, or at least make sure this is the right place to do this
|
||||||
podStateManager.loadPodState();
|
podStateManager.loadPodState();
|
||||||
|
|
||||||
|
initPumpStatusData();
|
||||||
|
|
||||||
Intent intent = new Intent(context, RileyLinkOmnipodService.class);
|
Intent intent = new Intent(context, RileyLinkOmnipodService.class);
|
||||||
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||||
serviceRunning = true;
|
serviceRunning = true;
|
||||||
|
@ -306,14 +308,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
omnipodPumpStatus.lastDataTime = omnipodPumpStatus.lastConnection;
|
omnipodPumpStatus.lastDataTime = omnipodPumpStatus.lastConnection;
|
||||||
omnipodPumpStatus.previousConnection = omnipodPumpStatus.lastConnection;
|
omnipodPumpStatus.previousConnection = omnipodPumpStatus.lastConnection;
|
||||||
|
|
||||||
rileyLinkOmnipodService.verifyConfiguration();
|
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, "initPumpStatusData: " + this.omnipodPumpStatus);
|
aapsLogger.debug(LTag.PUMP, "initPumpStatusData: " + this.omnipodPumpStatus);
|
||||||
|
|
||||||
// set first Omnipod Pump Start
|
|
||||||
if (!sp.contains(OmnipodConst.Statistics.FirstPumpStart)) {
|
|
||||||
sp.putLong(OmnipodConst.Statistics.FirstPumpStart, System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doPodCheck() {
|
private void doPodCheck() {
|
||||||
|
@ -355,9 +350,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "isBusy");
|
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "isBusy");
|
||||||
|
|
||||||
if (isServiceSet()) {
|
if (isServiceSet()) {
|
||||||
if (busy || !podStateManager.isPodRunning()) {
|
return busy || !podStateManager.isPodRunning();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -386,10 +379,18 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
return new RileyLinkPumpInfo(pumpDescription, frequency, connectedModel, serialNumber);
|
return new RileyLinkPumpInfo(pumpDescription, frequency, connectedModel, serialNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the last successful RileyLink communication
|
||||||
|
* For actual communication with the Pod, we use PodStateManager
|
||||||
|
*/
|
||||||
@Override public long getLastConnectionTimeMillis() {
|
@Override public long getLastConnectionTimeMillis() {
|
||||||
return omnipodPumpStatus.lastConnection;
|
return omnipodPumpStatus.lastConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only use for setting last successful RileyLink communication to now
|
||||||
|
* For actual communication with the Pod, we use PodStateManager
|
||||||
|
*/
|
||||||
@Override public void setLastCommunicationToNow() {
|
@Override public void setLastCommunicationToNow() {
|
||||||
omnipodPumpStatus.setLastCommunicationToNow();
|
omnipodPumpStatus.setLastCommunicationToNow();
|
||||||
}
|
}
|
||||||
|
@ -443,7 +444,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
triggerUIChange();
|
triggerUIChange();
|
||||||
|
|
||||||
} else if (!omnipodStatusRequestList.isEmpty()) {
|
} else if (!omnipodStatusRequestList.isEmpty()) {
|
||||||
|
|
||||||
List<OmnipodStatusRequest> removeList = new ArrayList<>();
|
List<OmnipodStatusRequest> removeList = new ArrayList<>();
|
||||||
|
|
||||||
for (OmnipodStatusRequest omnipodStatusRequest : omnipodStatusRequestList) {
|
for (OmnipodStatusRequest omnipodStatusRequest : omnipodStatusRequestList) {
|
||||||
|
@ -464,9 +464,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
i.putExtra("clipboardContent", result.toString());
|
i.putExtra("clipboardContent", result.toString());
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
context.startActivity(i);
|
context.startActivity(i);
|
||||||
|
|
||||||
// OKDialog.show(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.action),
|
|
||||||
// "Pulse Log:\n" + result.toString(), null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -542,7 +539,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isThisProfileSet(Profile profile) {
|
public boolean isThisProfileSet(Profile profile) {
|
||||||
|
|
||||||
// TODO status was not yet read from pod
|
// TODO status was not yet read from pod
|
||||||
// TODO maybe not possible, need to see how we will handle that
|
// TODO maybe not possible, need to see how we will handle that
|
||||||
if (currentProfile == null) {
|
if (currentProfile == null) {
|
||||||
|
@ -564,7 +560,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
|
|
||||||
if (currentProfile != null) {
|
if (currentProfile != null) {
|
||||||
int hour = (new GregorianCalendar()).get(Calendar.HOUR_OF_DAY);
|
int hour = (new GregorianCalendar()).get(Calendar.HOUR_OF_DAY);
|
||||||
return currentProfile.getBasalTimeFromMidnight(DateTimeUtil.getTimeInS(hour * 60));
|
return currentProfile.getBasalTimeFromMidnight(DateTimeUtil.getTimeInS(hour * 60));
|
||||||
|
@ -596,9 +591,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
// bolus needed, ask pump to deliver it
|
// bolus needed, ask pump to deliver it
|
||||||
return deliverBolus(detailedBolusInfo);
|
return deliverBolus(detailedBolusInfo);
|
||||||
} else {
|
} else {
|
||||||
//if (MedtronicHistoryData.doubleBolusDebug)
|
|
||||||
// aapsLogger.debug("DoubleBolusDebug: deliverTreatment::(carb only entry)");
|
|
||||||
|
|
||||||
// no bolus required, carb only treatment
|
// no bolus required, carb only treatment
|
||||||
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
|
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
|
||||||
|
|
||||||
|
@ -638,8 +630,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
// 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);
|
||||||
|
@ -688,7 +679,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
||||||
|
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - started");
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - started");
|
||||||
|
|
||||||
setRefreshButtonEnabled(false);
|
setRefreshButtonEnabled(false);
|
||||||
|
@ -788,7 +778,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String serialNumber() {
|
public String serialNumber() {
|
||||||
return podStateManager.hasPodState() ? String.valueOf(podStateManager.getAddress()) : "None";
|
return podStateManager.isPodInitialized() ? String.valueOf(podStateManager.getAddress()) : "-";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @NonNull public PumpDescription getPumpDescription() {
|
@Override @NonNull public PumpDescription getPumpDescription() {
|
||||||
|
@ -817,10 +807,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
if (activeExtendedBolus != null) {
|
if (activeExtendedBolus != null) {
|
||||||
ret += "Extended: " + activeExtendedBolus.toString() + "\n";
|
ret += "Extended: " + activeExtendedBolus.toString() + "\n";
|
||||||
}
|
}
|
||||||
// if (!veryShort) {
|
|
||||||
// ret += "TDD: " + DecimalFormatter.to0Decimal(pumpStatus.dailyTotalUnits) + " / "
|
|
||||||
// + pumpStatus.maxDailyTotalUnits + " U\n";
|
|
||||||
// }
|
|
||||||
ret += "IOB: " + getPumpStatusData().iob + "U\n";
|
ret += "IOB: " + getPumpStatusData().iob + "U\n";
|
||||||
ret += "Reserv: " + DecimalFormatter.to0Decimal(getPumpStatusData().reservoirRemainingUnits) + "U\n";
|
ret += "Reserv: " + DecimalFormatter.to0Decimal(getPumpStatusData().reservoirRemainingUnits) + "U\n";
|
||||||
ret += "Batt: " + getPumpStatusData().batteryRemaining + "\n";
|
ret += "Batt: " + getPumpStatusData().batteryRemaining + "\n";
|
||||||
|
@ -876,14 +862,12 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
long rileyLinkInitializationTimeout = 3 * 60 * 1000L; // 3 minutes
|
long rileyLinkInitializationTimeout = 3 * 60 * 1000L; // 3 minutes
|
||||||
if (podStateManager.isPodRunning() && podStateManager.getLastSuccessfulCommunication() != null) { // Null check for backwards compatibility
|
if (podStateManager.isPodRunning() && podStateManager.getLastSuccessfulCommunication() != null) { // Null check for backwards compatibility
|
||||||
if (podStateManager.getLastSuccessfulCommunication().getMillis() + unreachableTimeoutMilliseconds < System.currentTimeMillis()) {
|
if (podStateManager.getLastSuccessfulCommunication().getMillis() + unreachableTimeoutMilliseconds < System.currentTimeMillis()) {
|
||||||
if ((podStateManager.getLastFailedCommunication() != null && podStateManager.getLastSuccessfulCommunication().isBefore(podStateManager.getLastFailedCommunication())) ||
|
// We exceeded the alert threshold, and either our last command failed or we cannot reach the RL
|
||||||
|
// We should show an alert
|
||||||
|
return (podStateManager.getLastFailedCommunication() != null && podStateManager.getLastSuccessfulCommunication().isBefore(podStateManager.getLastFailedCommunication())) ||
|
||||||
rileyLinkServiceData.rileyLinkServiceState.isError() ||
|
rileyLinkServiceData.rileyLinkServiceState.isError() ||
|
||||||
// The below clause is a hack for working around the RL service state forever staying in connecting state on startup if the RL is switched off / unreachable
|
// The below clause is a hack for working around the RL service state forever staying in connecting state on startup if the RL is switched off / unreachable
|
||||||
(rileyLinkServiceData.getRileyLinkServiceState().isConnecting() && rileyLinkServiceData.getLastServiceStateChange() + rileyLinkInitializationTimeout < System.currentTimeMillis())) {
|
(rileyLinkServiceData.getRileyLinkServiceState().isConnecting() && rileyLinkServiceData.getLastServiceStateChange() + rileyLinkInitializationTimeout < System.currentTimeMillis());
|
||||||
// We exceeded the alert threshold, and either our last command failed or we cannot reach the RL
|
|
||||||
// We should show an alert
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't trigger an alert when we exceeded the thresholds, but the last communication was successful & the RL is reachable
|
// Don't trigger an alert when we exceeded the thresholds, but the last communication was successful & the RL is reachable
|
||||||
// This happens when we simply didn't need to send any commands to the pump
|
// This happens when we simply didn't need to send any commands to the pump
|
||||||
|
@ -924,9 +908,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
private void initializePump(boolean realInit) {
|
private void initializePump(boolean realInit) {
|
||||||
aapsLogger.info(LTag.PUMP, getLogPrefix() + "initializePump - start");
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "initializePump - start");
|
||||||
|
|
||||||
// TODO ccc
|
|
||||||
//OmnipodPumpStatus podPumpStatus = getPodPumpStatusObject();
|
|
||||||
|
|
||||||
setRefreshButtonEnabled(false);
|
setRefreshButtonEnabled(false);
|
||||||
|
|
||||||
if (podStateManager.isPodInitialized()) {
|
if (podStateManager.isPodInitialized()) {
|
||||||
|
@ -964,7 +945,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
setRefreshButtonEnabled(false);
|
setRefreshButtonEnabled(false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
OmnipodUITask responseTask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.SetBolus,
|
OmnipodUITask responseTask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.SetBolus,
|
||||||
detailedBolusInfo);
|
detailedBolusInfo);
|
||||||
|
|
||||||
|
@ -1012,10 +992,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
setRefreshButtonEnabled(true);
|
setRefreshButtonEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PumpType getPumpType() {
|
|
||||||
return pumpType;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
|
private PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
|
||||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(resourceId));
|
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(resourceId));
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ public class OmnipodConst {
|
||||||
|
|
||||||
public static class Statistics {
|
public static class Statistics {
|
||||||
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 LastGoodPumpCommunicationTime = Prefix + "lastGoodPumpCommunicationTime";
|
public static final String LastGoodPumpCommunicationTime = Prefix + "lastGoodPumpCommunicationTime";
|
||||||
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";
|
||||||
|
|
Loading…
Reference in a new issue