eliminate TreatmentsPlugin::getPlugin
This commit is contained in:
parent
07a18ef282
commit
e63169a94b
|
@ -9,10 +9,13 @@ interface AAPSLogger {
|
||||||
fun debug(message: String)
|
fun debug(message: String)
|
||||||
fun debug(enable: Boolean, tag: LTag, message: String)
|
fun debug(enable: Boolean, tag: LTag, message: String)
|
||||||
fun debug(tag: LTag, message: String)
|
fun debug(tag: LTag, message: String)
|
||||||
|
fun debug(tag: LTag, format: String, vararg arguments: Any?)
|
||||||
fun warn(tag: LTag, message: String)
|
fun warn(tag: LTag, message: String)
|
||||||
fun info(tag: LTag, message: String)
|
fun info(tag: LTag, message: String)
|
||||||
fun error(tag: LTag, message: String)
|
fun error(tag: LTag, message: String)
|
||||||
|
fun error(tag: LTag, message: String, throwable: Throwable)
|
||||||
|
fun error(tag: LTag, format: String, vararg arguments: Any?)
|
||||||
fun error(message: String)
|
fun error(message: String)
|
||||||
fun error(message: String, throwable: Throwable)
|
fun error(message: String, throwable: Throwable)
|
||||||
fun error(tag: LTag, message: String, throwable: Throwable)
|
fun error(format: String, vararg arguments: Any?)
|
||||||
}
|
}
|
|
@ -20,6 +20,10 @@ class AAPSLoggerDebug : AAPSLogger {
|
||||||
Log.d(tag.tag, message)
|
Log.d(tag.tag, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun debug(tag: LTag, format: String, vararg arguments: Any?) {
|
||||||
|
Log.d(tag.tag, String.format(format, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
override fun warn(tag: LTag, message: String) {
|
override fun warn(tag: LTag, message: String) {
|
||||||
Log.w(tag.tag, message)
|
Log.w(tag.tag, message)
|
||||||
}
|
}
|
||||||
|
@ -41,8 +45,16 @@ class AAPSLoggerDebug : AAPSLogger {
|
||||||
Log.e(LTag.CORE.tag, message, throwable)
|
Log.e(LTag.CORE.tag, message, throwable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun error(format: String, vararg arguments: Any?) {
|
||||||
|
Log.e(LTag.CORE.tag, String.format(format, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
override fun error(tag: LTag, message: String, throwable: Throwable) {
|
override fun error(tag: LTag, message: String, throwable: Throwable) {
|
||||||
Log.e(tag.tag, message, throwable)
|
Log.e(tag.tag, message, throwable)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun error(tag: LTag, format: String, vararg arguments: Any?) {
|
||||||
|
Log.e(tag.tag, String.format(format, arguments))
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -24,6 +24,11 @@ class AAPSLoggerProduction : AAPSLogger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun debug(tag: LTag, format: String, vararg arguments: Any?) {
|
||||||
|
if (L.isEnabled(tag.tag))
|
||||||
|
LoggerFactory.getLogger(tag.tag).debug(stackLogMarker() + String.format(format, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
override fun warn(tag: LTag, message: String) {
|
override fun warn(tag: LTag, message: String) {
|
||||||
if (L.isEnabled(tag.tag)) {
|
if (L.isEnabled(tag.tag)) {
|
||||||
LoggerFactory.getLogger(tag.tag).warn(stackLogMarker() + message)
|
LoggerFactory.getLogger(tag.tag).warn(stackLogMarker() + message)
|
||||||
|
@ -51,11 +56,21 @@ class AAPSLoggerProduction : AAPSLogger {
|
||||||
LoggerFactory.getLogger(LTag.CORE.tag).error(stackLogMarker() + message, throwable)
|
LoggerFactory.getLogger(LTag.CORE.tag).error(stackLogMarker() + message, throwable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun error(format: String, vararg arguments: Any?) {
|
||||||
|
LoggerFactory.getLogger(LTag.CORE.tag).error(stackLogMarker() + String.format(format, arguments))
|
||||||
|
}
|
||||||
|
|
||||||
override fun error(tag: LTag, message: String, throwable: Throwable) {
|
override fun error(tag: LTag, message: String, throwable: Throwable) {
|
||||||
if (L.isEnabled(tag.tag)) {
|
if (L.isEnabled(tag.tag)) {
|
||||||
LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + message, throwable)
|
LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + message, throwable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun error(tag: LTag, format: String, vararg arguments: Any?) {
|
||||||
|
if (L.isEnabled(tag.tag)) {
|
||||||
|
LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + String.format(format, arguments))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun StackTraceElement.toLogString(): String = "[${this.className.substringAfterLast(".")}.${this.methodName}():${this.lineNumber}]: "
|
fun StackTraceElement.toLogString(): String = "[${this.className.substringAfterLast(".")}.${this.methodName}():${this.lineNumber}]: "
|
||||||
|
|
|
@ -8,14 +8,11 @@ import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.BuildConfig;
|
import info.nightscout.androidaps.BuildConfig;
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
@ -23,6 +20,7 @@ import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
|
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||||
|
@ -30,16 +28,14 @@ import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpPluginBase;
|
import info.nightscout.androidaps.interfaces.PumpPluginBase;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
|
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
|
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
|
||||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
|
@ -56,7 +52,12 @@ import io.reactivex.schedulers.Schedulers;
|
||||||
public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpInterface, ConstraintsInterface {
|
public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpInterface, ConstraintsInterface {
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMP);
|
protected AAPSLogger aapsLogger;
|
||||||
|
protected RxBusWrapper rxBus;
|
||||||
|
protected ActivePluginProvider activePlugin;
|
||||||
|
protected Context context;
|
||||||
|
protected FabricPrivacy fabricPrivacy;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult().success(false)
|
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult().success(false)
|
||||||
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_supported_by_pump_driver));
|
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_supported_by_pump_driver));
|
||||||
|
@ -72,9 +73,25 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
protected boolean displayConnectionMessages = false;
|
protected boolean displayConnectionMessages = false;
|
||||||
|
|
||||||
|
|
||||||
protected PumpPluginAbstract(PluginDescription pluginDescription, PumpType pumpType, HasAndroidInjector injector, ResourceHelper resourceHelper, AAPSLogger aapsLogger, CommandQueueProvider commandQueue) {
|
protected PumpPluginAbstract(
|
||||||
|
PluginDescription pluginDescription,
|
||||||
|
PumpType pumpType,
|
||||||
|
HasAndroidInjector injector,
|
||||||
|
ResourceHelper resourceHelper,
|
||||||
|
AAPSLogger aapsLogger,
|
||||||
|
CommandQueueProvider commandQueue,
|
||||||
|
RxBusWrapper rxBus,
|
||||||
|
ActivePluginProvider activePlugin,
|
||||||
|
Context context,
|
||||||
|
FabricPrivacy fabricPrivacy
|
||||||
|
) {
|
||||||
|
|
||||||
super(pluginDescription, injector, aapsLogger, resourceHelper, commandQueue);
|
super(pluginDescription, injector, aapsLogger, resourceHelper, commandQueue);
|
||||||
|
this.aapsLogger = aapsLogger;
|
||||||
|
this.rxBus = rxBus;
|
||||||
|
this.activePlugin = activePlugin;
|
||||||
|
this.context = context;
|
||||||
|
this.fabricPrivacy = fabricPrivacy;
|
||||||
|
|
||||||
pumpDescription.setPumpDescription(pumpType);
|
pumpDescription.setPumpDescription(pumpType);
|
||||||
|
|
||||||
|
@ -90,18 +107,15 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
// TODO: moved from constructor .... test if it works
|
// TODO: moved from constructor .... test if it works
|
||||||
initPumpStatusData();
|
initPumpStatusData();
|
||||||
|
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
|
||||||
Intent intent = new Intent(context, getServiceClass());
|
Intent intent = new Intent(context, getServiceClass());
|
||||||
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
serviceRunning = true;
|
serviceRunning = true;
|
||||||
|
|
||||||
disposable.add(RxBus.Companion.getINSTANCE()
|
disposable.add(rxBus
|
||||||
.toObservable(EventAppExit.class)
|
.toObservable(EventAppExit.class)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe(event -> {
|
.subscribe(event -> context.unbindService(serviceConnection), exception -> fabricPrivacy.logException(exception))
|
||||||
MainApp.instance().getApplicationContext().unbindService(serviceConnection);
|
|
||||||
}, exception -> FabricPrivacy.getInstance().logException(exception))
|
|
||||||
);
|
);
|
||||||
onStartCustomActions();
|
onStartCustomActions();
|
||||||
}
|
}
|
||||||
|
@ -109,7 +123,6 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
|
||||||
context.unbindService(serviceConnection);
|
context.unbindService(serviceConnection);
|
||||||
|
|
||||||
serviceRunning = false;
|
serviceRunning = false;
|
||||||
|
@ -152,98 +165,91 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
|
|
||||||
|
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
if (displayConnectionMessages && isLoggingEnabled())
|
if (displayConnectionMessages)
|
||||||
LOG.warn("isConnected [PumpPluginAbstract].");
|
aapsLogger.debug(LTag.PUMP, "isConnected [PumpPluginAbstract].");
|
||||||
return PumpDriverState.isConnected(pumpState);
|
return PumpDriverState.isConnected(pumpState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isConnecting() {
|
public boolean isConnecting() {
|
||||||
if (displayConnectionMessages && isLoggingEnabled())
|
if (displayConnectionMessages)
|
||||||
LOG.warn("isConnecting [PumpPluginAbstract].");
|
aapsLogger.debug(LTag.PUMP, "isConnecting [PumpPluginAbstract].");
|
||||||
return pumpState == PumpDriverState.Connecting;
|
return pumpState == PumpDriverState.Connecting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void connect(String reason) {
|
public void connect(String reason) {
|
||||||
if (displayConnectionMessages && isLoggingEnabled())
|
if (displayConnectionMessages)
|
||||||
LOG.warn("connect (reason={}) [PumpPluginAbstract] - default (empty) implementation.", reason);
|
aapsLogger.debug(LTag.PUMP, "connect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void disconnect(String reason) {
|
public void disconnect(String reason) {
|
||||||
if (displayConnectionMessages && isLoggingEnabled())
|
if (displayConnectionMessages)
|
||||||
LOG.warn("disconnect (reason={}) [PumpPluginAbstract] - default (empty) implementation.", reason);
|
aapsLogger.debug(LTag.PUMP, "disconnect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void stopConnecting() {
|
public void stopConnecting() {
|
||||||
if (displayConnectionMessages && isLoggingEnabled())
|
if (displayConnectionMessages)
|
||||||
LOG.warn("stopConnecting [PumpPluginAbstract] - default (empty) implementation.");
|
aapsLogger.debug(LTag.PUMP, "stopConnecting [PumpPluginAbstract] - default (empty) implementation.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isHandshakeInProgress() {
|
public boolean isHandshakeInProgress() {
|
||||||
if (displayConnectionMessages && isLoggingEnabled())
|
if (displayConnectionMessages)
|
||||||
LOG.warn("isHandshakeInProgress [PumpPluginAbstract] - default (empty) implementation.");
|
aapsLogger.debug(LTag.PUMP, "isHandshakeInProgress [PumpPluginAbstract] - default (empty) implementation.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void finishHandshaking() {
|
public void finishHandshaking() {
|
||||||
if (displayConnectionMessages && isLoggingEnabled())
|
if (displayConnectionMessages)
|
||||||
LOG.warn("finishHandshaking [PumpPluginAbstract] - default (empty) implementation.");
|
aapsLogger.debug(LTag.PUMP, "finishHandshaking [PumpPluginAbstract] - default (empty) implementation.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void getPumpStatus() {
|
public void getPumpStatus() {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "getPumpStatus [PumpPluginAbstract] - Not implemented.");
|
||||||
LOG.warn("getPumpStatus [PumpPluginAbstract] - Not implemented.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Upload to pump new basal profile
|
// Upload to pump new basal profile
|
||||||
@NonNull public PumpEnactResult setNewBasalProfile(Profile profile) {
|
@NonNull public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "setNewBasalProfile [PumpPluginAbstract] - Not implemented.");
|
||||||
LOG.warn("setNewBasalProfile [PumpPluginAbstract] - Not implemented.");
|
|
||||||
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isThisProfileSet(Profile profile) {
|
public boolean isThisProfileSet(Profile profile) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "isThisProfileSet [PumpPluginAbstract] - Not implemented.");
|
||||||
LOG.warn("isThisProfileSet [PumpPluginAbstract] - Not implemented.");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public long lastDataTime() {
|
public long lastDataTime() {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "lastDataTime [PumpPluginAbstract].");
|
||||||
LOG.warn("lastDataTime [PumpPluginAbstract].");
|
|
||||||
return pumpStatus.lastConnection;
|
return pumpStatus.lastConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "getBaseBasalRate [PumpPluginAbstract] - Not implemented.");
|
||||||
LOG.warn("getBaseBasalRate [PumpPluginAbstract] - Not implemented.");
|
|
||||||
return 0.0d;
|
return 0.0d;
|
||||||
} // base basal rate, not temp basal
|
} // base basal rate, not temp basal
|
||||||
|
|
||||||
|
|
||||||
public void stopBolusDelivering() {
|
public void stopBolusDelivering() {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "stopBolusDelivering [PumpPluginAbstract] - Not implemented.");
|
||||||
LOG.warn("stopBolusDelivering [PumpPluginAbstract] - Not implemented.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile,
|
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile,
|
||||||
boolean enforceNew) {
|
boolean enforceNew) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute [PumpPluginAbstract] - Not implemented.");
|
||||||
LOG.warn("setTempBasalAbsolute [PumpPluginAbstract] - Not implemented.");
|
|
||||||
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,15 +257,13 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile,
|
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile,
|
||||||
boolean enforceNew) {
|
boolean enforceNew) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "setTempBasalPercent [PumpPluginAbstract] - Not implemented.");
|
||||||
LOG.warn("setTempBasalPercent [PumpPluginAbstract] - Not implemented.");
|
|
||||||
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NonNull public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
@NonNull public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "setExtendedBolus [PumpPluginAbstract] - Not implemented.");
|
||||||
LOG.warn("setExtendedBolus [PumpPluginAbstract] - Not implemented.");
|
|
||||||
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,15 +272,13 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
// when the cancel request is requested by the user (forced), the pump should always do a real cancel
|
// when the cancel request is requested by the user (forced), the pump should always do a real cancel
|
||||||
|
|
||||||
@NonNull public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
@NonNull public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "cancelTempBasal [PumpPluginAbstract] - Not implemented.");
|
||||||
LOG.warn("cancelTempBasal [PumpPluginAbstract] - Not implemented.");
|
|
||||||
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NonNull public PumpEnactResult cancelExtendedBolus() {
|
@NonNull public PumpEnactResult cancelExtendedBolus() {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "cancelExtendedBolus [PumpPluginAbstract] - Not implemented.");
|
||||||
LOG.warn("cancelExtendedBolus [PumpPluginAbstract] - Not implemented.");
|
|
||||||
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,8 +290,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public String deviceID() {
|
public String deviceID() {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "deviceID [PumpPluginAbstract] - Not implemented.");
|
||||||
LOG.warn("deviceID [PumpPluginAbstract] - Not implemented.");
|
|
||||||
return "FakeDevice";
|
return "FakeDevice";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,16 +305,14 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
// Short info for SMS, Wear etc
|
// Short info for SMS, Wear etc
|
||||||
|
|
||||||
public boolean isFakingTempsByExtendedBoluses() {
|
public boolean isFakingTempsByExtendedBoluses() {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "isFakingTempsByExtendedBoluses [PumpPluginAbstract] - Not implemented.");
|
||||||
LOG.warn("isFakingTempsByExtendedBoluses [PumpPluginAbstract] - Not implemented.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public PumpEnactResult loadTDDs() {
|
public PumpEnactResult loadTDDs() {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "loadTDDs [PumpPluginAbstract] - Not implemented.");
|
||||||
LOG.warn("loadTDDs [PumpPluginAbstract] - Not implemented.");
|
|
||||||
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,9 +320,8 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public JSONObject getJSONStatus(Profile profile, String profileName) {
|
public JSONObject getJSONStatus(Profile profile, String profileName) {
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
if ((pumpStatus.lastConnection + 5 * 60 * 1000L) < System.currentTimeMillis()) {
|
if ((pumpStatus.lastConnection + 5 * 60 * 1000L) < System.currentTimeMillis()) {
|
||||||
return null;
|
return new JSONObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONObject pump = new JSONObject();
|
JSONObject pump = new JSONObject();
|
||||||
|
@ -336,10 +334,10 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
|
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
|
||||||
try {
|
try {
|
||||||
extended.put("ActiveProfile", profileName);
|
extended.put("ActiveProfile", profileName);
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal tb = activePlugin.getActiveTreatments().getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
if (tb != null) {
|
if (tb != null) {
|
||||||
extended.put("TempBasalAbsoluteRate",
|
extended.put("TempBasalAbsoluteRate",
|
||||||
tb.tempBasalConvertedToAbsolute(System.currentTimeMillis(), profile));
|
tb.tempBasalConvertedToAbsolute(System.currentTimeMillis(), profile));
|
||||||
|
@ -347,7 +345,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
|
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtendedBolus eb = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
|
ExtendedBolus eb = activePlugin.getActiveTreatments().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||||
if (eb != null) {
|
if (eb != null) {
|
||||||
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
|
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
|
||||||
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
|
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
|
||||||
|
@ -362,7 +360,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
pump.put("reservoir", pumpStatus.reservoirRemainingUnits);
|
pump.put("reservoir", pumpStatus.reservoirRemainingUnits);
|
||||||
pump.put("clock", DateUtil.toISOString(new Date()));
|
pump.put("clock", DateUtil.toISOString(new Date()));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
LOG.error("Unhandled exception", e);
|
aapsLogger.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return pump;
|
return pump;
|
||||||
}
|
}
|
||||||
|
@ -373,7 +371,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
public String shortStatus(boolean veryShort) {
|
public String shortStatus(boolean veryShort) {
|
||||||
String ret = "";
|
String ret = "";
|
||||||
if (pumpStatus.lastConnection != 0) {
|
if (pumpStatus.lastConnection != 0) {
|
||||||
Long agoMsec = System.currentTimeMillis() - pumpStatus.lastConnection;
|
long agoMsec = System.currentTimeMillis() - pumpStatus.lastConnection;
|
||||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||||
ret += "LastConn: " + agoMin + " min ago\n";
|
ret += "LastConn: " + agoMin + " min ago\n";
|
||||||
}
|
}
|
||||||
|
@ -381,12 +379,11 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pumpStatus.lastBolusAmount) + "U @" + //
|
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pumpStatus.lastBolusAmount) + "U @" + //
|
||||||
android.text.format.DateFormat.format("HH:mm", pumpStatus.lastBolusTime) + "\n";
|
android.text.format.DateFormat.format("HH:mm", pumpStatus.lastBolusTime) + "\n";
|
||||||
}
|
}
|
||||||
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin()
|
TemporaryBasal activeTemp = activePlugin.getActiveTreatments().getRealTempBasalFromHistory(System.currentTimeMillis());
|
||||||
.getRealTempBasalFromHistory(System.currentTimeMillis());
|
|
||||||
if (activeTemp != null) {
|
if (activeTemp != null) {
|
||||||
ret += "Temp: " + activeTemp.toStringFull() + "\n";
|
ret += "Temp: " + activeTemp.toStringFull() + "\n";
|
||||||
}
|
}
|
||||||
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(
|
ExtendedBolus activeExtendedBolus = activePlugin.getActiveTreatments().getExtendedBolusFromHistory(
|
||||||
System.currentTimeMillis());
|
System.currentTimeMillis());
|
||||||
if (activeExtendedBolus != null) {
|
if (activeExtendedBolus != null) {
|
||||||
ret += "Extended: " + activeExtendedBolus.toString() + "\n";
|
ret += "Extended: " + activeExtendedBolus.toString() + "\n";
|
||||||
|
@ -408,31 +405,29 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
try {
|
try {
|
||||||
if (detailedBolusInfo.insulin == 0 && detailedBolusInfo.carbs == 0) {
|
if (detailedBolusInfo.insulin == 0 && detailedBolusInfo.carbs == 0) {
|
||||||
// neither carbs nor bolus requested
|
// neither carbs nor bolus requested
|
||||||
if (isLoggingEnabled())
|
aapsLogger.error("deliverTreatment: Invalid input");
|
||||||
LOG.error("deliverTreatment: Invalid input");
|
|
||||||
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(MainApp.gs(R.string.danar_invalidinput));
|
.comment(getResourceHelper().gs(R.string.danar_invalidinput));
|
||||||
} else if (detailedBolusInfo.insulin > 0) {
|
} else if (detailedBolusInfo.insulin > 0) {
|
||||||
// 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)
|
if (MedtronicHistoryData.doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: deliverTreatment::(carb only entry)");
|
aapsLogger.debug("DoubleBolusDebug: deliverTreatment::(carb only entry)");
|
||||||
|
|
||||||
// no bolus required, carb only treatment
|
// no bolus required, carb only treatment
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
|
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
|
||||||
|
|
||||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||||
bolusingEvent.setT(new Treatment());
|
bolusingEvent.setT(new Treatment());
|
||||||
bolusingEvent.getT().isSMB = detailedBolusInfo.isSMB;
|
bolusingEvent.getT().isSMB = detailedBolusInfo.isSMB;
|
||||||
bolusingEvent.setPercent(100);
|
bolusingEvent.setPercent(100);
|
||||||
RxBus.Companion.getINSTANCE().send(bolusingEvent);
|
rxBus.send(bolusingEvent);
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "deliverTreatment: Carb only treatment.");
|
||||||
LOG.debug("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(MainApp.gs(R.string.virtualpump_resultok));
|
.carbsDelivered(detailedBolusInfo.carbs).comment(getResourceHelper().gs(R.string.virtualpump_resultok));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
triggerUIChange();
|
triggerUIChange();
|
||||||
|
@ -440,20 +435,12 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isLoggingEnabled() {
|
|
||||||
return L.isEnabled(L.PUMP);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected abstract PumpEnactResult deliverBolus(DetailedBolusInfo detailedBolusInfo);
|
protected abstract PumpEnactResult deliverBolus(DetailedBolusInfo detailedBolusInfo);
|
||||||
|
|
||||||
|
|
||||||
protected abstract void triggerUIChange();
|
protected abstract void triggerUIChange();
|
||||||
|
|
||||||
|
private PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
|
||||||
public 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(MainApp.gs(resourceId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.medtronic;
|
package info.nightscout.androidaps.plugins.pump.medtronic;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
@ -9,7 +10,6 @@ import android.os.SystemClock;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import org.joda.time.LocalDateTime;
|
import org.joda.time.LocalDateTime;
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -27,7 +27,6 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.activities.ErrorHelperActivity;
|
import info.nightscout.androidaps.activities.ErrorHelperActivity;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
|
@ -37,18 +36,15 @@ import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.events.EventCustomActionsChanged;
|
import info.nightscout.androidaps.events.EventCustomActionsChanged;
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||||
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
|
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
|
|
||||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
|
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.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
|
@ -84,7 +80,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.events.EventRefreshButt
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService;
|
import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
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;
|
||||||
|
|
||||||
|
@ -98,16 +94,7 @@ import static info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUt
|
||||||
@Singleton
|
@Singleton
|
||||||
public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInterface {
|
public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInterface {
|
||||||
|
|
||||||
private final MainApp mainApp;
|
private final SP sp;
|
||||||
private final ResourceHelper resourceHelper;
|
|
||||||
private final ConstraintChecker constraintChecker;
|
|
||||||
private final ProfileFunction profileFunction;
|
|
||||||
private final TreatmentsPlugin treatmentsPlugin;
|
|
||||||
private final info.nightscout.androidaps.utils.sharedPreferences.SP sp;
|
|
||||||
private final RxBusWrapper rxBus;
|
|
||||||
private final CommandQueueProvider commandQueue;
|
|
||||||
|
|
||||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMP);
|
|
||||||
|
|
||||||
protected static MedtronicPumpPlugin plugin = null;
|
protected static MedtronicPumpPlugin plugin = null;
|
||||||
private RileyLinkMedtronicService medtronicService;
|
private RileyLinkMedtronicService medtronicService;
|
||||||
|
@ -133,13 +120,12 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
HasAndroidInjector injector,
|
HasAndroidInjector injector,
|
||||||
AAPSLogger aapsLogger,
|
AAPSLogger aapsLogger,
|
||||||
RxBusWrapper rxBus,
|
RxBusWrapper rxBus,
|
||||||
MainApp maiApp,
|
Context context,
|
||||||
ResourceHelper resourceHelper,
|
ResourceHelper resourceHelper,
|
||||||
ConstraintChecker constraintChecker,
|
ActivePluginProvider activePlugin,
|
||||||
ProfileFunction profileFunction,
|
|
||||||
TreatmentsPlugin treatmentsPlugin,
|
|
||||||
SP sp,
|
SP sp,
|
||||||
CommandQueueProvider commandQueue
|
CommandQueueProvider commandQueue,
|
||||||
|
FabricPrivacy fabricPrivacy
|
||||||
) {
|
) {
|
||||||
|
|
||||||
super(new PluginDescription() //
|
super(new PluginDescription() //
|
||||||
|
@ -149,33 +135,24 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
.shortName(R.string.medtronic_name_short) //
|
.shortName(R.string.medtronic_name_short) //
|
||||||
.preferencesId(R.xml.pref_medtronic).description(R.string.description_pump_medtronic), //
|
.preferencesId(R.xml.pref_medtronic).description(R.string.description_pump_medtronic), //
|
||||||
PumpType.Medtronic_522_722, // we default to most basic model, correct model from config is loaded later
|
PumpType.Medtronic_522_722, // we default to most basic model, correct model from config is loaded later
|
||||||
injector, resourceHelper, aapsLogger, commandQueue
|
injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, context, fabricPrivacy
|
||||||
|
|
||||||
);
|
);
|
||||||
this.plugin = this;
|
this.plugin = this;
|
||||||
|
|
||||||
this.mainApp = maiApp;
|
|
||||||
this.rxBus = rxBus;
|
this.rxBus = rxBus;
|
||||||
this.resourceHelper = resourceHelper;
|
|
||||||
this.constraintChecker = constraintChecker;
|
|
||||||
this.profileFunction = profileFunction;
|
|
||||||
this.treatmentsPlugin = treatmentsPlugin;
|
|
||||||
this.sp = sp;
|
this.sp = sp;
|
||||||
this.commandQueue = commandQueue;
|
|
||||||
|
|
||||||
displayConnectionMessages = false;
|
displayConnectionMessages = false;
|
||||||
|
|
||||||
serviceConnection = new ServiceConnection() {
|
serviceConnection = new ServiceConnection() {
|
||||||
|
|
||||||
public void onServiceDisconnected(ComponentName name) {
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "RileyLinkMedtronicService is disconnected");
|
||||||
LOG.debug("RileyLinkMedtronicService is disconnected");
|
|
||||||
medtronicService = null;
|
medtronicService = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "RileyLinkMedtronicService is connected");
|
||||||
LOG.debug("RileyLinkMedtronicService is connected");
|
|
||||||
RileyLinkMedtronicService.LocalBinder mLocalBinder = (RileyLinkMedtronicService.LocalBinder) service;
|
RileyLinkMedtronicService.LocalBinder mLocalBinder = (RileyLinkMedtronicService.LocalBinder) service;
|
||||||
medtronicService = mLocalBinder.getServiceInstance();
|
medtronicService = mLocalBinder.getServiceInstance();
|
||||||
|
|
||||||
|
@ -185,8 +162,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
SystemClock.sleep(5000);
|
SystemClock.sleep(5000);
|
||||||
|
|
||||||
if (MedtronicUtil.getPumpStatus() != null) {
|
if (MedtronicUtil.getPumpStatus() != null) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "Starting Medtronic-RileyLink service");
|
||||||
LOG.debug("Starting Medtronic-RileyLink service");
|
|
||||||
if (MedtronicUtil.getPumpStatus().setNotInPreInit()) {
|
if (MedtronicUtil.getPumpStatus().setNotInPreInit()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -202,7 +178,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
medtronicUIComm = new MedtronicUIComm();
|
medtronicUIComm = new MedtronicUIComm();
|
||||||
medtronicHistoryData = new MedtronicHistoryData();
|
medtronicHistoryData = new MedtronicHistoryData(aapsLogger, sp, activePlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -235,8 +211,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
pumpStatusLocal.refreshConfiguration();
|
pumpStatusLocal.refreshConfiguration();
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "initPumpStatusData: " + this.pumpStatusLocal);
|
||||||
LOG.debug("initPumpStatusData: {}", this.pumpStatusLocal);
|
|
||||||
|
|
||||||
this.pumpStatus = pumpStatusLocal;
|
this.pumpStatus = pumpStatusLocal;
|
||||||
|
|
||||||
|
@ -254,18 +229,18 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
private void migrateSettings() {
|
private void migrateSettings() {
|
||||||
|
|
||||||
if ("US (916 MHz)".equals(sp.getString(MedtronicConst.Prefs.PumpFrequency, null))) {
|
if ("US (916 MHz)".equals(sp.getString(MedtronicConst.Prefs.PumpFrequency, "US (916 MHz)"))) {
|
||||||
sp.putString(MedtronicConst.Prefs.PumpFrequency, MainApp.gs(R.string.key_medtronic_pump_frequency_us_ca));
|
sp.putString(MedtronicConst.Prefs.PumpFrequency, getResourceHelper().gs(R.string.key_medtronic_pump_frequency_us_ca));
|
||||||
}
|
}
|
||||||
|
|
||||||
String encoding = sp.getString(MedtronicConst.Prefs.Encoding, null);
|
String encoding = sp.getString(MedtronicConst.Prefs.Encoding, "RileyLink 4b6b Encoding");
|
||||||
|
|
||||||
if ("RileyLink 4b6b Encoding".equals(encoding)) {
|
if ("RileyLink 4b6b Encoding".equals(encoding)) {
|
||||||
sp.putString(MedtronicConst.Prefs.Encoding, MainApp.gs(R.string.key_medtronic_pump_encoding_4b6b_rileylink));
|
sp.putString(MedtronicConst.Prefs.Encoding, getResourceHelper().gs(R.string.key_medtronic_pump_encoding_4b6b_rileylink));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("Local 4b6b Encoding".equals(encoding)) {
|
if ("Local 4b6b Encoding".equals(encoding)) {
|
||||||
sp.putString(MedtronicConst.Prefs.Encoding, MainApp.gs(R.string.key_medtronic_pump_encoding_4b6b_local));
|
sp.putString(MedtronicConst.Prefs.Encoding, getResourceHelper().gs(R.string.key_medtronic_pump_encoding_4b6b_local));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,8 +259,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
StatusRefreshAction.GetData, null, null);
|
StatusRefreshAction.GetData, null, null);
|
||||||
|
|
||||||
if (doWeHaveAnyStatusNeededRefereshing(statusRefresh)) {
|
if (doWeHaveAnyStatusNeededRefereshing(statusRefresh)) {
|
||||||
if (!commandQueue.statusInQueue()) {
|
if (!getCommandQueue().statusInQueue()) {
|
||||||
commandQueue.readStatus("Scheduled Status Refresh", null);
|
getCommandQueue().readStatus("Scheduled Status Refresh", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,16 +305,16 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
if (isLoggingEnabled() && displayConnectionMessages)
|
if (displayConnectionMessages)
|
||||||
LOG.debug("MedtronicPumpPlugin::isInitialized");
|
aapsLogger.debug(LTag.PUMP, "MedtronicPumpPlugin::isInitialized");
|
||||||
return isServiceSet() && isInitialized;
|
return isServiceSet() && isInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBusy() {
|
public boolean isBusy() {
|
||||||
if (isLoggingEnabled() && displayConnectionMessages)
|
if (displayConnectionMessages)
|
||||||
LOG.debug("MedtronicPumpPlugin::isBusy");
|
aapsLogger.debug(LTag.PUMP, "MedtronicPumpPlugin::isBusy");
|
||||||
|
|
||||||
if (isServiceSet()) {
|
if (isServiceSet()) {
|
||||||
|
|
||||||
|
@ -389,16 +364,16 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
if (isLoggingEnabled() && displayConnectionMessages)
|
if (displayConnectionMessages)
|
||||||
LOG.debug("MedtronicPumpPlugin::isConnected");
|
aapsLogger.debug(LTag.PUMP, "MedtronicPumpPlugin::isConnected");
|
||||||
return isServiceSet() && medtronicService.isInitialized();
|
return isServiceSet() && medtronicService.isInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConnecting() {
|
public boolean isConnecting() {
|
||||||
if (isLoggingEnabled() && displayConnectionMessages)
|
if (displayConnectionMessages)
|
||||||
LOG.debug("MedtronicPumpPlugin::isConnecting");
|
aapsLogger.debug(LTag.PUMP, "MedtronicPumpPlugin::isConnecting");
|
||||||
return !isServiceSet() || !medtronicService.isInitialized();
|
return !isServiceSet() || !medtronicService.isInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,7 +389,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
refreshAnyStatusThatNeedsToBeRefreshed();
|
refreshAnyStatusThatNeedsToBeRefreshed();
|
||||||
}
|
}
|
||||||
|
|
||||||
RxBus.Companion.getINSTANCE().send(new EventMedtronicPumpValuesChanged());
|
rxBus.send(new EventMedtronicPumpValuesChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -429,14 +404,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
RileyLinkServiceState rileyLinkServiceState = MedtronicUtil.getServiceState();
|
RileyLinkServiceState rileyLinkServiceState = MedtronicUtil.getServiceState();
|
||||||
|
|
||||||
if (rileyLinkServiceState == null) {
|
if (rileyLinkServiceState == null) {
|
||||||
LOG.error("RileyLink unreachable. RileyLinkServiceState is null.");
|
aapsLogger.debug(LTag.PUMP, "RileyLink unreachable. RileyLinkServiceState is null.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rileyLinkServiceState != RileyLinkServiceState.PumpConnectorReady //
|
if (rileyLinkServiceState != RileyLinkServiceState.PumpConnectorReady //
|
||||||
&& rileyLinkServiceState != RileyLinkServiceState.RileyLinkReady //
|
&& rileyLinkServiceState != RileyLinkServiceState.RileyLinkReady //
|
||||||
&& rileyLinkServiceState != RileyLinkServiceState.TuneUpDevice) {
|
&& rileyLinkServiceState != RileyLinkServiceState.TuneUpDevice) {
|
||||||
LOG.error("RileyLink unreachable.");
|
aapsLogger.debug(LTag.PUMP, "RileyLink unreachable.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,8 +431,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
boolean resetTime = false;
|
boolean resetTime = false;
|
||||||
|
|
||||||
if (isPumpNotReachable()) {
|
if (isPumpNotReachable()) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.error("Pump unreachable.");
|
||||||
LOG.error("Pump unreachable.");
|
|
||||||
MedtronicUtil.sendNotification(MedtronicNotificationType.PumpUnreachable);
|
MedtronicUtil.sendNotification(MedtronicNotificationType.PumpUnreachable);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -538,14 +512,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
|
|
||||||
private void setRefreshButtonEnabled(boolean enabled) {
|
private void setRefreshButtonEnabled(boolean enabled) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventRefreshButtonState(enabled));
|
rxBus.send(new EventRefreshButtonState(enabled));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void initializePump(boolean realInit) {
|
private void initializePump(boolean realInit) {
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "initializePump - start");
|
||||||
LOG.info(getLogPrefix() + "initializePump - start");
|
|
||||||
|
|
||||||
if (medtronicCommunicationManager == null) {
|
if (medtronicCommunicationManager == null) {
|
||||||
medtronicCommunicationManager = MedtronicCommunicationManager.getInstance();
|
medtronicCommunicationManager = MedtronicCommunicationManager.getInstance();
|
||||||
|
@ -558,8 +531,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
if (isRefresh) {
|
if (isRefresh) {
|
||||||
if (isPumpNotReachable()) {
|
if (isPumpNotReachable()) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.error(getLogPrefix() + "initializePump::Pump unreachable.");
|
||||||
LOG.error(getLogPrefix() + "initializePump::Pump unreachable.");
|
|
||||||
MedtronicUtil.sendNotification(MedtronicNotificationType.PumpUnreachable);
|
MedtronicUtil.sendNotification(MedtronicNotificationType.PumpUnreachable);
|
||||||
|
|
||||||
setRefreshButtonEnabled(true);
|
setRefreshButtonEnabled(true);
|
||||||
|
@ -575,8 +547,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
medtronicUIComm.executeCommand(MedtronicCommandType.PumpModel);
|
medtronicUIComm.executeCommand(MedtronicCommandType.PumpModel);
|
||||||
} else {
|
} else {
|
||||||
if (pumpStatusLocal.medtronicDeviceType != MedtronicUtil.getMedtronicPumpModel()) {
|
if (pumpStatusLocal.medtronicDeviceType != MedtronicUtil.getMedtronicPumpModel()) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.warn(LTag.PUMP, getLogPrefix() + "Configured pump is not the same as one detected.");
|
||||||
LOG.warn(getLogPrefix() + "Configured pump is not the same as one detected.");
|
|
||||||
MedtronicUtil.sendNotification(MedtronicNotificationType.PumpTypeNotSame);
|
MedtronicUtil.sendNotification(MedtronicNotificationType.PumpTypeNotSame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -605,8 +576,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
int errorCount = medtronicUIComm.getInvalidResponsesCount();
|
int errorCount = medtronicUIComm.getInvalidResponsesCount();
|
||||||
|
|
||||||
if (errorCount >= 5) {
|
if (errorCount >= 5) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.error("Number of error counts was 5 or more. Starting tunning.");
|
||||||
LOG.error("Number of error counts was 5 or more. Starting tunning.");
|
|
||||||
setRefreshButtonEnabled(true);
|
setRefreshButtonEnabled(true);
|
||||||
ServiceTaskExecutor.startTask(new WakeAndTuneTask());
|
ServiceTaskExecutor.startTask(new WakeAndTuneTask());
|
||||||
return;
|
return;
|
||||||
|
@ -638,7 +608,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
@Override
|
@Override
|
||||||
public boolean isThisProfileSet(Profile profile) {
|
public boolean isThisProfileSet(Profile profile) {
|
||||||
MedtronicPumpStatus mdtPumpStatus = getMDTPumpStatus();
|
MedtronicPumpStatus mdtPumpStatus = getMDTPumpStatus();
|
||||||
LOG.debug("isThisProfileSet: basalInitalized={}", mdtPumpStatus.basalProfileStatus);
|
aapsLogger.debug(LTag.PUMP, "isThisProfileSet: basalInitalized=" + mdtPumpStatus.basalProfileStatus);
|
||||||
|
|
||||||
if (!isInitialized)
|
if (!isInitialized)
|
||||||
return true;
|
return true;
|
||||||
|
@ -664,8 +634,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
Double[] basalsByHour = getMDTPumpStatus().basalsByHour;
|
Double[] basalsByHour = getMDTPumpStatus().basalsByHour;
|
||||||
PumpType pumpType = getMDTPumpStatus().getPumpType();
|
PumpType pumpType = getMDTPumpStatus().getPumpType();
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, "Current Basals (h): "
|
||||||
LOG.debug("Current Basals (h): "
|
|
||||||
+ (basalsByHour == null ? "null" : BasalProfile.getProfilesByHourToString(basalsByHour)));
|
+ (basalsByHour == null ? "null" : BasalProfile.getProfilesByHourToString(basalsByHour)));
|
||||||
|
|
||||||
// int index = 0;
|
// int index = 0;
|
||||||
|
@ -689,14 +658,12 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLoggingEnabled()) {
|
aapsLogger.debug(LTag.PUMP, stringBuilder.toString());
|
||||||
LOG.debug(stringBuilder.toString());
|
|
||||||
|
|
||||||
if (!invalid) {
|
if (!invalid) {
|
||||||
LOG.debug("Basal profile is same as AAPS one.");
|
aapsLogger.debug(LTag.PUMP, "Basal profile is same as AAPS one.");
|
||||||
} else {
|
} else {
|
||||||
LOG.debug("Basal profile on Pump is different than the AAPS one.");
|
aapsLogger.debug(LTag.PUMP, "Basal profile on Pump is different than the AAPS one.");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (!invalid);
|
return (!invalid);
|
||||||
|
@ -736,8 +703,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
private MedtronicPumpStatus getMDTPumpStatus() {
|
private MedtronicPumpStatus getMDTPumpStatus() {
|
||||||
if (pumpStatusLocal == null) {
|
if (pumpStatusLocal == null) {
|
||||||
// FIXME I don't know why this happens
|
// FIXME I don't know why this happens
|
||||||
if (isLoggingEnabled())
|
aapsLogger.warn(LTag.PUMP, "!!!! Reset Pump Status Local");
|
||||||
LOG.warn("!!!! Reset Pump Status Local");
|
|
||||||
pumpStatusLocal = MedtronicUtil.getPumpStatus();
|
pumpStatusLocal = MedtronicUtil.getPumpStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -746,7 +712,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
|
|
||||||
protected void triggerUIChange() {
|
protected void triggerUIChange() {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventMedtronicPumpValuesChanged());
|
rxBus.send(new EventMedtronicPumpValuesChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
private BolusDeliveryType bolusDeliveryType = BolusDeliveryType.Idle;
|
private BolusDeliveryType bolusDeliveryType = BolusDeliveryType.Idle;
|
||||||
|
@ -761,13 +727,12 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
private void checkTimeAndOptionallySetTime() {
|
private void checkTimeAndOptionallySetTime() {
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, "MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Start");
|
||||||
LOG.info("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Start");
|
|
||||||
|
|
||||||
setRefreshButtonEnabled(false);
|
setRefreshButtonEnabled(false);
|
||||||
|
|
||||||
if (isPumpNotReachable()) {
|
if (isPumpNotReachable()) {
|
||||||
LOG.debug("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Pump Unreachable.");
|
aapsLogger.debug(LTag.PUMP, "MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Pump Unreachable.");
|
||||||
setRefreshButtonEnabled(true);
|
setRefreshButtonEnabled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -793,25 +758,23 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
if ((clock.localDeviceTime.getYear() <= 2015) || (timeDiff <= 24 * 60 * 60)) {
|
if ((clock.localDeviceTime.getYear() <= 2015) || (timeDiff <= 24 * 60 * 60)) {
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, "MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference is {} s. Set time on pump." + timeDiff);
|
||||||
LOG.info("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference is {} s. Set time on pump.", timeDiff);
|
|
||||||
|
|
||||||
medtronicUIComm.executeCommand(MedtronicCommandType.SetRealTimeClock);
|
medtronicUIComm.executeCommand(MedtronicCommandType.SetRealTimeClock);
|
||||||
|
|
||||||
if (clock.timeDifference == 0) {
|
if (clock.timeDifference == 0) {
|
||||||
Notification notification = new Notification(Notification.INSIGHT_DATE_TIME_UPDATED, MainApp.gs(R.string.pump_time_updated), Notification.INFO, 60);
|
Notification notification = new Notification(Notification.INSIGHT_DATE_TIME_UPDATED, getResourceHelper().gs(R.string.pump_time_updated), Notification.INFO, 60);
|
||||||
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
|
rxBus.send(new EventNewNotification(notification));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((clock.localDeviceTime.getYear() > 2015)) {
|
if ((clock.localDeviceTime.getYear() > 2015)) {
|
||||||
LOG.error("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference over 24h requested [diff={}]. Doing nothing.", timeDiff);
|
aapsLogger.error("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference over 24h requested [diff={}]. Doing nothing." + timeDiff);
|
||||||
sendNotification(MedtronicNotificationType.TimeChangeOver24h);
|
sendNotification(MedtronicNotificationType.TimeChangeOver24h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, "MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference is {} s. Do nothing." + timeDiff);
|
||||||
LOG.info("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference is {} s. Do nothing.", timeDiff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduleNextRefresh(MedtronicStatusRefreshType.PumpTime, 0);
|
scheduleNextRefresh(MedtronicStatusRefreshType.PumpTime, 0);
|
||||||
|
@ -821,7 +784,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
@NonNull
|
@NonNull
|
||||||
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
||||||
|
|
||||||
LOG.info("MedtronicPumpPlugin::deliverBolus - {}", BolusDeliveryType.DeliveryPrepared);
|
aapsLogger.info(LTag.PUMP, "MedtronicPumpPlugin::deliverBolus - " + BolusDeliveryType.DeliveryPrepared);
|
||||||
|
|
||||||
setRefreshButtonEnabled(false);
|
setRefreshButtonEnabled(false);
|
||||||
|
|
||||||
|
@ -831,7 +794,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
return new PumpEnactResult(getInjector()) //
|
return new PumpEnactResult(getInjector()) //
|
||||||
.success(false) //
|
.success(false) //
|
||||||
.enacted(false) //
|
.enacted(false) //
|
||||||
.comment(MainApp.gs(R.string.medtronic_cmd_bolus_could_not_be_delivered_no_insulin,
|
.comment(getResourceHelper().gs(R.string.medtronic_cmd_bolus_could_not_be_delivered_no_insulin,
|
||||||
mdtPumpStatus.reservoirRemainingUnits,
|
mdtPumpStatus.reservoirRemainingUnits,
|
||||||
detailedBolusInfo.insulin));
|
detailedBolusInfo.insulin));
|
||||||
}
|
}
|
||||||
|
@ -839,7 +802,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
bolusDeliveryType = BolusDeliveryType.DeliveryPrepared;
|
bolusDeliveryType = BolusDeliveryType.DeliveryPrepared;
|
||||||
|
|
||||||
if (isPumpNotReachable()) {
|
if (isPumpNotReachable()) {
|
||||||
LOG.debug("MedtronicPumpPlugin::deliverBolus - Pump Unreachable.");
|
aapsLogger.debug(LTag.PUMP, "MedtronicPumpPlugin::deliverBolus - Pump Unreachable.");
|
||||||
return setNotReachable(true, false);
|
return setNotReachable(true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -890,12 +853,12 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
// LOG.debug("MedtronicPumpPlugin::deliverBolus - Show dialog. Context: "
|
// LOG.debug("MedtronicPumpPlugin::deliverBolus - Show dialog. Context: "
|
||||||
// + MainApp.instance().getApplicationContext());
|
// + MainApp.instance().getApplicationContext());
|
||||||
|
|
||||||
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
Intent i = new Intent(context, ErrorHelperActivity.class);
|
||||||
i.putExtra("soundid", R.raw.boluserror);
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
i.putExtra("status", MainApp.gs(R.string.medtronic_cmd_cancel_bolus_not_supported));
|
i.putExtra("status", getResourceHelper().gs(R.string.medtronic_cmd_cancel_bolus_not_supported));
|
||||||
i.putExtra("title", MainApp.gs(R.string.combo_warning));
|
i.putExtra("title", getResourceHelper().gs(R.string.combo_warning));
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
MainApp.instance().startActivity(i);
|
context.startActivity(i);
|
||||||
|
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
@ -905,7 +868,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
detailedBolusInfo.date = now;
|
detailedBolusInfo.date = now;
|
||||||
detailedBolusInfo.deliverAt = now; // not sure about that one
|
detailedBolusInfo.deliverAt = now; // not sure about that one
|
||||||
|
|
||||||
treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, true);
|
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
|
||||||
|
|
||||||
// we subtract insulin, exact amount will be visible with next remainingInsulin update.
|
// we subtract insulin, exact amount will be visible with next remainingInsulin update.
|
||||||
getMDTPumpStatus().reservoirRemainingUnits -= detailedBolusInfo.insulin;
|
getMDTPumpStatus().reservoirRemainingUnits -= detailedBolusInfo.insulin;
|
||||||
|
@ -930,7 +893,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
return new PumpEnactResult(getInjector()) //
|
return new PumpEnactResult(getInjector()) //
|
||||||
.success(bolusDeliveryType == BolusDeliveryType.CancelDelivery) //
|
.success(bolusDeliveryType == BolusDeliveryType.CancelDelivery) //
|
||||||
.enacted(false) //
|
.enacted(false) //
|
||||||
.comment(MainApp.gs(R.string.medtronic_cmd_bolus_could_not_be_delivered));
|
.comment(getResourceHelper().gs(R.string.medtronic_cmd_bolus_could_not_be_delivered));
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -955,7 +918,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
return new PumpEnactResult(getInjector()) //
|
return new PumpEnactResult(getInjector()) //
|
||||||
.success(false) //
|
.success(false) //
|
||||||
.enacted(false) //
|
.enacted(false) //
|
||||||
.comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable));
|
.comment(getResourceHelper().gs(R.string.medtronic_pump_status_pump_unreachable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -991,29 +954,25 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
return new PumpEnactResult(getInjector()) //
|
return new PumpEnactResult(getInjector()) //
|
||||||
.success(false) //
|
.success(false) //
|
||||||
.enacted(false) //
|
.enacted(false) //
|
||||||
.comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable));
|
.comment(getResourceHelper().gs(R.string.medtronic_pump_status_pump_unreachable));
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
|
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
|
||||||
|
|
||||||
getMDTPumpStatus();
|
getMDTPumpStatus();
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute: rate: " + absoluteRate + ", duration=" + durationInMinutes);
|
||||||
LOG.info(getLogPrefix() + "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes);
|
|
||||||
|
|
||||||
// read current TBR
|
// read current TBR
|
||||||
TempBasalPair tbrCurrent = readTBR();
|
TempBasalPair tbrCurrent = readTBR();
|
||||||
|
|
||||||
if (tbrCurrent == null) {
|
if (tbrCurrent == null) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.warn(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute - Could not read current TBR, canceling operation.");
|
||||||
LOG.warn(getLogPrefix() + "setTempBasalAbsolute - Could not read current TBR, canceling operation.");
|
|
||||||
finishAction("TBR");
|
finishAction("TBR");
|
||||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||||
.comment(MainApp.gs(R.string.medtronic_cmd_cant_read_tbr));
|
.comment(getResourceHelper().gs(R.string.medtronic_cmd_cant_read_tbr));
|
||||||
} else {
|
} else {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute: Current Basal: duration: " + tbrCurrent.getDurationMinutes() + " min, rate=" + tbrCurrent.getInsulinRate());
|
||||||
LOG.info(getLogPrefix() + "setTempBasalAbsolute: Current Basal: duration: {} min, rate={}",
|
|
||||||
tbrCurrent.getDurationMinutes(), tbrCurrent.getInsulinRate());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!enforceNew) {
|
if (!enforceNew) {
|
||||||
|
@ -1027,8 +986,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sameRate) {
|
if (sameRate) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute - No enforceNew and same rate. Exiting.");
|
||||||
LOG.info(getLogPrefix() + "setTempBasalAbsolute - No enforceNew and same rate. Exiting.");
|
|
||||||
finishAction("TBR");
|
finishAction("TBR");
|
||||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||||
}
|
}
|
||||||
|
@ -1038,8 +996,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
// if TBR is running we will cancel it.
|
// if TBR is running we will cancel it.
|
||||||
if (tbrCurrent.getInsulinRate() != 0.0f && tbrCurrent.getDurationMinutes() > 0) {
|
if (tbrCurrent.getInsulinRate() != 0.0f && tbrCurrent.getDurationMinutes() > 0) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute - TBR running - so canceling it.");
|
||||||
LOG.info(getLogPrefix() + "setTempBasalAbsolute - TBR running - so canceling it.");
|
|
||||||
|
|
||||||
// CANCEL
|
// CANCEL
|
||||||
|
|
||||||
|
@ -1048,16 +1005,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
Boolean response = (Boolean) responseTask2.returnData;
|
Boolean response = (Boolean) responseTask2.returnData;
|
||||||
|
|
||||||
if (response) {
|
if (response) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute - Current TBR cancelled.");
|
||||||
LOG.info(getLogPrefix() + "setTempBasalAbsolute - Current TBR cancelled.");
|
|
||||||
} else {
|
} else {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.error(getLogPrefix() + "setTempBasalAbsolute - Cancel TBR failed.");
|
||||||
LOG.error(getLogPrefix() + "setTempBasalAbsolute - Cancel TBR failed.");
|
|
||||||
|
|
||||||
finishAction("TBR");
|
finishAction("TBR");
|
||||||
|
|
||||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||||
.comment(MainApp.gs(R.string.medtronic_cmd_cant_cancel_tbr_stop_op));
|
.comment(getResourceHelper().gs(R.string.medtronic_cmd_cant_cancel_tbr_stop_op));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1067,8 +1022,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
Boolean response = (Boolean) responseTask.returnData;
|
Boolean response = (Boolean) responseTask.returnData;
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute - setTBR. Response: " + response);
|
||||||
LOG.info(getLogPrefix() + "setTempBasalAbsolute - setTBR. Response: " + response);
|
|
||||||
|
|
||||||
if (response) {
|
if (response) {
|
||||||
// FIXME put this into UIPostProcessor
|
// FIXME put this into UIPostProcessor
|
||||||
|
@ -1082,7 +1036,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
.absolute(absoluteRate) //
|
.absolute(absoluteRate) //
|
||||||
.source(Source.USER);
|
.source(Source.USER);
|
||||||
|
|
||||||
treatmentsPlugin.addToHistoryTempBasal(tempStart);
|
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempStart);
|
||||||
|
|
||||||
incrementStatistics(MedtronicConst.Statistics.TBRsSet);
|
incrementStatistics(MedtronicConst.Statistics.TBRsSet);
|
||||||
|
|
||||||
|
@ -1095,7 +1049,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
finishAction("TBR");
|
finishAction("TBR");
|
||||||
|
|
||||||
return new PumpEnactResult(getInjector()).success(false).enacted(false) //
|
return new PumpEnactResult(getInjector()).success(false).enacted(false) //
|
||||||
.comment(MainApp.gs(R.string.medtronic_cmd_tbr_could_not_be_delivered));
|
.comment(getResourceHelper().gs(R.string.medtronic_cmd_tbr_could_not_be_delivered));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1110,7 +1064,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
double absoluteValue = profile.getBasal() * (percent / 100.0d);
|
double absoluteValue = profile.getBasal() * (percent / 100.0d);
|
||||||
getMDTPumpStatus();
|
getMDTPumpStatus();
|
||||||
absoluteValue = pumpStatusLocal.pumpType.determineCorrectBasalSize(absoluteValue);
|
absoluteValue = pumpStatusLocal.pumpType.determineCorrectBasalSize(absoluteValue);
|
||||||
LOG.warn("setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% (%d). This will start setTempBasalAbsolute, with calculated value (%.3f). Result might not be 100% correct.", percent, absoluteValue);
|
aapsLogger.warn(LTag.PUMP, "setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% (" + percent + "). This will start setTempBasalAbsolute, with calculated value (" + absoluteValue + "). Result might not be 100% correct.");
|
||||||
return setTempBasalAbsolute(absoluteValue, durationInMinutes, profile, enforceNew);
|
return setTempBasalAbsolute(absoluteValue, durationInMinutes, profile, enforceNew);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1119,7 +1073,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
private void finishAction(String overviewKey) {
|
private void finishAction(String overviewKey) {
|
||||||
|
|
||||||
if (overviewKey != null)
|
if (overviewKey != null)
|
||||||
RxBus.Companion.getINSTANCE().send(new EventRefreshOverview(overviewKey));
|
rxBus.send(new EventRefreshOverview(overviewKey));
|
||||||
|
|
||||||
triggerUIChange();
|
triggerUIChange();
|
||||||
|
|
||||||
|
@ -1153,14 +1107,12 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
if (medtronicHistoryData.isPumpSuspended()) {
|
if (medtronicHistoryData.isPumpSuspended()) {
|
||||||
this.pumpState = PumpDriverState.Suspended;
|
this.pumpState = PumpDriverState.Suspended;
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "isPumpSuspended: true");
|
||||||
LOG.debug(getLogPrefix() + "isPumpSuspended: true");
|
|
||||||
} else {
|
} else {
|
||||||
if (previousState == PumpDriverState.Suspended) {
|
if (previousState == PumpDriverState.Suspended) {
|
||||||
this.pumpState = PumpDriverState.Ready;
|
this.pumpState = PumpDriverState.Ready;
|
||||||
}
|
}
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "isPumpSuspended: false");
|
||||||
LOG.debug(getLogPrefix() + "isPumpSuspended: false");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
medtronicHistoryData.processNewHistoryData();
|
medtronicHistoryData.processNewHistoryData();
|
||||||
|
@ -1177,8 +1129,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
if (lastPumpHistoryEntry == null) {
|
if (lastPumpHistoryEntry == null) {
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntry: null");
|
||||||
LOG.debug(getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntry: null");
|
|
||||||
|
|
||||||
Long lastPumpHistoryEntryTime = getLastPumpEntryTime();
|
Long lastPumpHistoryEntryTime = getLastPumpEntryTime();
|
||||||
|
|
||||||
|
@ -1187,16 +1138,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
medtronicHistoryData.setIsInInit(true);
|
medtronicHistoryData.setIsInInit(true);
|
||||||
|
|
||||||
if (lastPumpHistoryEntryTime == 0L) {
|
if (lastPumpHistoryEntryTime == 0L) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: 0L - targetDate: "
|
||||||
LOG.debug(getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: 0L - targetDate: "
|
|
||||||
+ targetDate);
|
+ targetDate);
|
||||||
targetDate = timeMinus36h;
|
targetDate = timeMinus36h;
|
||||||
} else {
|
} else {
|
||||||
// LocalDateTime lastHistoryRecordTime = DateTimeUtil.toLocalDateTime(lastPumpHistoryEntryTime);
|
// LocalDateTime lastHistoryRecordTime = DateTimeUtil.toLocalDateTime(lastPumpHistoryEntryTime);
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: " + lastPumpHistoryEntryTime + " - targetDate: " + targetDate);
|
||||||
LOG.debug(getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: {} - targetDate: {}",
|
|
||||||
lastPumpHistoryEntryTime, targetDate);
|
|
||||||
|
|
||||||
medtronicHistoryData.setLastHistoryRecordTime(lastPumpHistoryEntryTime);
|
medtronicHistoryData.setLastHistoryRecordTime(lastPumpHistoryEntryTime);
|
||||||
|
|
||||||
|
@ -1212,34 +1160,30 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
targetDate = (timeMinus36h.isAfter(lastHistoryRecordTime) ? timeMinus36h : lastHistoryRecordTime);
|
targetDate = (timeMinus36h.isAfter(lastHistoryRecordTime) ? timeMinus36h : lastHistoryRecordTime);
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "readPumpHistoryLogic(): targetDate: " + targetDate);
|
||||||
LOG.debug(getLogPrefix() + "readPumpHistoryLogic(): targetDate: " + targetDate);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntry: not null - " + MedtronicUtil.gsonInstance.toJson(lastPumpHistoryEntry));
|
||||||
LOG.debug(getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntry: not null - {}",
|
|
||||||
MedtronicUtil.gsonInstance.toJson(lastPumpHistoryEntry));
|
|
||||||
medtronicHistoryData.setIsInInit(false);
|
medtronicHistoryData.setIsInInit(false);
|
||||||
// medtronicHistoryData.setLastHistoryRecordTime(lastPumpHistoryEntry.atechDateTime);
|
// medtronicHistoryData.setLastHistoryRecordTime(lastPumpHistoryEntry.atechDateTime);
|
||||||
|
|
||||||
// targetDate = lastPumpHistoryEntry.atechDateTime;
|
// targetDate = lastPumpHistoryEntry.atechDateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("HST: Target Date: {}", targetDate);
|
aapsLogger.debug(LTag.PUMP, "HST: Target Date: " + targetDate);
|
||||||
|
|
||||||
MedtronicUITask responseTask2 = medtronicUIComm.executeCommand(MedtronicCommandType.GetHistoryData,
|
MedtronicUITask responseTask2 = medtronicUIComm.executeCommand(MedtronicCommandType.GetHistoryData,
|
||||||
lastPumpHistoryEntry, targetDate);
|
lastPumpHistoryEntry, targetDate);
|
||||||
|
|
||||||
LOG.debug("HST: After task");
|
aapsLogger.debug(LTag.PUMP, "HST: After task");
|
||||||
|
|
||||||
PumpHistoryResult historyResult = (PumpHistoryResult) responseTask2.returnData;
|
PumpHistoryResult historyResult = (PumpHistoryResult) responseTask2.returnData;
|
||||||
|
|
||||||
LOG.debug("HST: History Result: {}", historyResult.toString());
|
aapsLogger.debug(LTag.PUMP, "HST: History Result: " + historyResult.toString());
|
||||||
|
|
||||||
PumpHistoryEntry latestEntry = historyResult.getLatestEntry();
|
PumpHistoryEntry latestEntry = historyResult.getLatestEntry();
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "Last entry: " + latestEntry);
|
||||||
LOG.debug(getLogPrefix() + "Last entry: " + latestEntry);
|
|
||||||
|
|
||||||
if (latestEntry == null) // no new history to read
|
if (latestEntry == null) // no new history to read
|
||||||
return;
|
return;
|
||||||
|
@ -1247,8 +1191,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
this.lastPumpHistoryEntry = latestEntry;
|
this.lastPumpHistoryEntry = latestEntry;
|
||||||
sp.putLong(MedtronicConst.Statistics.LastPumpHistoryEntry, latestEntry.atechDateTime);
|
sp.putLong(MedtronicConst.Statistics.LastPumpHistoryEntry, latestEntry.atechDateTime);
|
||||||
|
|
||||||
LOG.debug("HST: History: valid={}, unprocessed={}", historyResult.validEntries.size(),
|
aapsLogger.debug(LTag.PUMP, "HST: History: valid=" + historyResult.validEntries.size() + ", unprocessed=" + historyResult.unprocessedEntries.size());
|
||||||
historyResult.unprocessedEntries.size());
|
|
||||||
|
|
||||||
this.medtronicHistoryData.addNewHistory(historyResult);
|
this.medtronicHistoryData.addNewHistory(historyResult);
|
||||||
this.medtronicHistoryData.filterNewEntries();
|
this.medtronicHistoryData.filterNewEntries();
|
||||||
|
@ -1282,14 +1225,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
LocalDateTime localDateTime = DateTimeUtil.toLocalDateTime(lastPumpEntryTime);
|
LocalDateTime localDateTime = DateTimeUtil.toLocalDateTime(lastPumpEntryTime);
|
||||||
|
|
||||||
if (localDateTime.getYear() != (new GregorianCalendar().get(Calendar.YEAR))) {
|
if (localDateTime.getYear() != (new GregorianCalendar().get(Calendar.YEAR))) {
|
||||||
LOG.warn("Saved LastPumpHistoryEntry was invalid. Year was not the same.");
|
aapsLogger.warn(LTag.PUMP, "Saved LastPumpHistoryEntry was invalid. Year was not the same.");
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
return lastPumpEntryTime;
|
return lastPumpEntryTime;
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.warn("Saved LastPumpHistoryEntry was invalid.");
|
aapsLogger.warn(LTag.PUMP, "Saved LastPumpHistoryEntry was invalid.");
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1389,8 +1332,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - started");
|
||||||
LOG.info(getLogPrefix() + "cancelTempBasal - started");
|
|
||||||
|
|
||||||
if (isPumpNotReachable()) {
|
if (isPumpNotReachable()) {
|
||||||
|
|
||||||
|
@ -1399,7 +1341,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
return new PumpEnactResult(getInjector()) //
|
return new PumpEnactResult(getInjector()) //
|
||||||
.success(false) //
|
.success(false) //
|
||||||
.enacted(false) //
|
.enacted(false) //
|
||||||
.comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable));
|
.comment(getResourceHelper().gs(R.string.medtronic_pump_status_pump_unreachable));
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
|
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
|
||||||
|
@ -1409,17 +1351,15 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
if (tbrCurrent != null) {
|
if (tbrCurrent != null) {
|
||||||
if (tbrCurrent.getInsulinRate() == 0.0f && tbrCurrent.getDurationMinutes() == 0) {
|
if (tbrCurrent.getInsulinRate() == 0.0f && tbrCurrent.getDurationMinutes() == 0) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - TBR already canceled.");
|
||||||
LOG.info(getLogPrefix() + "cancelTempBasal - TBR already canceled.");
|
|
||||||
finishAction("TBR");
|
finishAction("TBR");
|
||||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.warn(LTag.PUMP, getLogPrefix() + "cancelTempBasal - Could not read currect TBR, canceling operation.");
|
||||||
LOG.warn(getLogPrefix() + "cancelTempBasal - Could not read currect TBR, canceling operation.");
|
|
||||||
finishAction("TBR");
|
finishAction("TBR");
|
||||||
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
return new PumpEnactResult(getInjector()).success(false).enacted(false)
|
||||||
.comment(MainApp.gs(R.string.medtronic_cmd_cant_read_tbr));
|
.comment(getResourceHelper().gs(R.string.medtronic_cmd_cant_read_tbr));
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicUITask responseTask2 = medtronicUIComm.executeCommand(MedtronicCommandType.CancelTBR);
|
MedtronicUITask responseTask2 = medtronicUIComm.executeCommand(MedtronicCommandType.CancelTBR);
|
||||||
|
@ -1429,24 +1369,22 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
finishAction("TBR");
|
finishAction("TBR");
|
||||||
|
|
||||||
if (response) {
|
if (response) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - Cancel TBR successful.");
|
||||||
LOG.info(getLogPrefix() + "cancelTempBasal - Cancel TBR successful.");
|
|
||||||
|
|
||||||
TemporaryBasal tempBasal = new TemporaryBasal() //
|
TemporaryBasal tempBasal = new TemporaryBasal() //
|
||||||
.date(System.currentTimeMillis()) //
|
.date(System.currentTimeMillis()) //
|
||||||
.duration(0) //
|
.duration(0) //
|
||||||
.source(Source.USER);
|
.source(Source.USER);
|
||||||
|
|
||||||
treatmentsPlugin.addToHistoryTempBasal(tempBasal);
|
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempBasal);
|
||||||
|
|
||||||
return new PumpEnactResult(getInjector()).success(true).enacted(true) //
|
return new PumpEnactResult(getInjector()).success(true).enacted(true) //
|
||||||
.isTempCancel(true);
|
.isTempCancel(true);
|
||||||
} else {
|
} else {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - Cancel TBR failed.");
|
||||||
LOG.info(getLogPrefix() + "cancelTempBasal - Cancel TBR failed.");
|
|
||||||
|
|
||||||
return new PumpEnactResult(getInjector()).success(response).enacted(response) //
|
return new PumpEnactResult(getInjector()).success(response).enacted(response) //
|
||||||
.comment(MainApp.gs(R.string.medtronic_cmd_cant_cancel_tbr));
|
.comment(getResourceHelper().gs(R.string.medtronic_cmd_cant_cancel_tbr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1467,15 +1405,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setNewBasalProfile");
|
||||||
LOG.info(getLogPrefix() + "setNewBasalProfile");
|
|
||||||
|
|
||||||
// this shouldn't be needed, but let's do check if profile setting we are setting is same as current one
|
// this shouldn't be needed, but let's do check if profile setting we are setting is same as current one
|
||||||
if (isProfileSame(profile)) {
|
if (isProfileSame(profile)) {
|
||||||
return new PumpEnactResult(getInjector()) //
|
return new PumpEnactResult(getInjector()) //
|
||||||
.success(true) //
|
.success(true) //
|
||||||
.enacted(false) //
|
.enacted(false) //
|
||||||
.comment(MainApp.gs(R.string.medtronic_cmd_basal_profile_not_set_is_same));
|
.comment(getResourceHelper().gs(R.string.medtronic_cmd_basal_profile_not_set_is_same));
|
||||||
}
|
}
|
||||||
|
|
||||||
setRefreshButtonEnabled(false);
|
setRefreshButtonEnabled(false);
|
||||||
|
@ -1487,7 +1424,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
return new PumpEnactResult(getInjector()) //
|
return new PumpEnactResult(getInjector()) //
|
||||||
.success(false) //
|
.success(false) //
|
||||||
.enacted(false) //
|
.enacted(false) //
|
||||||
.comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable));
|
.comment(getResourceHelper().gs(R.string.medtronic_pump_status_pump_unreachable));
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
|
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
|
||||||
|
@ -1500,7 +1437,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
return new PumpEnactResult(getInjector()) //
|
return new PumpEnactResult(getInjector()) //
|
||||||
.success(false) //
|
.success(false) //
|
||||||
.enacted(false) //
|
.enacted(false) //
|
||||||
.comment(MainApp.gs(R.string.medtronic_cmd_set_profile_pattern_overflow, profileInvalid));
|
.comment(getResourceHelper().gs(R.string.medtronic_cmd_set_profile_pattern_overflow, profileInvalid));
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetBasalProfileSTD,
|
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetBasalProfileSTD,
|
||||||
|
@ -1508,14 +1445,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
Boolean response = (Boolean) responseTask.returnData;
|
Boolean response = (Boolean) responseTask.returnData;
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "Basal Profile was set: " + response);
|
||||||
LOG.info(getLogPrefix() + "Basal Profile was set: " + response);
|
|
||||||
|
|
||||||
if (response) {
|
if (response) {
|
||||||
return new PumpEnactResult(getInjector()).success(true).enacted(true);
|
return new PumpEnactResult(getInjector()).success(true).enacted(true);
|
||||||
} else {
|
} else {
|
||||||
return new PumpEnactResult(getInjector()).success(response).enacted(response) //
|
return new PumpEnactResult(getInjector()).success(response).enacted(response) //
|
||||||
.comment(MainApp.gs(R.string.medtronic_cmd_basal_profile_could_not_be_set));
|
.comment(getResourceHelper().gs(R.string.medtronic_cmd_basal_profile_could_not_be_set));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1604,12 +1540,12 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
if (MedtronicUtil.getPumpStatus().verifyConfiguration()) {
|
if (MedtronicUtil.getPumpStatus().verifyConfiguration()) {
|
||||||
ServiceTaskExecutor.startTask(new WakeAndTuneTask());
|
ServiceTaskExecutor.startTask(new WakeAndTuneTask());
|
||||||
} else {
|
} else {
|
||||||
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
Intent i = new Intent(context, ErrorHelperActivity.class);
|
||||||
i.putExtra("soundid", R.raw.boluserror);
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
i.putExtra("status", MainApp.gs(R.string.medtronic_error_operation_not_possible_no_configuration));
|
i.putExtra("status", getResourceHelper().gs(R.string.medtronic_error_operation_not_possible_no_configuration));
|
||||||
i.putExtra("title", MainApp.gs(R.string.combo_warning));
|
i.putExtra("title", getResourceHelper().gs(R.string.combo_warning));
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
MainApp.instance().startActivity(i);
|
context.startActivity(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1635,14 +1571,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
@Override
|
@Override
|
||||||
public void timeDateOrTimeZoneChanged() {
|
public void timeDateOrTimeZoneChanged() {
|
||||||
|
|
||||||
if (isLoggingEnabled())
|
aapsLogger.warn(LTag.PUMP, getLogPrefix() + "Time, Date and/or TimeZone changed. ");
|
||||||
LOG.warn(getLogPrefix() + "Time, Date and/or TimeZone changed. ");
|
|
||||||
|
|
||||||
this.hasTimeDateOrTimeZoneChanged = true;
|
this.hasTimeDateOrTimeZoneChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshCustomActionsList() {
|
private void refreshCustomActionsList() {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventCustomActionsChanged());
|
rxBus.send(new EventCustomActionsChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,6 @@ import org.joda.time.LocalDateTime;
|
||||||
import org.joda.time.Minutes;
|
import org.joda.time.Minutes;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -29,10 +27,10 @@ import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.db.TDD;
|
import info.nightscout.androidaps.db.TDD;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
||||||
|
@ -54,7 +52,7 @@ import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentService;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentService;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,7 +68,10 @@ import info.nightscout.androidaps.utils.SP;
|
||||||
// All things marked with "TODO: Fix db code" needs to be updated in new 2.5 database code
|
// All things marked with "TODO: Fix db code" needs to be updated in new 2.5 database code
|
||||||
|
|
||||||
public class MedtronicHistoryData {
|
public class MedtronicHistoryData {
|
||||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMP);
|
|
||||||
|
private static AAPSLogger aapsLogger;
|
||||||
|
private SP sp;
|
||||||
|
private ActivePluginProvider activePlugin;
|
||||||
|
|
||||||
private List<PumpHistoryEntry> allHistory = null;
|
private List<PumpHistoryEntry> allHistory = null;
|
||||||
private List<PumpHistoryEntry> newHistory = null;
|
private List<PumpHistoryEntry> newHistory = null;
|
||||||
|
@ -94,11 +95,15 @@ public class MedtronicHistoryData {
|
||||||
public static boolean doubleBolusDebug = false;
|
public static boolean doubleBolusDebug = false;
|
||||||
|
|
||||||
|
|
||||||
public MedtronicHistoryData() {
|
public MedtronicHistoryData(AAPSLogger aapsLogger, SP sp, ActivePluginProvider activePlugin) {
|
||||||
this.allHistory = new ArrayList<>();
|
this.allHistory = new ArrayList<>();
|
||||||
this.gson = MedtronicUtil.gsonInstance;
|
this.gson = MedtronicUtil.gsonInstance;
|
||||||
this.gsonCore = MedtronicUtil.getGsonInstanceCore();
|
this.gsonCore = MedtronicUtil.getGsonInstanceCore();
|
||||||
|
|
||||||
|
this.aapsLogger = aapsLogger;
|
||||||
|
this.sp = sp;
|
||||||
|
this.activePlugin = activePlugin;
|
||||||
|
|
||||||
if (this.gson == null) {
|
if (this.gson == null) {
|
||||||
this.gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
this.gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||||
}
|
}
|
||||||
|
@ -134,20 +139,16 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
|
|
||||||
private static void showLogs(String header, String data) {
|
private static void showLogs(String header, String data) {
|
||||||
|
|
||||||
if (!isLogEnabled())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (header != null) {
|
if (header != null) {
|
||||||
LOG.debug(header);
|
aapsLogger.debug(LTag.PUMP, header);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(data)) {
|
if (StringUtils.isNotBlank(data)) {
|
||||||
for (final String token : StringUtil.splitString(data, 3500)) {
|
for (final String token : StringUtil.splitString(data, 3500)) {
|
||||||
LOG.debug("{}", token);
|
aapsLogger.debug(LTag.PUMP, "{}", token);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.debug("No data.");
|
aapsLogger.debug(LTag.PUMP, "No data.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +165,7 @@ public class MedtronicHistoryData {
|
||||||
List<PumpHistoryEntry> bolusEstimates = new ArrayList<>();
|
List<PumpHistoryEntry> bolusEstimates = new ArrayList<>();
|
||||||
long atechDate = DateTimeUtil.toATechDate(new GregorianCalendar());
|
long atechDate = DateTimeUtil.toATechDate(new GregorianCalendar());
|
||||||
|
|
||||||
//LOG.debug("Filter new entries: Before {}", newHistory);
|
//aapsLogger.debug(LTag.PUMP, "Filter new entries: Before {}", newHistory);
|
||||||
|
|
||||||
if (!isCollectionEmpty(newHistory)) {
|
if (!isCollectionEmpty(newHistory)) {
|
||||||
|
|
||||||
|
@ -205,8 +206,7 @@ public class MedtronicHistoryData {
|
||||||
sort(this.newHistory);
|
sort(this.newHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "New History entries found: {}", this.newHistory.size());
|
||||||
LOG.debug("New History entries found: {}", this.newHistory.size());
|
|
||||||
|
|
||||||
showLogs("List of history (after filtering): [" + this.newHistory.size() + "]", gson.toJson(this.newHistory));
|
showLogs("List of history (after filtering): [" + this.newHistory.size() + "]", gson.toJson(this.newHistory));
|
||||||
|
|
||||||
|
@ -258,14 +258,14 @@ public class MedtronicHistoryData {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.setLastHistoryRecordTime(pheLast.atechDateTime);
|
this.setLastHistoryRecordTime(pheLast.atechDateTime);
|
||||||
SP.putLong(MedtronicConst.Statistics.LastPumpHistoryEntry, pheLast.atechDateTime);
|
sp.putLong(MedtronicConst.Statistics.LastPumpHistoryEntry, pheLast.atechDateTime);
|
||||||
|
|
||||||
LocalDateTime dt = null;
|
LocalDateTime dt = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dt = DateTimeUtil.toLocalDateTime(pheLast.atechDateTime);
|
dt = DateTimeUtil.toLocalDateTime(pheLast.atechDateTime);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("Problem decoding date from last record: {}" + pheLast);
|
aapsLogger.error("Problem decoding date from last record: {}" + pheLast);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dt != null) {
|
if (dt != null) {
|
||||||
|
@ -287,11 +287,10 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
this.sort(this.allHistory);
|
this.sort(this.allHistory);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "All History records [afterFilterCount={}, removedItemsCount={}, newItemsCount={}]",
|
||||||
LOG.debug("All History records [afterFilterCount={}, removedItemsCount={}, newItemsCount={}]",
|
|
||||||
allHistory.size(), removeList.size(), newHistory.size());
|
allHistory.size(), removeList.size(), newHistory.size());
|
||||||
} else {
|
} else {
|
||||||
LOG.error("Since we couldn't determine date, we don't clean full history. This is just workaround.");
|
aapsLogger.error("Since we couldn't determine date, we don't clean full history. This is just workaround.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.newHistory.clear();
|
this.newHistory.clear();
|
||||||
|
@ -335,8 +334,7 @@ public class MedtronicHistoryData {
|
||||||
pumpHistoryEntryType == PumpHistoryEntryType.BatteryChange || //
|
pumpHistoryEntryType == PumpHistoryEntryType.BatteryChange || //
|
||||||
pumpHistoryEntryType == PumpHistoryEntryType.Prime);
|
pumpHistoryEntryType == PumpHistoryEntryType.Prime);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "isPumpSuspended. Last entry type={}, isSuspended={}", pumpHistoryEntryType, isSuspended);
|
||||||
LOG.debug("isPumpSuspended. Last entry type={}, isSuspended={}", pumpHistoryEntryType, isSuspended);
|
|
||||||
|
|
||||||
return isSuspended;
|
return isSuspended;
|
||||||
} else
|
} else
|
||||||
|
@ -409,14 +407,13 @@ public class MedtronicHistoryData {
|
||||||
// Prime (for reseting autosense)
|
// Prime (for reseting autosense)
|
||||||
List<PumpHistoryEntry> primeRecords = getFilteredItems(PumpHistoryEntryType.Prime);
|
List<PumpHistoryEntry> primeRecords = getFilteredItems(PumpHistoryEntryType.Prime);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: Prime [count={}, items={}]", primeRecords.size(), gson.toJson(primeRecords));
|
||||||
LOG.debug("ProcessHistoryData: Prime [count={}, items={}]", primeRecords.size(), gson.toJson(primeRecords));
|
|
||||||
|
|
||||||
if (isCollectionNotEmpty(primeRecords)) {
|
if (isCollectionNotEmpty(primeRecords)) {
|
||||||
try {
|
try {
|
||||||
processPrime(primeRecords);
|
processPrime(primeRecords);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("ProcessHistoryData: Error processing Prime entries: " + ex.getMessage(), ex);
|
aapsLogger.error("ProcessHistoryData: Error processing Prime entries: " + ex.getMessage(), ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,14 +421,13 @@ public class MedtronicHistoryData {
|
||||||
// TDD
|
// TDD
|
||||||
List<PumpHistoryEntry> tdds = getFilteredItems(PumpHistoryEntryType.EndResultTotals, getTDDType());
|
List<PumpHistoryEntry> tdds = getFilteredItems(PumpHistoryEntryType.EndResultTotals, getTDDType());
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: TDD [count={}, items={}]", tdds.size(), gson.toJson(tdds));
|
||||||
LOG.debug("ProcessHistoryData: TDD [count={}, items={}]", tdds.size(), gson.toJson(tdds));
|
|
||||||
|
|
||||||
if (isCollectionNotEmpty(tdds)) {
|
if (isCollectionNotEmpty(tdds)) {
|
||||||
try {
|
try {
|
||||||
processTDDs(tdds);
|
processTDDs(tdds);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("ProcessHistoryData: Error processing TDD entries: " + ex.getMessage(), ex);
|
aapsLogger.error("ProcessHistoryData: Error processing TDD entries: " + ex.getMessage(), ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -441,14 +437,13 @@ public class MedtronicHistoryData {
|
||||||
// Bolus
|
// Bolus
|
||||||
List<PumpHistoryEntry> treatments = getFilteredItems(PumpHistoryEntryType.Bolus);
|
List<PumpHistoryEntry> treatments = getFilteredItems(PumpHistoryEntryType.Bolus);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: Bolus [count={}, items={}]", treatments.size(), gson.toJson(treatments));
|
||||||
LOG.debug("ProcessHistoryData: Bolus [count={}, items={}]", treatments.size(), gson.toJson(treatments));
|
|
||||||
|
|
||||||
if (treatments.size() > 0) {
|
if (treatments.size() > 0) {
|
||||||
try {
|
try {
|
||||||
processBolusEntries(treatments);
|
processBolusEntries(treatments);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("ProcessHistoryData: Error processing Bolus entries: " + ex.getMessage(), ex);
|
aapsLogger.error("ProcessHistoryData: Error processing Bolus entries: " + ex.getMessage(), ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -456,14 +451,13 @@ public class MedtronicHistoryData {
|
||||||
// TBR
|
// TBR
|
||||||
List<PumpHistoryEntry> tbrs = getFilteredItems(PumpHistoryEntryType.TempBasalCombined);
|
List<PumpHistoryEntry> tbrs = getFilteredItems(PumpHistoryEntryType.TempBasalCombined);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: TBRs Processed [count={}, items={}]", tbrs.size(), gson.toJson(tbrs));
|
||||||
LOG.debug("ProcessHistoryData: TBRs Processed [count={}, items={}]", tbrs.size(), gson.toJson(tbrs));
|
|
||||||
|
|
||||||
if (tbrs.size() > 0) {
|
if (tbrs.size() > 0) {
|
||||||
try {
|
try {
|
||||||
processTBREntries(tbrs);
|
processTBREntries(tbrs);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("ProcessHistoryData: Error processing TBR entries: " + ex.getMessage(), ex);
|
aapsLogger.error("ProcessHistoryData: Error processing TBR entries: " + ex.getMessage(), ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -474,19 +468,18 @@ public class MedtronicHistoryData {
|
||||||
try {
|
try {
|
||||||
suspends = getSuspends();
|
suspends = getSuspends();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("ProcessHistoryData: Error getting Suspend entries: " + ex.getMessage(), ex);
|
aapsLogger.error("ProcessHistoryData: Error getting Suspend entries: " + ex.getMessage(), ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "ProcessHistoryData: 'Delivery Suspend' Processed [count={}, items={}]", suspends.size(),
|
||||||
LOG.debug("ProcessHistoryData: 'Delivery Suspend' Processed [count={}, items={}]", suspends.size(),
|
|
||||||
gson.toJson(suspends));
|
gson.toJson(suspends));
|
||||||
|
|
||||||
if (isCollectionNotEmpty(suspends)) {
|
if (isCollectionNotEmpty(suspends)) {
|
||||||
try {
|
try {
|
||||||
processSuspends(suspends);
|
processSuspends(suspends);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("ProcessHistoryData: Error processing Suspends entries: " + ex.getMessage(), ex);
|
aapsLogger.error("ProcessHistoryData: Error processing Suspends entries: " + ex.getMessage(), ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -509,12 +502,12 @@ public class MedtronicHistoryData {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastPrimeRecord != 0L) {
|
if (lastPrimeRecord != 0L) {
|
||||||
long lastPrimeFromAAPS = SP.getLong(MedtronicConst.Statistics.LastPrime, 0L);
|
long lastPrimeFromAAPS = sp.getLong(MedtronicConst.Statistics.LastPrime, 0L);
|
||||||
|
|
||||||
if (lastPrimeRecord != lastPrimeFromAAPS) {
|
if (lastPrimeRecord != lastPrimeFromAAPS) {
|
||||||
uploadCareportalEvent(DateTimeUtil.toMillisFromATD(lastPrimeRecord), CareportalEvent.SITECHANGE);
|
uploadCareportalEvent(DateTimeUtil.toMillisFromATD(lastPrimeRecord), CareportalEvent.SITECHANGE);
|
||||||
|
|
||||||
SP.putLong(MedtronicConst.Statistics.LastPrime, lastPrimeRecord);
|
sp.putLong(MedtronicConst.Statistics.LastPrime, lastPrimeRecord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -525,7 +518,7 @@ public class MedtronicHistoryData {
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
String enteredBy = SP.getString("careportal_enteredby", "");
|
String enteredBy = sp.getString("careportal_enteredby", "");
|
||||||
if (!enteredBy.equals("")) data.put("enteredBy", enteredBy);
|
if (!enteredBy.equals("")) data.put("enteredBy", enteredBy);
|
||||||
data.put("created_at", DateUtil.toISOString(date));
|
data.put("created_at", DateUtil.toISOString(date));
|
||||||
data.put("eventType", event);
|
data.put("eventType", event);
|
||||||
|
@ -537,7 +530,7 @@ public class MedtronicHistoryData {
|
||||||
MainApp.getDbHelper().createOrUpdate(careportalEvent);
|
MainApp.getDbHelper().createOrUpdate(careportalEvent);
|
||||||
NSUpload.uploadCareportalEntryToNS(data);
|
NSUpload.uploadCareportalEntryToNS(data);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
LOG.error("Unhandled exception", e);
|
aapsLogger.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,8 +539,7 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
List<PumpHistoryEntry> tdds = filterTDDs(tddsIn);
|
List<PumpHistoryEntry> tdds = filterTDDs(tddsIn);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, getLogPrefix() + "TDDs found: {}.\n{}", tdds.size(), gson.toJson(tdds));
|
||||||
LOG.debug(getLogPrefix() + "TDDs found: {}.\n{}", tdds.size(), gson.toJson(tdds));
|
|
||||||
|
|
||||||
List<TDD> tddsDb = databaseHelper.getTDDsForLastXDays(3);
|
List<TDD> tddsDb = databaseHelper.getTDDsForLastXDays(3);
|
||||||
|
|
||||||
|
@ -557,14 +549,13 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
DailyTotalsDTO totalsDTO = (DailyTotalsDTO) tdd.getDecodedData().get("Object");
|
DailyTotalsDTO totalsDTO = (DailyTotalsDTO) tdd.getDecodedData().get("Object");
|
||||||
|
|
||||||
//LOG.debug("DailyTotals: {}", totalsDTO);
|
//aapsLogger.debug(LTag.PUMP, "DailyTotals: {}", totalsDTO);
|
||||||
|
|
||||||
if (tddDbEntry == null) {
|
if (tddDbEntry == null) {
|
||||||
TDD tddNew = new TDD();
|
TDD tddNew = new TDD();
|
||||||
totalsDTO.setTDD(tddNew);
|
totalsDTO.setTDD(tddNew);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "TDD Add: {}", tddNew);
|
||||||
LOG.debug("TDD Add: {}", tddNew);
|
|
||||||
|
|
||||||
databaseHelper.createOrUpdateTDD(tddNew);
|
databaseHelper.createOrUpdateTDD(tddNew);
|
||||||
|
|
||||||
|
@ -573,8 +564,7 @@ public class MedtronicHistoryData {
|
||||||
if (!totalsDTO.doesEqual(tddDbEntry)) {
|
if (!totalsDTO.doesEqual(tddDbEntry)) {
|
||||||
totalsDTO.setTDD(tddDbEntry);
|
totalsDTO.setTDD(tddDbEntry);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "TDD Edit: {}", tddDbEntry);
|
||||||
LOG.debug("TDD Edit: {}", tddDbEntry);
|
|
||||||
|
|
||||||
databaseHelper.createOrUpdateTDD(tddDbEntry);
|
databaseHelper.createOrUpdateTDD(tddDbEntry);
|
||||||
}
|
}
|
||||||
|
@ -610,39 +600,37 @@ public class MedtronicHistoryData {
|
||||||
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.Bolus);
|
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.Bolus);
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: List (before filter): {}, FromDb={}", gson.toJson(entryList),
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: List (before filter): {}, FromDb={}", gson.toJson(entryList),
|
||||||
gsonCore.toJson(entriesFromHistory));
|
gsonCore.toJson(entriesFromHistory));
|
||||||
|
|
||||||
filterOutAlreadyAddedEntries(entryList, entriesFromHistory);
|
filterOutAlreadyAddedEntries(entryList, entriesFromHistory);
|
||||||
|
|
||||||
if (entryList.isEmpty()) {
|
if (entryList.isEmpty()) {
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: EntryList was filtered out.");
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: EntryList was filtered out.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
filterOutNonInsulinEntries(entriesFromHistory);
|
filterOutNonInsulinEntries(entriesFromHistory);
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: List (after filter): {}, FromDb={}", gson.toJson(entryList),
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: List (after filter): {}, FromDb={}", gson.toJson(entryList),
|
||||||
gsonCore.toJson(entriesFromHistory));
|
gsonCore.toJson(entriesFromHistory));
|
||||||
|
|
||||||
if (isCollectionEmpty(entriesFromHistory)) {
|
if (isCollectionEmpty(entriesFromHistory)) {
|
||||||
for (PumpHistoryEntry treatment : entryList) {
|
for (PumpHistoryEntry treatment : entryList) {
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "Add Bolus (no db entry): " + treatment);
|
||||||
LOG.debug("Add Bolus (no db entry): " + treatment);
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: Add Bolus: FromDb=null, Treatment={}", treatment);
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: Add Bolus: FromDb=null, Treatment={}", treatment);
|
||||||
|
|
||||||
addBolus(treatment, null);
|
addBolus(treatment, null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (PumpHistoryEntry treatment : entryList) {
|
for (PumpHistoryEntry treatment : entryList) {
|
||||||
DbObjectBase treatmentDb = findDbEntry(treatment, entriesFromHistory);
|
DbObjectBase treatmentDb = findDbEntry(treatment, entriesFromHistory);
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "Add Bolus {} - (entryFromDb={}) ", treatment, treatmentDb);
|
||||||
LOG.debug("Add Bolus {} - (entryFromDb={}) ", treatment, treatmentDb);
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: Add Bolus: FromDb={}, Treatment={}", treatmentDb, treatment);
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: Add Bolus: FromDb={}, Treatment={}", treatmentDb, treatment);
|
||||||
|
|
||||||
addBolus(treatment, (Treatment) treatmentDb);
|
addBolus(treatment, (Treatment) treatmentDb);
|
||||||
}
|
}
|
||||||
|
@ -690,8 +678,7 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.TBR);
|
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.TBR);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, ProcessHistoryRecord.TBR.getDescription() + " List (before filter): {}, FromDb={}", gson.toJson(entryList),
|
||||||
LOG.debug(ProcessHistoryRecord.TBR.getDescription() + " List (before filter): {}, FromDb={}", gson.toJson(entryList),
|
|
||||||
gson.toJson(entriesFromHistory));
|
gson.toJson(entriesFromHistory));
|
||||||
|
|
||||||
|
|
||||||
|
@ -712,7 +699,7 @@ public class MedtronicHistoryData {
|
||||||
readOldItem = false;
|
readOldItem = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.error("processDTO was null - shouldn't happen. ItemTwo={}", treatment);
|
aapsLogger.error("processDTO was null - shouldn't happen. ItemTwo={}", treatment);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (processDTO != null) {
|
if (processDTO != null) {
|
||||||
|
@ -744,10 +731,9 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
databaseHelper.createOrUpdate(tempBasal);
|
databaseHelper.createOrUpdate(tempBasal);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "Edit " + ProcessHistoryRecord.TBR.getDescription() + " - (entryFromDb={}) ", tempBasal);
|
||||||
LOG.debug("Edit " + ProcessHistoryRecord.TBR.getDescription() + " - (entryFromDb={}) ", tempBasal);
|
|
||||||
} else {
|
} else {
|
||||||
LOG.error("TempBasal not found. Item: {}", tempBasalProcessDTO.itemOne);
|
aapsLogger.error("TempBasal not found. Item: {}", tempBasalProcessDTO.itemOne);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -763,14 +749,13 @@ public class MedtronicHistoryData {
|
||||||
if (tempBasal == null) {
|
if (tempBasal == null) {
|
||||||
DbObjectBase treatmentDb = findDbEntry(treatment, entriesFromHistory);
|
DbObjectBase treatmentDb = findDbEntry(treatment, entriesFromHistory);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "Add " + ProcessHistoryRecord.TBR.getDescription() + " {} - (entryFromDb={}) ", treatment, treatmentDb);
|
||||||
LOG.debug("Add " + ProcessHistoryRecord.TBR.getDescription() + " {} - (entryFromDb={}) ", treatment, treatmentDb);
|
|
||||||
|
|
||||||
addTBR(treatment, (TemporaryBasal) treatmentDb);
|
addTBR(treatment, (TemporaryBasal) treatmentDb);
|
||||||
} else {
|
} else {
|
||||||
// this shouldn't happen
|
// this shouldn't happen
|
||||||
if (tempBasal.durationInMinutes != tempBasalProcessDTO.getDuration()) {
|
if (tempBasal.durationInMinutes != tempBasalProcessDTO.getDuration()) {
|
||||||
LOG.debug("Found entry with wrong duration (shouldn't happen)... updating");
|
aapsLogger.debug(LTag.PUMP, "Found entry with wrong duration (shouldn't happen)... updating");
|
||||||
tempBasal.durationInMinutes = tempBasalProcessDTO.getDuration();
|
tempBasal.durationInMinutes = tempBasalProcessDTO.getDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -813,26 +798,26 @@ public class MedtronicHistoryData {
|
||||||
//proposedTime += (this.pumpTime.timeDifference * 1000);
|
//proposedTime += (this.pumpTime.timeDifference * 1000);
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}", treatment, gson.toJson(entriesFromHistory));
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}", treatment, gson.toJson(entriesFromHistory));
|
||||||
|
|
||||||
if (entriesFromHistory.size() == 0) {
|
if (entriesFromHistory.size() == 0) {
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: findDbEntry Treatment={}, FromDb=null", treatment);
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: findDbEntry Treatment={}, FromDb=null", treatment);
|
||||||
return null;
|
return null;
|
||||||
} else if (entriesFromHistory.size() == 1) {
|
} else if (entriesFromHistory.size() == 1) {
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}. Type=SingleEntry", treatment, entriesFromHistory.get(0));
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}. Type=SingleEntry", treatment, entriesFromHistory.get(0));
|
||||||
|
|
||||||
// TODO: Fix db code
|
// TODO: Fix db code
|
||||||
// if difference is bigger than 2 minutes we discard entry
|
// if difference is bigger than 2 minutes we discard entry
|
||||||
long maxMillisAllowed = DateTimeUtil.getMillisFromATDWithAddedMinutes(treatment.atechDateTime, 2);
|
long maxMillisAllowed = DateTimeUtil.getMillisFromATDWithAddedMinutes(treatment.atechDateTime, 2);
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: findDbEntry maxMillisAllowed={}, AtechDateTime={} (add 2 minutes). ", maxMillisAllowed, treatment.atechDateTime);
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: findDbEntry maxMillisAllowed={}, AtechDateTime={} (add 2 minutes). ", maxMillisAllowed, treatment.atechDateTime);
|
||||||
|
|
||||||
if (entriesFromHistory.get(0).getDate() > maxMillisAllowed) {
|
if (entriesFromHistory.get(0).getDate() > maxMillisAllowed) {
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: findDbEntry entry filtered out, returning null. ");
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: findDbEntry entry filtered out, returning null. ");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -860,17 +845,16 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
if (outList.size() == 1) {
|
if (outList.size() == 1) {
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}. Type=EntrySelected, AtTimeMin={}, AtTimeSec={}", treatment, entriesFromHistory.get(0), min, sec);
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}. Type=EntrySelected, AtTimeMin={}, AtTimeSec={}", treatment, entriesFromHistory.get(0), min, sec);
|
||||||
|
|
||||||
return outList.get(0);
|
return outList.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (min == 0 && sec == 10 && outList.size() > 1) {
|
if (min == 0 && sec == 10 && outList.size() > 1) {
|
||||||
if (isLogEnabled())
|
aapsLogger.error("Too many entries (with too small diff): (timeDiff=[min={},sec={}],count={},list={})",
|
||||||
LOG.error("Too many entries (with too small diff): (timeDiff=[min={},sec={}],count={},list={})",
|
|
||||||
min, sec, outList.size(), gson.toJson(outList));
|
min, sec, outList.size(), gson.toJson(outList));
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: findDbEntry Error - Too many entries (with too small diff): (timeDiff=[min={},sec={}],count={},list={})",
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: findDbEntry Error - Too many entries (with too small diff): (timeDiff=[min={},sec={}],count={},list={})",
|
||||||
min, sec, outList.size(), gson.toJson(outList));
|
min, sec, outList.size(), gson.toJson(outList));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -882,7 +866,7 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
private List<? extends DbObjectBase> getDatabaseEntriesByLastTimestamp(long startTimestamp, ProcessHistoryRecord processHistoryRecord) {
|
private List<? extends DbObjectBase> getDatabaseEntriesByLastTimestamp(long startTimestamp, ProcessHistoryRecord processHistoryRecord) {
|
||||||
if (processHistoryRecord == ProcessHistoryRecord.Bolus) {
|
if (processHistoryRecord == ProcessHistoryRecord.Bolus) {
|
||||||
return TreatmentsPlugin.getPlugin().getTreatmentsFromHistoryAfterTimestamp(startTimestamp);
|
return activePlugin.getActiveTreatments().getTreatmentsFromHistoryAfterTimestamp(startTimestamp);
|
||||||
} else {
|
} else {
|
||||||
return databaseHelper.getTemporaryBasalsDataFromTime(startTimestamp, true);
|
return databaseHelper.getTemporaryBasalsDataFromTime(startTimestamp, true);
|
||||||
}
|
}
|
||||||
|
@ -920,7 +904,7 @@ public class MedtronicHistoryData {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: filterOutAlreadyAddedEntries: PumpHistory={}, Treatments={}",
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: filterOutAlreadyAddedEntries: PumpHistory={}, Treatments={}",
|
||||||
gson.toJson(removeTreatmentsFromPH),
|
gson.toJson(removeTreatmentsFromPH),
|
||||||
gsonCore.toJson(removeTreatmentsFromHistory));
|
gsonCore.toJson(removeTreatmentsFromHistory));
|
||||||
|
|
||||||
|
@ -934,7 +918,7 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
if (treatment == null) {
|
if (treatment == null) {
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: addBolus(tretament==null): Bolus={}", bolusDTO);
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: addBolus(tretament==null): Bolus={}", bolusDTO);
|
||||||
|
|
||||||
switch (bolusDTO.getBolusType()) {
|
switch (bolusDTO.getBolusType()) {
|
||||||
case Normal: {
|
case Normal: {
|
||||||
|
@ -948,14 +932,13 @@ public class MedtronicHistoryData {
|
||||||
addCarbsFromEstimate(detailedBolusInfo, bolus);
|
addCarbsFromEstimate(detailedBolusInfo, bolus);
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: addBolus(tretament==null): DetailedBolusInfo={}", detailedBolusInfo);
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: addBolus(tretament==null): DetailedBolusInfo={}", detailedBolusInfo);
|
||||||
|
|
||||||
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
|
boolean newRecord = activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false);
|
||||||
|
|
||||||
bolus.setLinkedObject(detailedBolusInfo);
|
bolus.setLinkedObject(detailedBolusInfo);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "addBolus - [date={},pumpId={}, insulin={}, newRecord={}]", detailedBolusInfo.date,
|
||||||
LOG.debug("addBolus - [date={},pumpId={}, insulin={}, newRecord={}]", detailedBolusInfo.date,
|
|
||||||
detailedBolusInfo.pumpId, detailedBolusInfo.insulin, newRecord);
|
detailedBolusInfo.pumpId, detailedBolusInfo.insulin, newRecord);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -973,12 +956,11 @@ public class MedtronicHistoryData {
|
||||||
bolus.setLinkedObject(extendedBolus);
|
bolus.setLinkedObject(extendedBolus);
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: addBolus(tretament==null): ExtendedBolus={}", extendedBolus);
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: addBolus(tretament==null): ExtendedBolus={}", extendedBolus);
|
||||||
|
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
|
activePlugin.getActiveTreatments().addToHistoryExtendedBolus(extendedBolus);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "addBolus - Extended [date={},pumpId={}, insulin={}, duration={}]", extendedBolus.date,
|
||||||
LOG.debug("addBolus - Extended [date={},pumpId={}, insulin={}, duration={}]", extendedBolus.date,
|
|
||||||
extendedBolus.pumpId, extendedBolus.insulin, extendedBolus.durationInMinutes);
|
extendedBolus.pumpId, extendedBolus.insulin, extendedBolus.durationInMinutes);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -988,19 +970,18 @@ public class MedtronicHistoryData {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: addBolus(OldTreatment={}): Bolus={}", treatment, bolusDTO);
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: addBolus(OldTreatment={}): Bolus={}", treatment, bolusDTO);
|
||||||
|
|
||||||
treatment.source = Source.PUMP;
|
treatment.source = Source.PUMP;
|
||||||
treatment.pumpId = bolus.getPumpId();
|
treatment.pumpId = bolus.getPumpId();
|
||||||
treatment.insulin = bolusDTO.getDeliveredAmount();
|
treatment.insulin = bolusDTO.getDeliveredAmount();
|
||||||
|
|
||||||
TreatmentService.UpdateReturn updateReturn = TreatmentsPlugin.getPlugin().getService().createOrUpdateMedtronic(treatment, false);
|
TreatmentService.UpdateReturn updateReturn = ((TreatmentsPlugin)activePlugin.getActiveTreatments()).getService().createOrUpdateMedtronic(treatment, false);
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: addBolus(tretament!=null): NewTreatment={}, UpdateReturn={}", treatment, updateReturn);
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: addBolus(tretament!=null): NewTreatment={}, UpdateReturn={}", treatment, updateReturn);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "editBolus - [date={},pumpId={}, insulin={}, newRecord={}]", treatment.date,
|
||||||
LOG.debug("editBolus - [date={},pumpId={}, insulin={}, newRecord={}]", treatment.date,
|
|
||||||
treatment.pumpId, treatment.insulin, updateReturn.toString());
|
treatment.pumpId, treatment.insulin, updateReturn.toString());
|
||||||
|
|
||||||
bolus.setLinkedObject(treatment);
|
bolus.setLinkedObject(treatment);
|
||||||
|
@ -1016,7 +997,7 @@ public class MedtronicHistoryData {
|
||||||
BolusWizardDTO bolusWizard = (BolusWizardDTO) bolus.getDecodedData().get("Estimate");
|
BolusWizardDTO bolusWizard = (BolusWizardDTO) bolus.getDecodedData().get("Estimate");
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: addCarbsFromEstimate: Bolus={}, BolusWizardDTO={}", bolus, bolusWizard);
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: addCarbsFromEstimate: Bolus={}, BolusWizardDTO={}", bolus, bolusWizard);
|
||||||
|
|
||||||
detailedBolusInfo.carbs = bolusWizard.carbs;
|
detailedBolusInfo.carbs = bolusWizard.carbs;
|
||||||
}
|
}
|
||||||
|
@ -1047,8 +1028,7 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
databaseHelper.createOrUpdate(temporaryBasalDb);
|
databaseHelper.createOrUpdate(temporaryBasalDb);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, operation + " - [date={},pumpId={}, rate={} {}, duration={}]", //
|
||||||
LOG.debug(operation + " - [date={},pumpId={}, rate={} {}, duration={}]", //
|
|
||||||
temporaryBasalDb.date, //
|
temporaryBasalDb.date, //
|
||||||
temporaryBasalDb.pumpId, //
|
temporaryBasalDb.pumpId, //
|
||||||
temporaryBasalDb.isAbsolute ? String.format(Locale.ENGLISH, "%.2f", temporaryBasalDb.absoluteRate) :
|
temporaryBasalDb.isAbsolute ? String.format(Locale.ENGLISH, "%.2f", temporaryBasalDb.absoluteRate) :
|
||||||
|
@ -1336,7 +1316,7 @@ public class MedtronicHistoryData {
|
||||||
// oldestEntryTime = oldestEntryTime.plusSeconds(this.pumpTime.timeDifference);
|
// oldestEntryTime = oldestEntryTime.plusSeconds(this.pumpTime.timeDifference);
|
||||||
// }
|
// }
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("Problem decoding date from last record: {}" + currentTreatment);
|
aapsLogger.error("Problem decoding date from last record: {}" + currentTreatment);
|
||||||
return 8; // default return of 6 minutes
|
return 8; // default return of 6 minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1345,8 +1325,7 @@ public class MedtronicHistoryData {
|
||||||
Minutes minutes = Minutes.minutesBetween(oldestEntryTime, now);
|
Minutes minutes = Minutes.minutesBetween(oldestEntryTime, now);
|
||||||
|
|
||||||
// returns oldest time in history, with calculated time difference between pump and phone, minus 5 minutes
|
// returns oldest time in history, with calculated time difference between pump and phone, minus 5 minutes
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "Oldest entry: {}, pumpTimeDifference={}, newDt={}, currentTime={}, differenceMin={}", dt,
|
||||||
LOG.debug("Oldest entry: {}, pumpTimeDifference={}, newDt={}, currentTime={}, differenceMin={}", dt,
|
|
||||||
this.pumpTime.timeDifference, oldestEntryTime, now, minutes.getMinutes());
|
this.pumpTime.timeDifference, oldestEntryTime, now, minutes.getMinutes());
|
||||||
|
|
||||||
return minutes.getMinutes();
|
return minutes.getMinutes();
|
||||||
|
@ -1367,22 +1346,22 @@ public class MedtronicHistoryData {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: getOldestTimestamp. Oldest entry found: time={}, object={}", dt, currentTreatment);
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: getOldestTimestamp. Oldest entry found: time={}, object={}", dt, currentTreatment);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
GregorianCalendar oldestEntryTime = DateTimeUtil.toGregorianCalendar(dt);
|
GregorianCalendar oldestEntryTime = DateTimeUtil.toGregorianCalendar(dt);
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: getOldestTimestamp. oldestEntryTime: {}", DateTimeUtil.toString(oldestEntryTime));
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: getOldestTimestamp. oldestEntryTime: {}", DateTimeUtil.toString(oldestEntryTime));
|
||||||
oldestEntryTime.add(Calendar.MINUTE, -2);
|
oldestEntryTime.add(Calendar.MINUTE, -2);
|
||||||
|
|
||||||
if (doubleBolusDebug)
|
if (doubleBolusDebug)
|
||||||
LOG.debug("DoubleBolusDebug: getOldestTimestamp. oldestEntryTime (-2m): {}, timeInMillis={}", DateTimeUtil.toString(oldestEntryTime), oldestEntryTime.getTimeInMillis());
|
aapsLogger.debug(LTag.PUMP, "DoubleBolusDebug: getOldestTimestamp. oldestEntryTime (-2m): {}, timeInMillis={}", DateTimeUtil.toString(oldestEntryTime), oldestEntryTime.getTimeInMillis());
|
||||||
|
|
||||||
return oldestEntryTime.getTimeInMillis();
|
return oldestEntryTime.getTimeInMillis();
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("Problem decoding date from last record: {}", currentTreatment);
|
aapsLogger.error("Problem decoding date from last record: {}", currentTreatment);
|
||||||
return 8; // default return of 6 minutes
|
return 8; // default return of 6 minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1422,8 +1401,7 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
List<PumpHistoryEntry> filteredItems = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile);
|
List<PumpHistoryEntry> filteredItems = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "hasBasalProfileChanged. Items: " + gson.toJson(filteredItems));
|
||||||
LOG.debug("hasBasalProfileChanged. Items: " + gson.toJson(filteredItems));
|
|
||||||
|
|
||||||
return (filteredItems.size() > 0);
|
return (filteredItems.size() > 0);
|
||||||
}
|
}
|
||||||
|
@ -1433,8 +1411,7 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
List<PumpHistoryEntry> filteredItems = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile);
|
List<PumpHistoryEntry> filteredItems = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "processLastBasalProfileChange. Items: " + filteredItems);
|
||||||
LOG.debug("processLastBasalProfileChange. Items: " + filteredItems);
|
|
||||||
|
|
||||||
PumpHistoryEntry newProfile = null;
|
PumpHistoryEntry newProfile = null;
|
||||||
Long lastDate = null;
|
Long lastDate = null;
|
||||||
|
@ -1453,8 +1430,7 @@ public class MedtronicHistoryData {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newProfile != null) {
|
if (newProfile != null) {
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "processLastBasalProfileChange. item found, setting new basalProfileLocally: " + newProfile);
|
||||||
LOG.debug("processLastBasalProfileChange. item found, setting new basalProfileLocally: " + newProfile);
|
|
||||||
BasalProfile basalProfile = (BasalProfile) newProfile.getDecodedData().get("Object");
|
BasalProfile basalProfile = (BasalProfile) newProfile.getDecodedData().get("Object");
|
||||||
|
|
||||||
mdtPumpStatus.basalsByHour = basalProfile.getProfilesByHour();
|
mdtPumpStatus.basalsByHour = basalProfile.getProfilesByHour();
|
||||||
|
@ -1518,8 +1494,7 @@ public class MedtronicHistoryData {
|
||||||
} else {
|
} else {
|
||||||
List<PumpHistoryEntry> filteredItems = getFilteredItems(entryTypes);
|
List<PumpHistoryEntry> filteredItems = getFilteredItems(entryTypes);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMP, "Items: " + filteredItems);
|
||||||
LOG.debug("Items: " + filteredItems);
|
|
||||||
|
|
||||||
return filteredItems.size() > 0;
|
return filteredItems.size() > 0;
|
||||||
}
|
}
|
||||||
|
@ -1528,7 +1503,7 @@ public class MedtronicHistoryData {
|
||||||
|
|
||||||
private List<PumpHistoryEntry> getFilteredItems(List<PumpHistoryEntry> inList, PumpHistoryEntryType... entryTypes) {
|
private List<PumpHistoryEntry> getFilteredItems(List<PumpHistoryEntry> inList, PumpHistoryEntryType... entryTypes) {
|
||||||
|
|
||||||
// LOG.debug("InList: " + inList.size());
|
// aapsLogger.debug(LTag.PUMP, "InList: " + inList.size());
|
||||||
List<PumpHistoryEntry> outList = new ArrayList<>();
|
List<PumpHistoryEntry> outList = new ArrayList<>();
|
||||||
|
|
||||||
if (inList != null && inList.size() > 0) {
|
if (inList != null && inList.size() > 0) {
|
||||||
|
@ -1548,7 +1523,7 @@ public class MedtronicHistoryData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOG.debug("OutList: " + outList.size());
|
// aapsLogger.debug(LTag.PUMP, "OutList: " + outList.size());
|
||||||
|
|
||||||
return outList;
|
return outList;
|
||||||
}
|
}
|
||||||
|
@ -1563,8 +1538,4 @@ public class MedtronicHistoryData {
|
||||||
return "MedtronicHistoryData::";
|
return "MedtronicHistoryData::";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isLogEnabled() {
|
|
||||||
return (L.isEnabled(L.PUMP));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,21 +72,10 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
private final ResourceHelper resourceHelper;
|
private final ResourceHelper resourceHelper;
|
||||||
private final ProfileFunction profileFunction;
|
private final ProfileFunction profileFunction;
|
||||||
private final ActivePluginProvider activePlugin;
|
private final ActivePluginProvider activePlugin;
|
||||||
|
private final FabricPrivacy fabricPrivacy;
|
||||||
|
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
private static TreatmentsPlugin treatmentsPlugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use dagger to get an instance
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static TreatmentsPlugin getPlugin() {
|
|
||||||
if (treatmentsPlugin == null)
|
|
||||||
throw new IllegalStateException("Accessing TreatmentsPlugin before first instantiation");
|
|
||||||
return treatmentsPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected TreatmentService service;
|
protected TreatmentService service;
|
||||||
|
|
||||||
private IobTotal lastTreatmentCalculation;
|
private IobTotal lastTreatmentCalculation;
|
||||||
|
@ -107,7 +96,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
Context context,
|
Context context,
|
||||||
SP sp,
|
SP sp,
|
||||||
ProfileFunction profileFunction,
|
ProfileFunction profileFunction,
|
||||||
ActivePluginProvider activePlugin
|
ActivePluginProvider activePlugin,
|
||||||
|
FabricPrivacy fabricPrivacy
|
||||||
) {
|
) {
|
||||||
super(new PluginDescription()
|
super(new PluginDescription()
|
||||||
.mainType(PluginType.TREATMENT)
|
.mainType(PluginType.TREATMENT)
|
||||||
|
@ -125,7 +115,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
this.sp = sp;
|
this.sp = sp;
|
||||||
this.profileFunction = profileFunction;
|
this.profileFunction = profileFunction;
|
||||||
this.activePlugin = activePlugin;
|
this.activePlugin = activePlugin;
|
||||||
treatmentsPlugin = this;
|
this.fabricPrivacy = fabricPrivacy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -143,19 +133,19 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
updateTotalIOBTreatments();
|
updateTotalIOBTreatments();
|
||||||
rxBus.send(event.getNext());
|
rxBus.send(event.getNext());
|
||||||
},
|
},
|
||||||
exception -> FabricPrivacy.getInstance().logException(exception)
|
fabricPrivacy::logException
|
||||||
));
|
));
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventReloadProfileSwitchData.class)
|
.toObservable(EventReloadProfileSwitchData.class)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe(event -> initializeProfileSwitchData(range()),
|
.subscribe(event -> initializeProfileSwitchData(range()),
|
||||||
exception -> FabricPrivacy.getInstance().logException(exception)
|
fabricPrivacy::logException
|
||||||
));
|
));
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventTempTargetChange.class)
|
.toObservable(EventTempTargetChange.class)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe(event -> initializeTempTargetData(range()),
|
.subscribe(event -> initializeTempTargetData(range()),
|
||||||
exception -> FabricPrivacy.getInstance().logException(exception)
|
fabricPrivacy::logException
|
||||||
));
|
));
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventReloadTempBasalData.class)
|
.toObservable(EventReloadTempBasalData.class)
|
||||||
|
@ -165,7 +155,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
initializeTempBasalData(range());
|
initializeTempBasalData(range());
|
||||||
updateTotalIOBTempBasals();
|
updateTotalIOBTempBasals();
|
||||||
},
|
},
|
||||||
exception -> FabricPrivacy.getInstance().logException(exception)
|
fabricPrivacy::logException
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,7 +631,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "TreatmentClash");
|
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "TreatmentClash");
|
||||||
bundle.putString(FirebaseAnalytics.Param.VALUE, status);
|
bundle.putString(FirebaseAnalytics.Param.VALUE, status);
|
||||||
FabricPrivacy.getInstance().logCustom(bundle);
|
fabricPrivacy.logCustom(bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newRecordCreated;
|
return newRecordCreated;
|
||||||
|
@ -722,14 +712,14 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
@Override
|
@Override
|
||||||
public void doProfileSwitch(@NotNull final ProfileStore profileStore, @NotNull final String profileName, final int duration, final int percentage, final int timeShift, final long date) {
|
public void doProfileSwitch(@NotNull final ProfileStore profileStore, @NotNull final String profileName, final int duration, final int percentage, final int timeShift, final long date) {
|
||||||
ProfileSwitch profileSwitch = profileFunction.prepareProfileSwitch(profileStore, profileName, duration, percentage, timeShift, date);
|
ProfileSwitch profileSwitch = profileFunction.prepareProfileSwitch(profileStore, profileName, duration, percentage, timeShift, date);
|
||||||
treatmentsPlugin.addToHistoryProfileSwitch(profileSwitch);
|
addToHistoryProfileSwitch(profileSwitch);
|
||||||
if (percentage == 90 && duration == 10)
|
if (percentage == 90 && duration == 10)
|
||||||
sp.putBoolean(R.string.key_objectiveuseprofileswitch, true);
|
sp.putBoolean(R.string.key_objectiveuseprofileswitch, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doProfileSwitch(final int duration, final int percentage, final int timeShift) {
|
public void doProfileSwitch(final int duration, final int percentage, final int timeShift) {
|
||||||
ProfileSwitch profileSwitch = treatmentsPlugin.getProfileSwitchFromHistory(System.currentTimeMillis());
|
ProfileSwitch profileSwitch = getProfileSwitchFromHistory(System.currentTimeMillis());
|
||||||
if (profileSwitch != null) {
|
if (profileSwitch != null) {
|
||||||
profileSwitch = new ProfileSwitch(getInjector());
|
profileSwitch = new ProfileSwitch(getInjector());
|
||||||
profileSwitch.date = System.currentTimeMillis();
|
profileSwitch.date = System.currentTimeMillis();
|
||||||
|
@ -741,7 +731,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
profileSwitch.isCPP = percentage != 100 || timeShift != 0;
|
profileSwitch.isCPP = percentage != 100 || timeShift != 0;
|
||||||
profileSwitch.timeshift = timeShift;
|
profileSwitch.timeshift = timeShift;
|
||||||
profileSwitch.percentage = percentage;
|
profileSwitch.percentage = percentage;
|
||||||
treatmentsPlugin.addToHistoryProfileSwitch(profileSwitch);
|
addToHistoryProfileSwitch(profileSwitch);
|
||||||
} else {
|
} else {
|
||||||
getAapsLogger().error(LTag.PROFILE, "No profile switch exists");
|
getAapsLogger().error(LTag.PROFILE, "No profile switch exists");
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentService
|
import info.nightscout.androidaps.plugins.treatments.TreatmentService
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.HtmlHelper
|
import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
import info.nightscout.androidaps.utils.MidnightTime
|
import info.nightscout.androidaps.utils.MidnightTime
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
|
@ -29,8 +30,9 @@ class TddCalculator @Inject constructor(
|
||||||
val mainApp: MainApp,
|
val mainApp: MainApp,
|
||||||
val sp: SP,
|
val sp: SP,
|
||||||
val activePlugin: ActivePluginProvider,
|
val activePlugin: ActivePluginProvider,
|
||||||
val profileFunction: ProfileFunction
|
val profileFunction: ProfileFunction,
|
||||||
) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, activePlugin) {
|
fabricPrivacy: FabricPrivacy
|
||||||
|
) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, activePlugin, fabricPrivacy) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
service = TreatmentService() // plugin is not started
|
service = TreatmentService() // plugin is not started
|
||||||
|
|
Loading…
Reference in a new issue