Merge pull request #2 from nightscout/dev

getting latest dev updates from master dev
This commit is contained in:
teleriddler 2021-02-17 09:54:32 +01:00 committed by GitHub
commit 673cb9a362
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 827 additions and 746 deletions

View file

@ -312,7 +312,7 @@ class ActionsFragment : DaggerFragment() {
private fun checkPumpCustomActions() { private fun checkPumpCustomActions() {
val activePump = activePlugin.activePump val activePump = activePlugin.activePump
val customActions = activePump.customActions ?: return val customActions = activePump.getCustomActions() ?: return
val currentContext = context ?: return val currentContext = context ?: return
removePumpCustomActions() removePumpCustomActions()

View file

@ -45,9 +45,6 @@ import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
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.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.queue.commands.CustomCommand;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
@ -224,11 +221,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
} }
@Override @Override
public void finishHandshaking() { public void connect(@NonNull String reason) {
}
@Override
public void connect(String reason) {
// ruffyscripter establishes a connection as needed. // ruffyscripter establishes a connection as needed.
// ComboPlugin.runCommand performs on connect checks if needed, thus needs info on // ComboPlugin.runCommand performs on connect checks if needed, thus needs info on
// whether a connection is there. // whether a connection is there.
@ -240,7 +233,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
} }
@Override @Override
public void disconnect(String reason) { public void disconnect(@NonNull String reason) {
getAapsLogger().debug(LTag.PUMP, "Disconnect called with reason: " + reason); getAapsLogger().debug(LTag.PUMP, "Disconnect called with reason: " + reason);
ruffyScripter.disconnect(); ruffyScripter.disconnect();
} }
@ -251,7 +244,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
} }
@NonNull @Override @NonNull @Override
public synchronized PumpEnactResult setNewBasalProfile(Profile profile) { public synchronized PumpEnactResult setNewBasalProfile(@NonNull Profile profile) {
if (!isInitialized()) { if (!isInitialized()) {
// note that this should not happen anymore since the queue is present, which // note that this should not happen anymore since the queue is present, which
// issues a READSTATE when starting to issue commands which initializes the pump // issues a READSTATE when starting to issue commands which initializes the pump
@ -294,7 +287,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
} }
@Override @Override
public boolean isThisProfileSet(Profile profile) { public boolean isThisProfileSet(@NonNull Profile profile) {
if (!isInitialized()) { if (!isInitialized()) {
/* This might be called too soon during boot. Return true to prevent a request /* This might be called too soon during boot. Return true to prevent a request
to update the profile. KeepAlive is called every Constants.keepalivems to update the profile. KeepAlive is called every Constants.keepalivems
@ -338,7 +331,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
* Runs pump initialization if needed and reads the pump state from the main screen. * Runs pump initialization if needed and reads the pump state from the main screen.
*/ */
@Override @Override
public synchronized void getPumpStatus(String reason) { public synchronized void getPumpStatus(@NonNull String reason) {
getAapsLogger().debug(LTag.PUMP, "getPumpStatus called"); getAapsLogger().debug(LTag.PUMP, "getPumpStatus called");
if (!pump.initialized) { if (!pump.initialized) {
initializePump(); initializePump();
@ -720,7 +713,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
* the new value (and thus still has the old duration of e.g. 1 min) expires?) * the new value (and thus still has the old duration of e.g. 1 min) expires?)
*/ */
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean force) { public PumpEnactResult setTempBasalAbsolute(double absoluteRate, int durationInMinutes, @NonNull Profile profile, boolean force) {
getAapsLogger().debug(LTag.PUMP, "setTempBasalAbsolute called with a rate of " + absoluteRate + " for " + durationInMinutes + " min."); getAapsLogger().debug(LTag.PUMP, "setTempBasalAbsolute called with a rate of " + absoluteRate + " for " + durationInMinutes + " min.");
int unroundedPercentage = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue(); int unroundedPercentage = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
int roundedPercentage = (int) (Math.round(absoluteRate / getBaseBasalRate() * 10) * 10); int roundedPercentage = (int) (Math.round(absoluteRate / getBaseBasalRate() * 10) * 10);
@ -738,7 +731,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
* is or isn't running at the moment * is or isn't running at the moment
*/ */
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalPercent(Integer percent, final Integer durationInMinutes, Profile profile, boolean forceNew) { public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, @NonNull Profile profile, boolean forceNew) {
return setTempBasalPercent(percent, durationInMinutes); return setTempBasalPercent(percent, durationInMinutes);
} }
@ -794,7 +787,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
} }
@NonNull @Override @NonNull @Override
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) {
return OPERATION_NOT_SUPPORTED; return OPERATION_NOT_SUPPORTED;
} }
@ -853,6 +846,10 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
} }
} }
@Override public int waitForDisconnectionInSeconds() {
return 0;
}
private interface CommandExecution { private interface CommandExecution {
CommandResult execute(); CommandResult execute();
} }
@ -1388,19 +1385,6 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
return maxIob; return maxIob;
} }
@Override
public List<CustomAction> getCustomActions() {
return null;
}
@Override
public void executeCustomAction(CustomActionType customActionType) {
}
@Nullable @Override public PumpEnactResult executeCustomCommand(CustomCommand customCommand) {
return null;
}
@Override @Override
public boolean canHandleDST() { public boolean canHandleDST() {
return false; return false;

View file

@ -11,7 +11,6 @@ import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -54,8 +53,6 @@ import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
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.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue; import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
@ -133,7 +130,6 @@ import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_erro
import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator; import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator;
import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil; import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.commands.CustomCommand;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.TimeChangeType; import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
@ -343,11 +339,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
return false; return false;
} }
@Override
public void finishHandshaking() {
}
@Override @Override
public void connect(String reason) { public void connect(String reason) {
if (connectionService != null && alertService != null) if (connectionService != null && alertService != null)
@ -709,7 +700,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
} }
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { public PumpEnactResult setTempBasalAbsolute(double absoluteRate, int durationInMinutes, @NonNull Profile profile, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
if (activeBasalRate == null) return result; if (activeBasalRate == null) return result;
if (activeBasalRate.getActiveBasalRate() == 0) return result; if (activeBasalRate.getActiveBasalRate() == 0) return result;
@ -759,7 +750,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
} }
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) { public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, @NonNull Profile profile, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
percent = (int) Math.round(((double) percent) / 10d) * 10; percent = (int) Math.round(((double) percent) / 10d) * 10;
if (percent == 100) return cancelTempBasal(true); if (percent == 100) return cancelTempBasal(true);
@ -798,7 +789,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
} }
@NonNull @Override @NonNull @Override
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) {
PumpEnactResult result = cancelExtendedBolusOnly(); PumpEnactResult result = cancelExtendedBolusOnly();
if (result.success) if (result.success)
result = setExtendedBolusOnly(insulin, durationInMinutes, sp.getBoolean(R.string.key_disable_vibration, false)); result = setExtendedBolusOnly(insulin, durationInMinutes, sp.getBoolean(R.string.key_disable_vibration, false));
@ -987,11 +978,11 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
} }
@NonNull @Override @NonNull @Override
public JSONObject getJSONStatus(Profile profile, String profileName, String version) { public JSONObject getJSONStatus(@NonNull Profile profile, @NonNull String profileName, @NonNull String version) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (connectionService == null) return null; if (connectionService == null) return new JSONObject();
if (System.currentTimeMillis() - connectionService.getLastConnected() > (60 * 60 * 1000)) { if (System.currentTimeMillis() - connectionService.getLastConnected() > (60 * 60 * 1000)) {
return null; return new JSONObject();
} }
final JSONObject pump = new JSONObject(); final JSONObject pump = new JSONObject();
@ -1165,19 +1156,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
return new PumpEnactResult(getInjector()).success(true); return new PumpEnactResult(getInjector()).success(true);
} }
@Override
public List<CustomAction> getCustomActions() {
return null;
}
@Override
public void executeCustomAction(CustomActionType customActionType) {
}
@Nullable @Override public PumpEnactResult executeCustomCommand(CustomCommand customCommand) {
return null;
}
private void readHistory() { private void readHistory() {
try { try {
PumpTime pumpTime = connectionService.requestMessage(new GetDateTimeMessage()).await().getPumpTime(); PumpTime pumpTime = connectionService.requestMessage(new GetDateTimeMessage()).await().getPumpTime();

View file

@ -1,13 +1,10 @@
package info.nightscout.androidaps.plugins.pump.mdi; package info.nightscout.androidaps.plugins.pump.mdi;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -24,11 +21,7 @@ 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.LTag; import info.nightscout.androidaps.logging.LTag;
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.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.queue.commands.CustomCommand;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
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;
@ -50,7 +43,6 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
public MDIPlugin( public MDIPlugin(
HasAndroidInjector injector, HasAndroidInjector injector,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
RxBusWrapper rxBus,
ResourceHelper resourceHelper, ResourceHelper resourceHelper,
CommandQueueProvider commandQueue, CommandQueueProvider commandQueue,
TreatmentsPlugin treatmentsPlugin TreatmentsPlugin treatmentsPlugin
@ -82,8 +74,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
@NonNull @Override @NonNull @Override
public PumpEnactResult loadTDDs() { public PumpEnactResult loadTDDs() {
//no result, could read DB in the future? //no result, could read DB in the future?
PumpEnactResult result = new PumpEnactResult(getInjector()); return new PumpEnactResult(getInjector());
return result;
} }
@Override @Override
@ -117,15 +108,15 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
} }
@Override @Override
public void finishHandshaking() { public void connect(@NonNull String reason) {
} }
@Override @Override
public void connect(String reason) { public void disconnect(@NonNull String reason) {
} }
@Override @Override public int waitForDisconnectionInSeconds() {
public void disconnect(String reason) { return 0;
} }
@Override @Override
@ -133,11 +124,11 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
} }
@Override @Override
public void getPumpStatus(String reason) { public void getPumpStatus(@NonNull String reason) {
} }
@NonNull @Override @NonNull @Override
public PumpEnactResult setNewBasalProfile(Profile profile) { public PumpEnactResult setNewBasalProfile(@NonNull Profile profile) {
// Do nothing here. we are using ConfigBuilderPlugin.getPlugin().getActiveProfile().getProfile(); // Do nothing here. we are using ConfigBuilderPlugin.getPlugin().getActiveProfile().getProfile();
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
result.success = true; result.success = true;
@ -145,7 +136,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
} }
@Override @Override
public boolean isThisProfileSet(Profile profile) { public boolean isThisProfileSet(@NonNull Profile profile) {
return false; return false;
} }
@ -185,7 +176,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
} }
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { public PumpEnactResult setTempBasalAbsolute(double absoluteRate, int durationInMinutes, @NonNull Profile profile, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
result.success = false; result.success = false;
result.comment = getResourceHelper().gs(R.string.pumperror); result.comment = getResourceHelper().gs(R.string.pumperror);
@ -194,7 +185,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
} }
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) { public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, @NonNull Profile profile, boolean enforceNew) {
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
result.success = false; result.success = false;
result.comment = getResourceHelper().gs(R.string.pumperror); result.comment = getResourceHelper().gs(R.string.pumperror);
@ -203,7 +194,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
} }
@NonNull @Override @NonNull @Override
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) {
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
result.success = false; result.success = false;
result.comment = getResourceHelper().gs(R.string.pumperror); result.comment = getResourceHelper().gs(R.string.pumperror);
@ -230,7 +221,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
} }
@NonNull @Override @NonNull @Override
public JSONObject getJSONStatus(Profile profile, String profileName, String version) { public JSONObject getJSONStatus(@NonNull Profile profile, @NonNull String profileName, @NonNull String version) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
JSONObject pump = new JSONObject(); JSONObject pump = new JSONObject();
JSONObject status = new JSONObject(); JSONObject status = new JSONObject();
@ -238,16 +229,14 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
try { try {
status.put("status", "normal"); status.put("status", "normal");
extended.put("Version", version); extended.put("Version", version);
try {
extended.put("ActiveProfile", profileName); extended.put("ActiveProfile", profileName);
} catch (Exception e) {
}
status.put("timestamp", DateUtil.toISOString(now)); status.put("timestamp", DateUtil.toISOString(now));
pump.put("status", status); pump.put("status", status);
pump.put("extended", extended); pump.put("extended", extended);
pump.put("clock", DateUtil.toISOString(now)); pump.put("clock", DateUtil.toISOString(now));
} catch (JSONException e) { } catch (JSONException e) {
getAapsLogger().error("Exception: ", e);
} }
return pump; return pump;
} }
@ -277,26 +266,13 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
return model().getModel(); return model().getModel();
} }
@Override
public List<CustomAction> getCustomActions() {
return null;
}
@Override
public void executeCustomAction(CustomActionType customActionType) {
}
@Nullable @Override public PumpEnactResult executeCustomCommand(CustomCommand customCommand) {
return null;
}
@Override @Override
public boolean canHandleDST() { public boolean canHandleDST() {
return true; return true;
} }
@Override @Override
public void timezoneOrDSTChanged(TimeChangeType changeType) { public void timezoneOrDSTChanged(@NonNull TimeChangeType changeType) {
} }

View file

@ -18,24 +18,21 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
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.general.actions.defs.CustomAction
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
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.plugins.pump.virtual.events.EventVirtualPumpUpdateGui import info.nightscout.androidaps.plugins.pump.virtual.events.EventVirtualPumpUpdateGui
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.queue.commands.CustomCommand
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.InstanceId.instanceId import info.nightscout.androidaps.utils.InstanceId.instanceId
import info.nightscout.androidaps.utils.TimeChangeType import info.nightscout.androidaps.utils.TimeChangeType
import io.reactivex.rxkotlin.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign
import org.json.JSONException import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
import javax.inject.Inject import javax.inject.Inject
@ -75,7 +72,7 @@ class VirtualPumpPlugin @Inject constructor(
var pumpType: PumpType? = null var pumpType: PumpType? = null
private set private set
private var lastDataTime: Long = 0 private var lastDataTime: Long = 0
private val pumpDescription = PumpDescription() override val pumpDescription = PumpDescription()
init { init {
pumpDescription.isBolusCapable = true pumpDescription.isBolusCapable = true
@ -129,57 +126,29 @@ class VirtualPumpPlugin @Inject constructor(
uploadStatus.isVisible = !config.NSCLIENT uploadStatus.isVisible = !config.NSCLIENT
} }
override fun isFakingTempsByExtendedBoluses(): Boolean { override val isFakingTempsByExtendedBoluses: Boolean
return config.NSCLIENT && getFakingStatus() get() = config.NSCLIENT && getFakingStatus()
}
override fun loadTDDs(): PumpEnactResult { //no result, could read DB in the future? override fun loadTDDs(): PumpEnactResult { //no result, could read DB in the future?
return PumpEnactResult(injector) return PumpEnactResult(injector)
} }
override fun getCustomActions(): List<CustomAction>? { override val isInitialized: Boolean = true
return null override val isSuspended: Boolean = false
} override val isBusy: Boolean = false
override val isConnected: Boolean = true
override val isConnecting: Boolean = false
override val isHandshakeInProgress: Boolean = false
override fun executeCustomAction(customActionType: CustomActionType) {}
override fun executeCustomCommand(customCommand: CustomCommand?): PumpEnactResult? {
return null
}
override fun isInitialized(): Boolean {
return true
}
override fun isSuspended(): Boolean {
return false
}
override fun isBusy(): Boolean {
return false
}
override fun isConnected(): Boolean {
return true
}
override fun isConnecting(): Boolean {
return false
}
override fun isHandshakeInProgress(): Boolean {
return false
}
override fun finishHandshaking() {}
override fun connect(reason: String) { override fun connect(reason: String) {
//if (!Config.NSCLIENT) NSUpload.uploadDeviceStatus() //if (!Config.NSCLIENT) NSUpload.uploadDeviceStatus()
lastDataTime = System.currentTimeMillis() lastDataTime = System.currentTimeMillis()
} }
override fun waitForDisconnectionInSeconds(): Int = 0
override fun disconnect(reason: String) {} override fun disconnect(reason: String) {}
override fun stopConnecting() {} override fun stopConnecting() {}
override fun getPumpStatus(reason: String?) { override fun getPumpStatus(reason: String) {
lastDataTime = System.currentTimeMillis() lastDataTime = System.currentTimeMillis()
} }
@ -201,17 +170,14 @@ class VirtualPumpPlugin @Inject constructor(
return lastDataTime return lastDataTime
} }
override fun getBaseBasalRate(): Double { override val baseBasalRate: Double
return profileFunction.getProfile()?.basal ?: 0.0 get() = profileFunction.getProfile()?.basal ?: 0.0
}
override fun getReservoirLevel(): Double { override val reservoirLevel: Double
return reservoirInUnits.toDouble() get() = reservoirInUnits.toDouble()
}
override fun getBatteryLevel(): Int { override val batteryLevel: Int
return batteryPercent get() = batteryPercent
}
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
val result = PumpEnactResult(injector) val result = PumpEnactResult(injector)
@ -305,7 +271,7 @@ class VirtualPumpPlugin @Inject constructor(
return result return result
} }
override fun cancelTempBasal(force: Boolean): PumpEnactResult { override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult {
val result = PumpEnactResult(injector) val result = PumpEnactResult(injector)
result.success = true result.success = true
result.isTempCancel = true result.isTempCancel = true
@ -392,10 +358,6 @@ class VirtualPumpPlugin @Inject constructor(
return instanceId() return instanceId()
} }
override fun getPumpDescription(): PumpDescription {
return pumpDescription
}
override fun shortStatus(veryShort: Boolean): String { override fun shortStatus(veryShort: Boolean): String {
return "Virtual Pump" return "Virtual Pump"
} }
@ -405,15 +367,15 @@ class VirtualPumpPlugin @Inject constructor(
} }
fun refreshConfiguration() { fun refreshConfiguration() {
val pumptype = sp.getString(R.string.key_virtualpump_type, PumpType.GenericAAPS.description) val pumpType = sp.getString(R.string.key_virtualpump_type, PumpType.GenericAAPS.description)
val pumpTypeNew = PumpType.getByDescription(pumptype) val pumpTypeNew = PumpType.getByDescription(pumpType)
aapsLogger.debug(LTag.PUMP, "Pump in configuration: $pumptype, PumpType object: $pumpTypeNew") aapsLogger.debug(LTag.PUMP, "Pump in configuration: $pumpType, PumpType object: $pumpTypeNew")
if (pumpType == pumpTypeNew) return if (this.pumpType == pumpTypeNew) return
aapsLogger.debug(LTag.PUMP, "New pump configuration found ($pumpTypeNew), changing from previous ($pumpType)") aapsLogger.debug(LTag.PUMP, "New pump configuration found ($pumpTypeNew), changing from previous (${this.pumpType})")
pumpDescription.setPumpDescription(pumpTypeNew) pumpDescription.setPumpDescription(pumpTypeNew)
pumpType = pumpTypeNew this.pumpType = pumpTypeNew
} }
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType?) {} override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {}
} }

View file

@ -84,7 +84,7 @@ import javax.inject.Singleton
*/ */
@Singleton @Singleton
class CommandQueue @Inject constructor( open class CommandQueue @Inject constructor(
private val injector: HasAndroidInjector, private val injector: HasAndroidInjector,
private val aapsLogger: AAPSLogger, private val aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper, private val rxBus: RxBusWrapper,
@ -145,7 +145,7 @@ class CommandQueue @Inject constructor(
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
@Synchronized @Synchronized
private fun isLastScheduled(type: CommandType): Boolean { fun isLastScheduled(type: CommandType): Boolean {
synchronized(queue) { synchronized(queue) {
if (queue.size > 0 && queue[queue.size - 1].commandType == type) { if (queue.size > 0 && queue[queue.size - 1].commandType == type) {
return true return true
@ -187,11 +187,8 @@ class CommandQueue @Inject constructor(
// After new command added to the queue // After new command added to the queue
// start thread again if not already running // start thread again if not already running
@Synchronized @Synchronized
private fun notifyAboutNewCommand() { open fun notifyAboutNewCommand() {
while (thread != null && thread!!.state != Thread.State.TERMINATED && thread!!.waitingForDisconnect) { waitForFinishedThread()
aapsLogger.debug(LTag.PUMPQUEUE, "Waiting for previous thread finish")
SystemClock.sleep(500)
}
if (thread == null || thread!!.state == Thread.State.TERMINATED) { if (thread == null || thread!!.state == Thread.State.TERMINATED) {
thread = QueueThread(this, context, aapsLogger, rxBus, activePlugin.get(), resourceHelper, sp) thread = QueueThread(this, context, aapsLogger, rxBus, activePlugin.get(), resourceHelper, sp)
thread!!.start() thread!!.start()
@ -201,6 +198,15 @@ class CommandQueue @Inject constructor(
} }
} }
fun waitForFinishedThread() {
thread?.let { thread ->
while (thread.state != Thread.State.TERMINATED && thread.waitingForDisconnect) {
aapsLogger.debug(LTag.PUMPQUEUE, "Waiting for previous thread finish")
SystemClock.sleep(500)
}
}
}
override fun independentConnect(reason: String, callback: Callback?) { override fun independentConnect(reason: String, callback: Callback?) {
aapsLogger.debug(LTag.PUMPQUEUE, "Starting new queue") aapsLogger.debug(LTag.PUMPQUEUE, "Starting new queue")
val tempCommandQueue = CommandQueue(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, constraintChecker, profileFunction, activePlugin, context, sp, buildHelper, fabricPrivacy) val tempCommandQueue = CommandQueue(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, constraintChecker, profileFunction, activePlugin, context, sp, buildHelper, fabricPrivacy)
@ -454,12 +460,12 @@ class CommandQueue @Inject constructor(
// returns true if command is queued // returns true if command is queued
override fun loadTDDs(callback: Callback?): Boolean { override fun loadTDDs(callback: Callback?): Boolean {
if (isRunning(CommandType.LOAD_HISTORY)) { if (isRunning(CommandType.LOAD_TDD)) {
callback?.result(executingNowError())?.run() callback?.result(executingNowError())?.run()
return false return false
} }
// remove all unfinished // remove all unfinished
removeAll(CommandType.LOAD_HISTORY) removeAll(CommandType.LOAD_TDD)
// add new command to queue // add new command to queue
add(CommandLoadTDDs(injector, callback)) add(CommandLoadTDDs(injector, callback))
notifyAboutNewCommand() notifyAboutNewCommand()

View file

@ -1,171 +0,0 @@
package info.nightscout.androidaps.queue;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.os.PowerManager;
import android.os.SystemClock;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusProgressIfRunning;
import info.nightscout.androidaps.queue.events.EventQueueChanged;
import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
/**
* Created by mike on 09.11.2017.
*/
public class QueueThread extends Thread {
private final CommandQueue queue;
private final AAPSLogger aapsLogger;
private final RxBusWrapper rxBus;
private final ActivePluginProvider activePlugin;
private final ResourceHelper resourceHelper;
private final SP sp;
private boolean connectLogged = false;
boolean waitingForDisconnect = false;
private PowerManager.WakeLock mWakeLock;
QueueThread(CommandQueue queue, Context context, AAPSLogger aapsLogger, RxBusWrapper rxBus, ActivePluginProvider activePlugin, ResourceHelper resourceHelper, SP sp) {
super();
this.queue = queue;
this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
this.activePlugin = activePlugin;
this.resourceHelper = resourceHelper;
this.sp = sp;
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (powerManager != null)
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:QueueThread");
}
@Override
public final void run() {
if (mWakeLock != null)
mWakeLock.acquire(T.mins(10).msecs());
rxBus.send(new EventQueueChanged());
long lastCommandTime;
long connectionStartTime = lastCommandTime = System.currentTimeMillis();
try {
while (true) {
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
PumpInterface pump = activePlugin.getActivePump();
if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) {
rxBus.send(new EventDismissBolusProgressIfRunning(null));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.connectiontimedout)));
aapsLogger.debug(LTag.PUMPQUEUE, "timed out");
pump.stopConnecting();
//BLUETOOTH-WATCHDOG
boolean watchdog = sp.getBoolean(R.string.key_btwatchdog, false);
long last_watchdog = sp.getLong(R.string.key_btwatchdog_lastbark, 0L);
watchdog = watchdog && System.currentTimeMillis() - last_watchdog > (Constants.MIN_WATCHDOG_INTERVAL_IN_SECONDS * 1000);
if (watchdog) {
aapsLogger.debug(LTag.PUMPQUEUE, "BT watchdog - toggeling the phonest bluetooth");
//write time
sp.putLong(R.string.key_btwatchdog_lastbark, System.currentTimeMillis());
//toggle BT
pump.stopConnecting();
pump.disconnect("watchdog");
SystemClock.sleep(1000);
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter != null) {
bluetoothAdapter.disable();
SystemClock.sleep(1000);
bluetoothAdapter.enable();
SystemClock.sleep(1000);
}
//start over again once after watchdog barked
//Notification notification = new Notification(Notification.OLD_NSCLIENT, "Watchdog", Notification.URGENT);
//rxBus.send(new EventNewNotification(notification));
connectionStartTime = lastCommandTime = System.currentTimeMillis();
pump.connect("watchdog");
} else {
queue.clear();
aapsLogger.debug(LTag.PUMPQUEUE, "no connection possible");
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
pump.disconnect("Queue empty");
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED));
return;
}
}
if (pump.isHandshakeInProgress()) {
aapsLogger.debug(LTag.PUMPQUEUE, "handshaking " + secondsElapsed);
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.HANDSHAKING, (int) secondsElapsed));
SystemClock.sleep(100);
continue;
}
if (pump.isConnecting()) {
aapsLogger.debug(LTag.PUMPQUEUE, "connecting " + secondsElapsed);
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, (int) secondsElapsed));
SystemClock.sleep(1000);
continue;
}
if (!pump.isConnected()) {
aapsLogger.debug(LTag.PUMPQUEUE, "connect");
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, (int) secondsElapsed));
pump.connect("Connection needed");
SystemClock.sleep(1000);
continue;
}
if (queue.performing() == null) {
if (!connectLogged) {
connectLogged = true;
aapsLogger.debug(LTag.PUMPQUEUE, "connection time " + secondsElapsed + "s");
}
// Pickup 1st command and set performing variable
if (queue.size() > 0) {
queue.pickup();
if (queue.performing() != null) {
aapsLogger.debug(LTag.PUMPQUEUE, "performing " + queue.performing().status());
rxBus.send(new EventQueueChanged());
queue.performing().execute();
queue.resetPerforming();
rxBus.send(new EventQueueChanged());
lastCommandTime = System.currentTimeMillis();
SystemClock.sleep(100);
continue;
}
}
}
if (queue.size() == 0 && queue.performing() == null) {
long secondsFromLastCommand = (System.currentTimeMillis() - lastCommandTime) / 1000;
if (secondsFromLastCommand >= 5) {
waitingForDisconnect = true;
aapsLogger.debug(LTag.PUMPQUEUE, "queue empty. disconnect");
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
pump.disconnect("Queue empty");
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED));
aapsLogger.debug(LTag.PUMPQUEUE, "disconnected");
return;
} else {
aapsLogger.debug(LTag.PUMPQUEUE, "waiting for disconnect");
SystemClock.sleep(1000);
}
}
}
} finally {
if (mWakeLock != null && mWakeLock.isHeld())
mWakeLock.release();
aapsLogger.debug(LTag.PUMPQUEUE, "thread end");
}
}
}

View file

@ -0,0 +1,149 @@
package info.nightscout.androidaps.queue
import android.bluetooth.BluetoothAdapter
import android.content.Context
import android.os.PowerManager
import android.os.SystemClock
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventPumpStatusChanged
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusProgressIfRunning
import info.nightscout.androidaps.queue.events.EventQueueChanged
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
class QueueThread internal constructor(
private val queue: CommandQueue,
context: Context,
private val aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper,
private val activePlugin: ActivePluginProvider,
private val resourceHelper: ResourceHelper,
private val sp: SP
) : Thread() {
private var connectLogged = false
var waitingForDisconnect = false
private var mWakeLock: PowerManager.WakeLock? = null
init {
mWakeLock = (context.getSystemService(Context.POWER_SERVICE) as PowerManager).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, resourceHelper.gs(R.string.app_name) + ":QueueThread")
}
override fun run() {
mWakeLock?.acquire(T.mins(10).msecs())
rxBus.send(EventQueueChanged())
var lastCommandTime: Long
lastCommandTime = System.currentTimeMillis()
var connectionStartTime = lastCommandTime
try {
while (true) {
val secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000
val pump = activePlugin.activePump
if (!pump.isConnected && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) {
rxBus.send(EventDismissBolusProgressIfRunning(null))
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.connectiontimedout)))
aapsLogger.debug(LTag.PUMPQUEUE, "timed out")
pump.stopConnecting()
//BLUETOOTH-WATCHDOG
var watchdog = sp.getBoolean(R.string.key_btwatchdog, false)
val lastWatchdog = sp.getLong(R.string.key_btwatchdog_lastbark, 0L)
watchdog = watchdog && System.currentTimeMillis() - lastWatchdog > Constants.MIN_WATCHDOG_INTERVAL_IN_SECONDS * 1000
if (watchdog) {
aapsLogger.debug(LTag.PUMPQUEUE, "BT watchdog - toggling the phone bluetooth")
//write time
sp.putLong(R.string.key_btwatchdog_lastbark, System.currentTimeMillis())
//toggle BT
pump.stopConnecting()
pump.disconnect("watchdog")
SystemClock.sleep(1000)
val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
if (bluetoothAdapter != null) {
bluetoothAdapter.disable()
SystemClock.sleep(1000)
bluetoothAdapter.enable()
SystemClock.sleep(1000)
}
//start over again once after watchdog barked
//Notification notification = new Notification(Notification.OLD_NSCLIENT, "Watchdog", Notification.URGENT);
//rxBus.send(new EventNewNotification(notification));
lastCommandTime = System.currentTimeMillis()
connectionStartTime = lastCommandTime
pump.connect("watchdog")
} else {
queue.clear()
aapsLogger.debug(LTag.PUMPQUEUE, "no connection possible")
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
pump.disconnect("Queue empty")
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED))
return
}
}
if (pump.isHandshakeInProgress) {
aapsLogger.debug(LTag.PUMPQUEUE, "handshaking $secondsElapsed")
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.HANDSHAKING, secondsElapsed.toInt()))
SystemClock.sleep(100)
continue
}
if (pump.isConnecting) {
aapsLogger.debug(LTag.PUMPQUEUE, "connecting $secondsElapsed")
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, secondsElapsed.toInt()))
SystemClock.sleep(1000)
continue
}
if (!pump.isConnected) {
aapsLogger.debug(LTag.PUMPQUEUE, "connect")
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, secondsElapsed.toInt()))
pump.connect("Connection needed")
SystemClock.sleep(1000)
continue
}
if (queue.performing() == null) {
if (!connectLogged) {
connectLogged = true
aapsLogger.debug(LTag.PUMPQUEUE, "connection time " + secondsElapsed + "s")
}
// Pickup 1st command and set performing variable
if (queue.size() > 0) {
queue.pickup()
if (queue.performing() != null) {
aapsLogger.debug(LTag.PUMPQUEUE, "performing " + queue.performing()?.status())
rxBus.send(EventQueueChanged())
queue.performing()?.execute()
queue.resetPerforming()
rxBus.send(EventQueueChanged())
lastCommandTime = System.currentTimeMillis()
SystemClock.sleep(100)
continue
}
}
}
if (queue.size() == 0 && queue.performing() == null) {
val secondsFromLastCommand = (System.currentTimeMillis() - lastCommandTime) / 1000
if (secondsFromLastCommand >= pump.waitForDisconnectionInSeconds()) {
waitingForDisconnect = true
aapsLogger.debug(LTag.PUMPQUEUE, "queue empty. disconnect")
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
pump.disconnect("Queue empty")
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED))
aapsLogger.debug(LTag.PUMPQUEUE, "disconnected")
return
} else {
aapsLogger.debug(LTag.PUMPQUEUE, "waiting for disconnect")
SystemClock.sleep(1000)
}
}
}
} finally {
if (mWakeLock?.isHeld == true) mWakeLock?.release()
aapsLogger.debug(LTag.PUMPQUEUE, "thread end")
}
}
}

View file

@ -9,7 +9,7 @@ import javax.inject.Inject
class CommandLoadTDDs( class CommandLoadTDDs(
injector: HasAndroidInjector, injector: HasAndroidInjector,
callback: Callback? callback: Callback?
) : Command(injector, CommandType.LOAD_HISTORY, callback) { ) : Command(injector, CommandType.LOAD_TDD, callback) {
@Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var activePlugin: ActivePluginProvider

View file

@ -14,7 +14,7 @@ class CommandTempBasalPercent(
private val enforceNew: Boolean, private val enforceNew: Boolean,
private val profile: Profile, private val profile: Profile,
callback: Callback? callback: Callback?
) : Command(injector, CommandType.BASAL_PROFILE, callback) { ) : Command(injector, CommandType.TEMPBASAL, callback) {
@Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var activePlugin: ActivePluginProvider

View file

@ -0,0 +1,64 @@
package info.nightscout.androidaps
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.interfaces.PumpDescription
import info.nightscout.androidaps.interfaces.PumpInterface
import info.nightscout.androidaps.plugins.common.ManufacturerType
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.utils.TimeChangeType
import org.json.JSONObject
@Suppress("MemberVisibilityCanBePrivate")
class TestPumpPlugin(val injector: HasAndroidInjector) : PumpInterface {
override var isConnected = false
override var isConnecting = false
override var isHandshakeInProgress = false
val lastData = 0L
val baseBasal = 0.0
override val pumpDescription = PumpDescription()
override val isInitialized: Boolean = true
override val isSuspended: Boolean = false
override val isBusy: Boolean = false
override fun connect(reason: String) {
isConnected = true
}
override fun disconnect(reason: String) {
isConnected = false
}
override fun stopConnecting() {
isConnected = false
}
override fun waitForDisconnectionInSeconds(): Int = 0
override fun getPumpStatus(reason: String) {}
override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector)
override fun isThisProfileSet(profile: Profile): Boolean = true
override fun lastDataTime(): Long = lastData
override val baseBasalRate: Double = baseBasal
override val reservoirLevel: Double = 0.0
override val batteryLevel: Int = 0
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun stopBolusDelivering() {}
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun cancelExtendedBolus(): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject = JSONObject()
override fun manufacturer(): ManufacturerType = ManufacturerType.AndroidAPS
override fun model(): PumpType = PumpType.GenericAAPS
override fun serialNumber(): String = "1"
override fun shortStatus(veryShort: Boolean): String = ""
override val isFakingTempsByExtendedBoluses: Boolean = false
override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun canHandleDST(): Boolean = true
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {}
}

View file

@ -14,7 +14,7 @@ import org.powermock.modules.junit4.PowerMockRunner
class MsgSettingBasalTest : DanaRTestBase() { class MsgSettingBasalTest : DanaRTestBase() {
@Test fun runTest() { @Test fun runTest() {
`when`(danaRPlugin.getPumpDescription()).thenReturn(PumpDescription()) `when`(danaRPlugin.pumpDescription).thenReturn(PumpDescription())
val packet = MsgSettingBasal(injector) val packet = MsgSettingBasal(injector)
// test message decoding // test message decoding

View file

@ -1,24 +1,30 @@
package info.nightscout.androidaps.queue package info.nightscout.androidaps.queue
import android.content.Context import android.content.Context
import android.os.PowerManager
import dagger.Lazy import dagger.Lazy
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config import info.nightscout.androidaps.Config
import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.TestPumpPlugin
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.PumpDescription import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.general.maintenance.LoggerUtils import info.nightscout.androidaps.plugins.general.maintenance.LoggerUtils
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.queue.commands.Command import info.nightscout.androidaps.queue.commands.*
import info.nightscout.androidaps.queue.commands.CustomCommand import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
@ -33,16 +39,35 @@ import java.util.*
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest( @PrepareForTest(
ConstraintChecker::class, VirtualPumpPlugin::class, ToastUtils::class, Context::class, ConstraintChecker::class, VirtualPumpPlugin::class, ToastUtils::class, Context::class,
TreatmentsPlugin::class, FabricPrivacy::class, LoggerUtils::class) TreatmentsPlugin::class, FabricPrivacy::class, LoggerUtils::class, PowerManager::class)
class CommandQueueTest : TestBaseWithProfile() { class CommandQueueTest : TestBaseWithProfile() {
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker
@Mock lateinit var lazyActivePlugin: Lazy<ActivePluginProvider> @Mock lateinit var lazyActivePlugin: Lazy<ActivePluginProvider>
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var loggerUtils: LoggerUtils @Mock lateinit var loggerUtils: LoggerUtils
@Mock lateinit var powerManager: PowerManager
class CommandQueueMocked(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
rxBus: RxBusWrapper,
aapsSchedulers: AapsSchedulers,
resourceHelper: ResourceHelper,
constraintChecker: ConstraintChecker,
profileFunction: ProfileFunction,
activePlugin: Lazy<ActivePluginProvider>,
context: Context,
sp: SP,
buildHelper: BuildHelper,
fabricPrivacy: FabricPrivacy
) : CommandQueue(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, constraintChecker, profileFunction, activePlugin, context, sp, buildHelper, fabricPrivacy) {
override fun notifyAboutNewCommand() {}
}
val injector = HasAndroidInjector { val injector = HasAndroidInjector {
AndroidInjector { AndroidInjector {
@ -50,22 +75,38 @@ class CommandQueueTest : TestBaseWithProfile() {
it.aapsLogger = aapsLogger it.aapsLogger = aapsLogger
it.resourceHelper = resourceHelper it.resourceHelper = resourceHelper
} }
if (it is CommandTempBasalPercent) {
it.activePlugin = activePlugin
}
if (it is CommandBolus) {
it.activePlugin = activePlugin
it.rxBus = rxBus
}
if (it is CommandCustomCommand) {
it.activePlugin = activePlugin
}
if (it is CommandExtendedBolus) {
it.activePlugin = activePlugin
}
if (it is CommandLoadHistory) {
it.activePlugin = activePlugin
}
} }
} }
lateinit var commandQueue: CommandQueue lateinit var commandQueue: CommandQueue
lateinit var testPumpPlugin: TestPumpPlugin
@Before @Before
fun prepare() { fun prepare() {
commandQueue = CommandQueue(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, constraintChecker, profileFunction, lazyActivePlugin, context, sp, BuildHelper(Config(), loggerUtils), fabricPrivacy) commandQueue = CommandQueueMocked(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, constraintChecker, profileFunction, lazyActivePlugin, context, sp, BuildHelper(Config(), loggerUtils), fabricPrivacy)
testPumpPlugin = TestPumpPlugin(injector)
val pumpDescription = PumpDescription() testPumpPlugin.pumpDescription.basalMinimumRate = 0.1
pumpDescription.basalMinimumRate = 0.1
`when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager)
`when`(lazyActivePlugin.get()).thenReturn(activePlugin) `when`(lazyActivePlugin.get()).thenReturn(activePlugin)
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin) `when`(activePlugin.activePump).thenReturn(testPumpPlugin)
`when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription)
`when`(virtualPumpPlugin.isThisProfileSet(anyObject())).thenReturn(false)
`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin) `when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin)
`when`(treatmentsPlugin.lastBolusTime).thenReturn(Calendar.getInstance().also { it.set(2000, 0, 1) }.timeInMillis) `when`(treatmentsPlugin.lastBolusTime).thenReturn(Calendar.getInstance().also { it.set(2000, 0, 1) }.timeInMillis)
`when`(profileFunction.getProfile()).thenReturn(validProfile) `when`(profileFunction.getProfile()).thenReturn(validProfile)
@ -81,7 +122,22 @@ class CommandQueueTest : TestBaseWithProfile() {
`when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject())).thenReturn(percentageConstraint) `when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject())).thenReturn(percentageConstraint)
} }
/* @Test
fun commandIsPickedUp() {
val commandQueue = CommandQueue(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, constraintChecker, profileFunction, lazyActivePlugin, context, sp, BuildHelper(Config(), loggerUtils), fabricPrivacy)
// start with empty queue
Assert.assertEquals(0, commandQueue.size())
// add bolus command
commandQueue.bolus(DetailedBolusInfo(), null)
Assert.assertEquals(1, commandQueue.size())
commandQueue.waitForFinishedThread()
Thread.sleep(1000)
Assert.assertEquals(0, commandQueue.size())
}
@Test @Test
fun doTests() { fun doTests() {
@ -112,16 +168,20 @@ class CommandQueueTest : TestBaseWithProfile() {
commandQueue.tempBasalPercent(0, 30, true, validProfile, null) commandQueue.tempBasalPercent(0, 30, true, validProfile, null)
Assert.assertEquals(1, commandQueue.size()) Assert.assertEquals(1, commandQueue.size())
// cancel tempbasal it should replace previous TEMPBASAL
commandQueue.cancelTempBasal(false, null)
Assert.assertEquals(1, commandQueue.size())
// add extended bolus // add extended bolus
commandQueue.extendedBolus(1.0, 30, null) commandQueue.extendedBolus(1.0, 30, null)
Assert.assertEquals(2, commandQueue.size()) Assert.assertEquals(2, commandQueue.size())
// add cancel temp basal should remove previous 2 temp basal setting // add extended should remove previous extended setting
commandQueue.extendedBolus(1.0, 30, null) commandQueue.extendedBolus(1.0, 30, null)
Assert.assertEquals(2, commandQueue.size()) Assert.assertEquals(2, commandQueue.size())
// cancel extended bolus should replace previous extended // cancel extended bolus should replace previous extended
commandQueue.extendedBolus(1.0, 30, null) commandQueue.cancelExtended(null)
Assert.assertEquals(2, commandQueue.size()) Assert.assertEquals(2, commandQueue.size())
// add setProfile // add setProfile
@ -179,7 +239,7 @@ class CommandQueueTest : TestBaseWithProfile() {
Assert.assertFalse(queued) Assert.assertFalse(queued)
Assert.assertEquals(commandQueue.size(), 1) Assert.assertEquals(commandQueue.size(), 1)
} }
*/
@Test @Test
fun smbIsRejectedIfLastKnownBolusIsOutdated() { fun smbIsRejectedIfLastKnownBolusIsOutdated() {
// given // given
@ -222,21 +282,105 @@ class CommandQueueTest : TestBaseWithProfile() {
} }
@Test @Test
fun isCustomCommandInQueue() { fun isSetUserOptionsCommandInQueue() {
// given // given
Assert.assertEquals(0, commandQueue.size()) Assert.assertEquals(0, commandQueue.size())
// when // when
val queued1 = commandQueue.customCommand(CustomCommand1(), null) commandQueue.setUserOptions(null)
val queued2 = commandQueue.customCommand(CustomCommand2(), null)
// then // then
Assert.assertTrue(queued1) Assert.assertTrue(commandQueue.isLastScheduled(Command.CommandType.SET_USER_SETTINGS))
Assert.assertTrue(queued2) Assert.assertEquals(1, commandQueue.size())
Assert.assertTrue(commandQueue.isCustomCommandInQueue(CustomCommand1::class.java)) // next should be ignored
Assert.assertTrue(commandQueue.isCustomCommandInQueue(CustomCommand2::class.java)) commandQueue.setUserOptions(null)
Assert.assertFalse(commandQueue.isCustomCommandInQueue(CustomCommand3::class.java)) Assert.assertEquals(1, commandQueue.size())
Assert.assertEquals(2, commandQueue.size()) }
@Test
fun isLoadEventsCommandInQueue() {
// given
Assert.assertEquals(0, commandQueue.size())
// when
commandQueue.loadEvents(null)
// then
Assert.assertTrue(commandQueue.isLastScheduled(Command.CommandType.LOAD_EVENTS))
Assert.assertEquals(1, commandQueue.size())
// next should be ignored
commandQueue.loadEvents(null)
Assert.assertEquals(1, commandQueue.size())
}
@Test
fun isLoadTDDsCommandInQueue() {
// given
Assert.assertEquals(0, commandQueue.size())
// when
commandQueue.loadTDDs(null)
// then
Assert.assertEquals(1, commandQueue.size())
// next should be ignored
commandQueue.loadTDDs(null)
Assert.assertEquals(1, commandQueue.size())
}
@Test
fun isLoadHistoryCommandInQueue() {
// given
Assert.assertEquals(0, commandQueue.size())
// when
commandQueue.loadHistory(0, null)
// then
Assert.assertTrue(commandQueue.isLastScheduled(Command.CommandType.LOAD_HISTORY))
Assert.assertEquals(1, commandQueue.size())
// next should be ignored
commandQueue.loadHistory(0, null)
Assert.assertEquals(1, commandQueue.size())
}
@Test
fun isStopCommandInQueue() {
// given
Assert.assertEquals(0, commandQueue.size())
// when
commandQueue.stopPump(null)
// then
Assert.assertTrue(commandQueue.isLastScheduled(Command.CommandType.STOP_PUMP))
Assert.assertEquals(1, commandQueue.size())
}
@Test
fun isStarCommandInQueue() {
// given
Assert.assertEquals(0, commandQueue.size())
// when
commandQueue.startPump(null)
// then
Assert.assertTrue(commandQueue.isLastScheduled(Command.CommandType.START_PUMP))
Assert.assertEquals(1, commandQueue.size())
}
@Test
fun isSetTbrNotificationCommandInQueue() {
// given
Assert.assertEquals(0, commandQueue.size())
// when
commandQueue.setTBROverNotification(null, true)
// then
Assert.assertTrue(commandQueue.isLastScheduled(Command.CommandType.INSIGHT_SET_TBR_OVER_ALARM))
Assert.assertEquals(1, commandQueue.size())
} }
@Test @Test
@ -269,6 +413,22 @@ class CommandQueueTest : TestBaseWithProfile() {
Assert.assertEquals(1, commandQueue.size()) Assert.assertEquals(1, commandQueue.size())
} }
@Test
fun readStatusTwiceIsNotAllowed() {
// given
Assert.assertEquals(0, commandQueue.size())
// when
val queued1 = commandQueue.readStatus("1", null)
val queued2 = commandQueue.readStatus("2", null)
// then
Assert.assertTrue(queued1)
Assert.assertFalse(queued2)
Assert.assertEquals(1, commandQueue.size())
Assert.assertTrue(commandQueue.statusInQueue())
}
private class CustomCommand1 : CustomCommand { private class CustomCommand1 : CustomCommand {
override val statusDescription: String override val statusDescription: String

View file

@ -0,0 +1,98 @@
package info.nightscout.androidaps.queue
import android.content.Context
import android.os.PowerManager
import dagger.Lazy
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.TestPumpPlugin
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.PumpDescription
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.general.maintenance.LoggerUtils
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.queue.commands.Command
import info.nightscout.androidaps.queue.commands.CommandTempBasalAbsolute
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
import java.util.*
@RunWith(PowerMockRunner::class)
@PrepareForTest(
ConstraintChecker::class, VirtualPumpPlugin::class, ToastUtils::class, Context::class,
TreatmentsPlugin::class, FabricPrivacy::class, LoggerUtils::class, PowerManager::class)
class QueueThreadTest : TestBaseWithProfile() {
@Mock lateinit var constraintChecker: ConstraintChecker
@Mock lateinit var lazyActivePlugin: Lazy<ActivePluginProvider>
@Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var context: Context
@Mock lateinit var sp: SP
@Mock lateinit var loggerUtils: LoggerUtils
@Mock lateinit var powerManager: PowerManager
val injector = HasAndroidInjector {
AndroidInjector {
if (it is Command) {
it.aapsLogger = aapsLogger
it.resourceHelper = resourceHelper
}
if (it is CommandTempBasalAbsolute) {
it.activePlugin = activePlugin
}
}
}
private lateinit var pumpPlugin: TestPumpPlugin
lateinit var commandQueue: CommandQueue
lateinit var sut: QueueThread
@Before
fun prepare() {
pumpPlugin = TestPumpPlugin(injector)
commandQueue = CommandQueue(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, constraintChecker, profileFunction, lazyActivePlugin, context, sp, BuildHelper(Config(), loggerUtils), fabricPrivacy)
val pumpDescription = PumpDescription()
pumpDescription.basalMinimumRate = 0.1
Mockito.`when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager)
Mockito.`when`(lazyActivePlugin.get()).thenReturn(activePlugin)
Mockito.`when`(activePlugin.activePump).thenReturn(pumpPlugin)
Mockito.`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin)
Mockito.`when`(treatmentsPlugin.lastBolusTime).thenReturn(Calendar.getInstance().also { it.set(2000, 0, 1) }.timeInMillis)
Mockito.`when`(profileFunction.getProfile()).thenReturn(validProfile)
val bolusConstraint = Constraint(0.0)
Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(bolusConstraint)
Mockito.`when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(bolusConstraint)
val carbsConstraint = Constraint(0)
Mockito.`when`(constraintChecker.applyCarbsConstraints(anyObject())).thenReturn(carbsConstraint)
val rateConstraint = Constraint(0.0)
Mockito.`when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(rateConstraint)
val percentageConstraint = Constraint(0)
Mockito.`when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject())).thenReturn(percentageConstraint)
sut = QueueThread(commandQueue, context, aapsLogger, rxBus, activePlugin, resourceHelper, sp)
}
@Test
fun commandIsPickedUp() {
commandQueue.tempBasalAbsolute(2.0, 60, true, validProfile, null)
sut.run()
Assert.assertEquals(0, commandQueue.size())
}
}

View file

@ -1,152 +0,0 @@
package info.nightscout.androidaps.interfaces;
import androidx.annotation.Nullable;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
import java.util.List;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.plugins.common.ManufacturerType;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.queue.commands.CustomCommand;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.utils.TimeChangeType;
/**
* Created by mike on 04.06.2016.
*/
public interface PumpInterface {
boolean isInitialized(); // true if pump status has been read and is ready to accept commands
boolean isSuspended(); // true if suspended (not delivering insulin)
boolean isBusy(); // if true pump is not ready to accept commands right now
boolean isConnected(); // true if BT connection is established
boolean isConnecting(); // true if BT connection is in progress
boolean isHandshakeInProgress(); // true if BT is connected but initial handshake is still in progress
void finishHandshaking(); // set initial handshake completed
void connect(String reason);
void disconnect(String reason);
void stopConnecting();
void getPumpStatus(String reason);
// Upload to pump new basal profile
@NotNull
PumpEnactResult setNewBasalProfile(Profile profile);
boolean isThisProfileSet(Profile profile);
long lastDataTime();
double getBaseBasalRate(); // base basal rate, not temp basal
double getReservoirLevel();
int getBatteryLevel(); // in percent as integer
@NotNull
PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo);
void stopBolusDelivering();
@NotNull
PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew);
@NotNull
PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew);
@NotNull
PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes);
//some pumps might set a very short temp close to 100% as cancelling a temp can be noisy
//when the cancel request is requested by the user (forced), the pump should always do a real cancel
@NotNull
PumpEnactResult cancelTempBasal(boolean enforceNew);
@NotNull
PumpEnactResult cancelExtendedBolus();
// Status to be passed to NS
@NotNull
JSONObject getJSONStatus(Profile profile, String profileName, String version);
@NotNull
ManufacturerType manufacturer();
@NotNull
PumpType model();
@NotNull
String serialNumber();
// Pump capabilities
@NotNull
PumpDescription getPumpDescription();
// Short info for SMS, Wear etc
@NotNull
String shortStatus(boolean veryShort);
boolean isFakingTempsByExtendedBoluses();
@NotNull
PumpEnactResult loadTDDs();
boolean canHandleDST();
/**
* Provides a list of custom actions to be displayed in the Actions tab.
* Plese note that these actions will not be queued upon execution
*
* @return list of custom actions
*/
@Nullable
List<CustomAction> getCustomActions();
/**
* Executes a custom action. Please note that these actions will not be queued
*
* @param customActionType action to be executed
*/
void executeCustomAction(CustomActionType customActionType);
/**
* Executes a custom queued command
* See {@link CommandQueueProvider#customCommand(CustomCommand, Callback)} for queuing a custom command.
*
* @param customCommand the custom command to be executed
* @return PumpEnactResult that represents the command execution result
*/
@Nullable
PumpEnactResult executeCustomCommand(CustomCommand customCommand);
/**
* This method will be called when time or Timezone changes, and pump driver can then do a specific action (for
* example update clock on pump).
*/
void timezoneOrDSTChanged(TimeChangeType timeChangeType);
/* Only used for pump types where hasCustomUnreachableAlertCheck=true */
default boolean isUnreachableAlertTimeoutExceeded(long alertTimeoutMilliseconds) {
return false;
}
default boolean setNeutralTempAtFullHour() {
return false;
}
}

View file

@ -0,0 +1,102 @@
package info.nightscout.androidaps.interfaces
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.plugins.common.ManufacturerType
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.queue.commands.CustomCommand
import info.nightscout.androidaps.utils.TimeChangeType
import org.json.JSONObject
/**
* Created by mike on 04.06.2016.
*/
interface PumpInterface {
val isInitialized: Boolean // true if pump status has been read and is ready to accept commands
val isSuspended: Boolean // true if suspended (not delivering insulin)
val isBusy: Boolean // if true pump is not ready to accept commands right now
val isConnected: Boolean // true if BT connection is established
val isConnecting: Boolean // true if BT connection is in progress
val isHandshakeInProgress: Boolean // true if BT is connected but initial handshake is still in progress
@JvmDefault fun finishHandshaking() {} // set initial handshake completed
fun connect(reason: String)
fun disconnect(reason: String)
@JvmDefault fun waitForDisconnectionInSeconds(): Int = 5 // wait [x] second after last command before sending disconnect
fun stopConnecting()
fun getPumpStatus(reason: String)
// Upload to pump new basal profile
fun setNewBasalProfile(profile: Profile): PumpEnactResult
fun isThisProfileSet(profile: Profile): Boolean
fun lastDataTime(): Long
val baseBasalRate: Double // base basal rate, not temp basal
val reservoirLevel: Double
val batteryLevel: Int // in percent as integer
fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult
fun stopBolusDelivering()
fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean): PumpEnactResult
fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean): PumpEnactResult
fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult
//some pumps might set a very short temp close to 100% as cancelling a temp can be noisy
//when the cancel request is requested by the user (forced), the pump should always do a real cancel
fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult
fun cancelExtendedBolus(): PumpEnactResult
// Status to be passed to NS
fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject
fun manufacturer(): ManufacturerType
fun model(): PumpType
fun serialNumber(): String
// Pump capabilities
val pumpDescription: PumpDescription
// Short info for SMS, Wear etc
fun shortStatus(veryShort: Boolean): String
val isFakingTempsByExtendedBoluses: Boolean
fun loadTDDs(): PumpEnactResult
fun canHandleDST(): Boolean
/**
* Provides a list of custom actions to be displayed in the Actions tab.
* Please note that these actions will not be queued upon execution
*
* @return list of custom actions
*/
@JvmDefault fun getCustomActions(): List<CustomAction>? = null
/**
* Executes a custom action. Please note that these actions will not be queued
*
* @param customActionType action to be executed
*/
@JvmDefault fun executeCustomAction(customActionType: CustomActionType) {}
/**
* Executes a custom queued command
* See [CommandQueueProvider.customCommand] for queuing a custom command.
*
* @param customCommand the custom command to be executed
* @return PumpEnactResult that represents the command execution result
*/
@JvmDefault fun executeCustomCommand(customCommand: CustomCommand): PumpEnactResult? = null
/**
* This method will be called when time or Timezone changes, and pump driver can then do a specific action (for
* example update clock on pump).
*/
@JvmDefault fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {}
/* Only used for pump types where hasCustomUnreachableAlertCheck=true */
@JvmDefault
fun isUnreachableAlertTimeoutExceeded(alertTimeoutMilliseconds: Long): Boolean = false
@JvmDefault fun setNeutralTempAtFullHour(): Boolean = false
}

View file

@ -2,9 +2,8 @@ package info.nightscout.androidaps.plugins.general.actions.defs
import info.nightscout.androidaps.core.R import info.nightscout.androidaps.core.R
class CustomAction @JvmOverloads constructor(val name: Int, val customActionType: CustomActionType?, val iconResourceId: Int = R.drawable.ic_actions_profileswitch, var isEnabled: Boolean = true) { class CustomAction @JvmOverloads constructor(val name: Int, val customActionType: CustomActionType, val iconResourceId: Int = R.drawable.ic_actions_profileswitch, var isEnabled: Boolean = true) {
constructor(nameResourceId: Int, actionType: CustomActionType?, enabled: Boolean) : constructor(nameResourceId: Int, actionType: CustomActionType, enabled: Boolean) :
this(nameResourceId, actionType, R.drawable.ic_actions_profileswitch, enabled) this(nameResourceId, actionType, R.drawable.ic_actions_profileswitch, enabled)
} }

View file

@ -44,7 +44,6 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers; import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
/** /**
* Created by andy on 23.04.18. * Created by andy on 23.04.18.
@ -151,7 +150,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
/** /**
* Service class (same one you did serviceConnection for) * Service class (same one you did serviceConnection for)
* *
* @return * @return Class
*/ */
public abstract Class getServiceClass(); public abstract Class getServiceClass();
@ -187,13 +186,13 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
} }
public void connect(String reason) { public void connect(@NonNull String reason) {
if (displayConnectionMessages) if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "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(@NonNull String reason) {
if (displayConnectionMessages) if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "disconnect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason); aapsLogger.debug(LTag.PUMP, "disconnect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason);
} }
@ -220,13 +219,13 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
} }
// Upload to pump new basal profile // Upload to pump new basal profile
@NonNull public PumpEnactResult setNewBasalProfile(Profile profile) { @NonNull public PumpEnactResult setNewBasalProfile(@NonNull Profile profile) {
aapsLogger.debug(LTag.PUMP, "setNewBasalProfile [PumpPluginAbstract] - Not implemented."); aapsLogger.debug(LTag.PUMP, "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(@NonNull Profile profile) {
aapsLogger.debug(LTag.PUMP, "isThisProfileSet [PumpPluginAbstract] - Not implemented."); aapsLogger.debug(LTag.PUMP, "isThisProfileSet [PumpPluginAbstract] - Not implemented.");
return true; return true;
} }
@ -250,22 +249,20 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, public PumpEnactResult setTempBasalAbsolute(double absoluteRate, int durationInMinutes, @NonNull Profile profile, boolean enforceNew) {
boolean enforceNew) {
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute [PumpPluginAbstract] - Not implemented."); aapsLogger.debug(LTag.PUMP, "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);
} }
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, @NonNull Profile profile, boolean enforceNew) {
boolean enforceNew) {
aapsLogger.debug(LTag.PUMP, "setTempBasalPercent [PumpPluginAbstract] - Not implemented."); aapsLogger.debug(LTag.PUMP, "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, int durationInMinutes) {
aapsLogger.debug(LTag.PUMP, "setExtendedBolus [PumpPluginAbstract] - Not implemented."); aapsLogger.debug(LTag.PUMP, "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);
} }
@ -321,7 +318,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
@NonNull @Override @NonNull @Override
public JSONObject getJSONStatus(Profile profile, String profileName, String version) { public JSONObject getJSONStatus(@NonNull Profile profile, @NonNull String profileName, @NonNull String version) {
if ((getPumpStatusData().lastConnection + 60 * 60 * 1000L) < System.currentTimeMillis()) { if ((getPumpStatusData().lastConnection + 60 * 60 * 1000L) < System.currentTimeMillis()) {
return new JSONObject(); return new JSONObject();
@ -444,7 +441,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
} }
public ManufacturerType manufacturer() { @NonNull public ManufacturerType manufacturer() {
return pumpType.getManufacturer(); return pumpType.getManufacturer();
} }
@ -477,5 +474,4 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
private PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) { private PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(resourceId)); return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(resourceId));
} }
} }

View file

@ -28,6 +28,7 @@ abstract class Command(
READSTATUS, READSTATUS,
LOAD_HISTORY, // TDDs and so far only Dana specific LOAD_HISTORY, // TDDs and so far only Dana specific
LOAD_EVENTS, // so far only Dana specific LOAD_EVENTS, // so far only Dana specific
LOAD_TDD,
SET_USER_SETTINGS, // so far only Dana specific, SET_USER_SETTINGS, // so far only Dana specific,
START_PUMP, START_PUMP,
STOP_PUMP, STOP_PUMP,
@ -36,6 +37,7 @@ abstract class Command(
} }
init { init {
@Suppress("LeakingThis")
injector.androidInjector().inject(this) injector.androidInjector().inject(this)
} }

View file

@ -194,7 +194,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
// This is called from APS // This is called from APS
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { public PumpEnactResult setTempBasalAbsolute(double absoluteRate, int durationInMinutes, Profile profile, boolean enforceNew) {
// Recheck pump status if older than 30 min // Recheck pump status if older than 30 min
//This should not be needed while using queue because connection should be done before calling this //This should not be needed while using queue because connection should be done before calling this
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) { //if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {

View file

@ -220,7 +220,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
// This is called from APS // This is called from APS
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { public PumpEnactResult setTempBasalAbsolute(double absoluteRate, int durationInMinutes, Profile profile, boolean enforceNew) {
// Recheck pump status if older than 30 min // Recheck pump status if older than 30 min
//This should not be needed while using queue because connection should be done before calling this //This should not be needed while using queue because connection should be done before calling this
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) { //if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
@ -251,7 +251,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
} }
if (doLowTemp || doHighTemp) { if (doLowTemp || doHighTemp) {
Integer percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue(); int percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 mins. So if it's less than .10u/h, set a zero temp. // Any basal less than 0.10u/h will be dumped once per hour, not every 4 mins. So if it's less than .10u/h, set a zero temp.
if (absoluteRate < 0.10d) percentRate = 0; if (absoluteRate < 0.10d) percentRate = 0;
if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue(); if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue();
@ -298,7 +298,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
} }
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) { public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, Profile profile, boolean enforceNew) {
DanaPump pump = danaPump; DanaPump pump = danaPump;
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value(); percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value();

View file

@ -1,13 +1,11 @@
package info.nightscout.androidaps.danar; package info.nightscout.androidaps.danar;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Date; import java.util.Date;
import java.util.List;
import dagger.android.HasAndroidInjector; import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.dana.DanaFragment; import info.nightscout.androidaps.dana.DanaFragment;
@ -36,16 +34,12 @@ import info.nightscout.androidaps.logging.LTag;
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.ConstraintChecker;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.queue.commands.CustomCommand;
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.Round; import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers; import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -223,7 +217,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
} }
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) { public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, Profile profile, boolean enforceNew) {
DanaPump pump = danaPump; DanaPump pump = danaPump;
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value(); percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
@ -271,7 +265,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
} }
@NonNull @Override @NonNull @Override
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) {
DanaPump pump = danaPump; DanaPump pump = danaPump;
insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value(); insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
// needs to be rounded // needs to be rounded
@ -335,7 +329,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
} }
@Override @Override
public void connect(String from) { public void connect(@NonNull String from) {
if (sExecutionService != null) { if (sExecutionService != null) {
sExecutionService.connect(); sExecutionService.connect();
pumpDescription.basalStep = danaPump.getBasalStep(); pumpDescription.basalStep = danaPump.getBasalStep();
@ -354,7 +348,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
} }
@Override @Override
public void disconnect(String from) { public void disconnect(@NonNull String from) {
if (sExecutionService != null) sExecutionService.disconnect(from); if (sExecutionService != null) sExecutionService.disconnect(from);
} }
@ -364,7 +358,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
} }
@Override @Override
public void getPumpStatus(String reason) { public void getPumpStatus(@NonNull String reason) {
if (sExecutionService != null) { if (sExecutionService != null) {
sExecutionService.getPumpStatus(); sExecutionService.getPumpStatus();
pumpDescription.basalStep = danaPump.getBasalStep(); pumpDescription.basalStep = danaPump.getBasalStep();
@ -373,7 +367,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
} }
@NonNull @Override @NonNull @Override
public JSONObject getJSONStatus(Profile profile, String profilename, String version) { public JSONObject getJSONStatus(@NonNull Profile profile, @NonNull String profilename, @NonNull String version) {
DanaPump pump = danaPump; DanaPump pump = danaPump;
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (pump.getLastConnection() + 60 * 60 * 1000L < System.currentTimeMillis()) { if (pump.getLastConnection() + 60 * 60 * 1000L < System.currentTimeMillis()) {
@ -508,30 +502,11 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
} }
// TODO: daily total constraint // TODO: daily total constraint
@Override
public List<CustomAction> getCustomActions() {
return null;
}
@Override
public void executeCustomAction(CustomActionType customActionType) {
}
@Nullable @Override public PumpEnactResult executeCustomCommand(CustomCommand customCommand) {
return null;
}
@Override @Override
public boolean canHandleDST() { public boolean canHandleDST() {
return false; return false;
} }
@Override
public void timezoneOrDSTChanged(TimeChangeType timeChangeType) {
}
@Override public void clearPairing() { @Override public void clearPairing() {
} }
} }

View file

@ -192,7 +192,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
// This is called from APS // This is called from APS
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { public PumpEnactResult setTempBasalAbsolute(double absoluteRate, int durationInMinutes, Profile profile, boolean enforceNew) {
// Recheck pump status if older than 30 min // Recheck pump status if older than 30 min
//This should not be needed while using queue because connection should be done before calling this //This should not be needed while using queue because connection should be done before calling this
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) { //if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {

View file

@ -24,14 +24,11 @@ import info.nightscout.androidaps.logging.LTag
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.ConstraintChecker
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.queue.commands.CustomCommand
import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.*
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
@ -136,37 +133,28 @@ class DanaRSPlugin @Inject constructor(
commandQueue.readStatus("DeviceChanged", null) commandQueue.readStatus("DeviceChanged", null)
} }
override fun connect(from: String) { override fun connect(reason: String) {
aapsLogger.debug(LTag.PUMP, "RS connect from: $from") aapsLogger.debug(LTag.PUMP, "RS connect from: $reason")
if (danaRSService != null && mDeviceAddress != "" && mDeviceName != "") { if (danaRSService != null && mDeviceAddress != "" && mDeviceName != "") {
val success = danaRSService?.connect(from, mDeviceAddress) ?: false val success = danaRSService?.connect(reason, mDeviceAddress) ?: false
if (!success) ToastUtils.showToastInUiThread(context, resourceHelper.gs(R.string.ble_not_supported)) if (!success) ToastUtils.showToastInUiThread(context, resourceHelper.gs(R.string.ble_not_supported))
} }
} }
override fun isConnected(): Boolean { override val isConnected: Boolean = danaRSService?.isConnected ?: false
return danaRSService?.isConnected ?: false override val isConnecting: Boolean = danaRSService?.isConnecting ?: false
} override val isHandshakeInProgress: Boolean = false
override fun isConnecting(): Boolean { override fun disconnect(reason: String) {
return danaRSService?.isConnecting ?: false aapsLogger.debug(LTag.PUMP, "RS disconnect from: $reason")
} danaRSService?.disconnect(reason)
override fun isHandshakeInProgress(): Boolean {
return false
}
override fun finishHandshaking() {}
override fun disconnect(from: String) {
aapsLogger.debug(LTag.PUMP, "RS disconnect from: $from")
danaRSService?.disconnect(from)
} }
override fun stopConnecting() { override fun stopConnecting() {
danaRSService?.stopConnecting() danaRSService?.stopConnecting()
} }
override fun getPumpStatus(reason: String?) { override fun getPumpStatus(reason: String) {
danaRSService?.readPumpStatus() danaRSService?.readPumpStatus()
pumpDesc.basalStep = danaPump.basalStep pumpDesc.basalStep = danaPump.basalStep
pumpDesc.bolusStep = danaPump.bolusStep pumpDesc.bolusStep = danaPump.bolusStep
@ -207,17 +195,14 @@ class DanaRSPlugin @Inject constructor(
} }
// Pump interface // Pump interface
override fun isInitialized(): Boolean { override val isInitialized: Boolean =
return danaPump.lastConnection > 0 && danaPump.maxBasal > 0 && danaPump.isRSPasswordOK danaPump.lastConnection > 0 && danaPump.maxBasal > 0 && danaPump.isRSPasswordOK
}
override fun isSuspended(): Boolean { override val isSuspended: Boolean =
return danaPump.pumpSuspended || danaPump.errorState != DanaPump.ErrorState.NONE danaPump.pumpSuspended || danaPump.errorState != DanaPump.ErrorState.NONE
}
override fun isBusy(): Boolean { override val isBusy: Boolean =
return danaRSService?.isConnected ?: false || danaRSService?.isConnecting ?: false danaRSService?.isConnected ?: false || danaRSService?.isConnecting ?: false
}
override fun setNewBasalProfile(profile: Profile): PumpEnactResult { override fun setNewBasalProfile(profile: Profile): PumpEnactResult {
val result = PumpEnactResult(injector) val result = PumpEnactResult(injector)
@ -263,21 +248,10 @@ class DanaRSPlugin @Inject constructor(
return true return true
} }
override fun lastDataTime(): Long { override fun lastDataTime(): Long = danaPump.lastConnection
return danaPump.lastConnection override val baseBasalRate: Double = danaPump.currentBasal
} override val reservoirLevel: Double = danaPump.reservoirRemainingUnits
override val batteryLevel: Int = danaPump.batteryRemaining
override fun getBaseBasalRate(): Double {
return danaPump.currentBasal
}
override fun getReservoirLevel(): Double {
return danaPump.reservoirRemainingUnits
}
override fun getBatteryLevel(): Int {
return danaPump.batteryRemaining
}
@Synchronized @Synchronized
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
@ -361,7 +335,7 @@ class DanaRSPlugin @Inject constructor(
} }
if (doLowTemp || doHighTemp) { if (doLowTemp || doHighTemp) {
var percentRate = 0 var percentRate = 0
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 mins. So if it's less than .10u/h, set a zero temp. // Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp.
if (absoluteAfterConstrain >= 0.10) { if (absoluteAfterConstrain >= 0.10) {
percentRate = java.lang.Double.valueOf(absoluteAfterConstrain / baseBasalRate * 100).toInt() percentRate = java.lang.Double.valueOf(absoluteAfterConstrain / baseBasalRate * 100).toInt()
} else { } else {
@ -389,7 +363,7 @@ class DanaRSPlugin @Inject constructor(
} }
} }
// Convert duration from minutes to hours // Convert duration from minutes to hours
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Setting temp basal $percentRate% for $durationInMinutes mins (doLowTemp || doHighTemp)") aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Setting temp basal $percentRate% for $durationInMinutes minutes (doLowTemp || doHighTemp)")
result = if (percentRate == 0 && durationInMinutes > 30) { result = if (percentRate == 0 && durationInMinutes > 30) {
setTempBasalPercent(percentRate, durationInMinutes, profile, enforceNew) setTempBasalPercent(percentRate, durationInMinutes, profile, enforceNew)
} else { } else {
@ -397,10 +371,10 @@ class DanaRSPlugin @Inject constructor(
setHighTempBasalPercent(percentRate) setHighTempBasalPercent(percentRate)
} }
if (!result.success) { if (!result.success) {
aapsLogger.error("setTempBasalAbsolute: Failed to set hightemp basal") aapsLogger.error("setTempBasalAbsolute: Failed to set high temp basal")
return result return result
} }
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: hightemp basal set ok") aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: high temp basal set ok")
return result return result
} }
// We should never end here // We should never end here
@ -524,7 +498,7 @@ class DanaRSPlugin @Inject constructor(
} }
@Synchronized @Synchronized
override fun cancelTempBasal(force: Boolean): PumpEnactResult { override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult {
val result = PumpEnactResult(injector) val result = PumpEnactResult(injector)
val runningTB = activePluginProvider.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis()) val runningTB = activePluginProvider.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis())
if (runningTB != null) { if (runningTB != null) {
@ -627,16 +601,15 @@ class DanaRSPlugin @Inject constructor(
return danaPump.serialNumber return danaPump.serialNumber
} }
override fun getPumpDescription(): PumpDescription { override val pumpDescription: PumpDescription = pumpDesc
return pumpDesc
}
@Suppress("SpellCheckingInspection")
override fun shortStatus(veryShort: Boolean): String { override fun shortStatus(veryShort: Boolean): String {
var ret = "" var ret = ""
if (danaPump.lastConnection != 0L) { if (danaPump.lastConnection != 0L) {
val agoMillis = System.currentTimeMillis() - danaPump.lastConnection val agoMillis = System.currentTimeMillis() - danaPump.lastConnection
val agoMin = (agoMillis / 60.0 / 1000.0).toInt() val agoMin = (agoMillis / 60.0 / 1000.0).toInt()
ret += "LastConn: $agoMin minago\n" ret += "LastConn: $agoMin minAgo\n"
} }
if (danaPump.lastBolusTime != 0L) if (danaPump.lastBolusTime != 0L)
ret += "LastBolus: ${DecimalFormatter.to2Decimal(danaPump.lastBolusAmount)}U @${DateFormat.format("HH:mm", danaPump.lastBolusTime)}" ret += "LastBolus: ${DecimalFormatter.to2Decimal(danaPump.lastBolusAmount)}U @${DateFormat.format("HH:mm", danaPump.lastBolusTime)}"
@ -657,13 +630,9 @@ class DanaRSPlugin @Inject constructor(
return ret return ret
} }
override fun isFakingTempsByExtendedBoluses(): Boolean = false override val isFakingTempsByExtendedBoluses: Boolean = false
override fun loadTDDs(): PumpEnactResult = loadHistory(info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_DAILY) override fun loadTDDs(): PumpEnactResult = loadHistory(info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_DAILY)
override fun getCustomActions(): List<CustomAction>? = null
override fun executeCustomAction(customActionType: CustomActionType) {}
override fun executeCustomCommand(customCommand: CustomCommand?): PumpEnactResult? = null
override fun canHandleDST(): Boolean = false override fun canHandleDST(): Boolean = false
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType?) {}
override fun clearPairing() { override fun clearPairing() {
sp.remove(resourceHelper.gs(R.string.key_danars_pairingkey) + mDeviceName) sp.remove(resourceHelper.gs(R.string.key_danars_pairingkey) + mDeviceName)
sp.remove(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + mDeviceName) sp.remove(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + mDeviceName)

View file

@ -84,7 +84,6 @@ import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPu
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.queue.commands.CustomCommand;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.TimeChangeType; import info.nightscout.androidaps.utils.TimeChangeType;
@ -648,7 +647,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@Override @Override
public boolean isThisProfileSet(Profile profile) { public boolean isThisProfileSet(@NonNull Profile profile) {
aapsLogger.debug(LTag.PUMP, "isThisProfileSet: basalInitalized=" + medtronicPumpStatus.basalProfileStatus); aapsLogger.debug(LTag.PUMP, "isThisProfileSet: basalInitalized=" + medtronicPumpStatus.basalProfileStatus);
if (!isInitialized) if (!isInitialized)
@ -875,7 +874,7 @@ 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());
ErrorHelperActivity.Companion.runAlarm(context,getResourceHelper().gs(R.string.medtronic_cmd_cancel_bolus_not_supported), getResourceHelper().gs(R.string.medtronic_warning), R.raw.boluserror); ErrorHelperActivity.Companion.runAlarm(context, getResourceHelper().gs(R.string.medtronic_cmd_cancel_bolus_not_supported), getResourceHelper().gs(R.string.medtronic_warning), R.raw.boluserror);
}).start(); }).start();
} }
@ -958,7 +957,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
// if enforceNew===true current temp basal is canceled and new TBR set (duration is prolonged), // if enforceNew===true current temp basal is canceled and new TBR set (duration is prolonged),
// if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed // if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, public PumpEnactResult setTempBasalAbsolute(double absoluteRate, int durationInMinutes, Profile profile,
boolean enforceNew) { boolean enforceNew) {
setRefreshButtonEnabled(false); setRefreshButtonEnabled(false);
@ -1070,8 +1069,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@NonNull @Override @NonNull @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, @NonNull Profile profile, boolean enforceNew) {
boolean enforceNew) {
if (percent == 0) { if (percent == 0) {
return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew); return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew);
} else { } else {
@ -1426,7 +1424,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
} }
@NonNull @Override @NonNull @Override
public PumpEnactResult setNewBasalProfile(Profile profile) { public PumpEnactResult setNewBasalProfile(@NonNull Profile profile) {
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setNewBasalProfile"); aapsLogger.info(LTag.PUMP, 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
@ -1579,10 +1577,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
} }
@Nullable @Override public PumpEnactResult executeCustomCommand(CustomCommand customCommand) {
return null;
}
@Override @Override
public void timezoneOrDSTChanged(TimeChangeType changeType) { public void timezoneOrDSTChanged(TimeChangeType changeType) {

View file

@ -17,7 +17,6 @@ import org.joda.time.Duration;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -51,7 +50,6 @@ import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
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.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.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
@ -90,7 +88,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.queue.command.Comman
import info.nightscout.androidaps.plugins.pump.omnipod.eros.queue.command.CommandUpdateAlertConfiguration; import info.nightscout.androidaps.plugins.pump.omnipod.eros.queue.command.CommandUpdateAlertConfiguration;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.queue.command.OmnipodCustomCommand; import info.nightscout.androidaps.plugins.pump.omnipod.eros.queue.command.OmnipodCustomCommand;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.queue.command.OmnipodCustomCommandType; import info.nightscout.androidaps.plugins.pump.omnipod.eros.queue.command.OmnipodCustomCommandType;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.rileylink.manager.OmnipodRileyLinkCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.rileylink.service.RileyLinkOmnipodService; import info.nightscout.androidaps.plugins.pump.omnipod.eros.rileylink.service.RileyLinkOmnipodService;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.ui.OmnipodOverviewFragment; import info.nightscout.androidaps.plugins.pump.omnipod.eros.ui.OmnipodOverviewFragment;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.util.AapsOmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.eros.util.AapsOmnipodUtil;
@ -139,7 +136,6 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
private final DateUtil dateUtil; private final DateUtil dateUtil;
private final PumpDescription pumpDescription; private final PumpDescription pumpDescription;
private final ServiceConnection serviceConnection; private final ServiceConnection serviceConnection;
private final OmnipodRileyLinkCommunicationManager omnipodRileyLinkCommunicationManager;
private final PumpType pumpType = PumpType.Insulet_Omnipod; private final PumpType pumpType = PumpType.Insulet_Omnipod;
private final CompositeDisposable disposables = new CompositeDisposable(); private final CompositeDisposable disposables = new CompositeDisposable();
private final NSUpload nsUpload; private final NSUpload nsUpload;
@ -177,8 +173,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
RileyLinkUtil rileyLinkUtil, RileyLinkUtil rileyLinkUtil,
OmnipodAlertUtil omnipodAlertUtil, OmnipodAlertUtil omnipodAlertUtil,
ProfileFunction profileFunction, ProfileFunction profileFunction,
NSUpload nsUpload, NSUpload nsUpload
OmnipodRileyLinkCommunicationManager omnipodRileyLinkCommunicationManager
) { ) {
super(new PluginDescription() // super(new PluginDescription() //
.mainType(PluginType.PUMP) // .mainType(PluginType.PUMP) //
@ -206,7 +201,6 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
this.omnipodAlertUtil = omnipodAlertUtil; this.omnipodAlertUtil = omnipodAlertUtil;
this.profileFunction = profileFunction; this.profileFunction = profileFunction;
this.nsUpload = nsUpload; this.nsUpload = nsUpload;
this.omnipodRileyLinkCommunicationManager = omnipodRileyLinkCommunicationManager;
pumpDescription = new PumpDescription(pumpType); pumpDescription = new PumpDescription(pumpType);
@ -562,7 +556,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
* When the user explicitly requested it by clicking the Refresh button on the Omnipod tab (which is executed through {@link #executeCustomCommand(CustomCommand)}) * When the user explicitly requested it by clicking the Refresh button on the Omnipod tab (which is executed through {@link #executeCustomCommand(CustomCommand)})
*/ */
@Override @Override
public void getPumpStatus(String reason) { public void getPumpStatus(@NonNull String reason) {
if (firstRun) { if (firstRun) {
initializeAfterRileyLinkConnection(); initializeAfterRileyLinkConnection();
firstRun = false; firstRun = false;
@ -583,7 +577,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
@NonNull @NonNull
@Override @Override
public PumpEnactResult setNewBasalProfile(Profile profile) { public PumpEnactResult setNewBasalProfile(@NonNull Profile profile) {
PumpEnactResult result = executeCommand(OmnipodCommandType.SET_BASAL_PROFILE, () -> aapsOmnipodManager.setBasalProfile(profile, true)); PumpEnactResult result = executeCommand(OmnipodCommandType.SET_BASAL_PROFILE, () -> aapsOmnipodManager.setBasalProfile(profile, true));
aapsLogger.info(LTag.PUMP, "Basal Profile was set: " + result.success); aapsLogger.info(LTag.PUMP, "Basal Profile was set: " + result.success);
@ -592,7 +586,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
} }
@Override @Override
public boolean isThisProfileSet(Profile profile) { public boolean isThisProfileSet(@NonNull Profile profile) {
if (!podStateManager.isPodActivationCompleted()) { if (!podStateManager.isPodActivationCompleted()) {
// When no Pod is active, return true here in order to prevent AAPS from setting a profile // When no Pod is active, return true here in order to prevent AAPS from setting a profile
// When we activate a new Pod, we just use ProfileFunction to set the currently active profile // When we activate a new Pod, we just use ProfileFunction to set the currently active profile
@ -663,8 +657,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
// if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed // if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed
@Override @Override
@NonNull @NonNull
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer public PumpEnactResult setTempBasalAbsolute(double absoluteRate, int durationInMinutes, @NonNull Profile profile, boolean enforceNew) {
durationInMinutes, Profile profile, boolean enforceNew) {
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes); aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes);
if (durationInMinutes <= 0 || durationInMinutes % BASAL_STEP_DURATION.getStandardMinutes() != 0) { if (durationInMinutes <= 0 || durationInMinutes % BASAL_STEP_DURATION.getStandardMinutes() != 0) {
@ -712,7 +705,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
// TODO improve (i8n and more) // TODO improve (i8n and more)
@NonNull @Override @NonNull @Override
public JSONObject getJSONStatus(Profile profile, String profileName, String version) { public JSONObject getJSONStatus(@NonNull Profile profile, @NonNull String profileName, @NonNull String version) {
if (!podStateManager.isPodActivationCompleted() || lastConnectionTimeMillis + 60 * 60 * 1000L < System.currentTimeMillis()) { if (!podStateManager.isPodActivationCompleted() || lastConnectionTimeMillis + 60 * 60 * 1000L < System.currentTimeMillis()) {
return new JSONObject(); return new JSONObject();
@ -824,17 +817,12 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
} }
@Override @Override
public List<CustomAction> getCustomActions() { public void executeCustomAction(@NonNull CustomActionType customActionType) {
return Collections.emptyList();
}
@Override
public void executeCustomAction(CustomActionType customActionType) {
aapsLogger.warn(LTag.PUMP, "Unknown custom action: " + customActionType); aapsLogger.warn(LTag.PUMP, "Unknown custom action: " + customActionType);
} }
@Override @Override
public PumpEnactResult executeCustomCommand(CustomCommand command) { public PumpEnactResult executeCustomCommand(@NonNull CustomCommand command) {
if (!(command instanceof OmnipodCustomCommand)) { if (!(command instanceof OmnipodCustomCommand)) {
aapsLogger.warn(LTag.PUMP, "Unknown custom command: " + command.getClass().getName()); aapsLogger.warn(LTag.PUMP, "Unknown custom command: " + command.getClass().getName());
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(resourceHelper.gs(R.string.omnipod_error_unknown_custom_command, command.getClass().getName())); return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(resourceHelper.gs(R.string.omnipod_error_unknown_custom_command, command.getClass().getName()));
@ -1018,12 +1006,16 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
aapsLogger.debug(LTag.PUMP, "finishHandshaking [OmnipodPumpPlugin] - default (empty) implementation."); aapsLogger.debug(LTag.PUMP, "finishHandshaking [OmnipodPumpPlugin] - default (empty) implementation.");
} }
@Override public void connect(String reason) { @Override public void connect(@NonNull String reason) {
if (displayConnectionMessages) if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "connect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason); aapsLogger.debug(LTag.PUMP, "connect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason);
} }
@Override public void disconnect(String reason) { @Override public int waitForDisconnectionInSeconds() {
return 0;
}
@Override public void disconnect(@NonNull String reason) {
if (displayConnectionMessages) if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "disconnect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason); aapsLogger.debug(LTag.PUMP, "disconnect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason);
} }
@ -1033,8 +1025,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
aapsLogger.debug(LTag.PUMP, "stopConnecting [PumpPluginAbstract] - default (empty) implementation."); aapsLogger.debug(LTag.PUMP, "stopConnecting [PumpPluginAbstract] - default (empty) implementation.");
} }
@NonNull @Override public PumpEnactResult setTempBasalPercent(Integer percent, Integer @NonNull @Override public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, @NonNull Profile profile, boolean enforceNew) {
durationInMinutes, Profile profile, boolean enforceNew) {
if (percent == 0) { if (percent == 0) {
return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew); return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew);
} else { } else {
@ -1045,8 +1036,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
} }
} }
@NonNull @Override public PumpEnactResult setExtendedBolus(Double insulin, Integer @NonNull @Override public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) {
durationInMinutes) {
aapsLogger.debug(LTag.PUMP, "setExtendedBolus [OmnipodPumpPlugin] - Not implemented."); aapsLogger.debug(LTag.PUMP, "setExtendedBolus [OmnipodPumpPlugin] - Not implemented.");
return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver); return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver);
} }