From 341a536011b0bf614b1a804cbe76cbe0a3adafdf Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 16 Feb 2021 21:30:47 +0100 Subject: [PATCH] PumpInterface -> kt --- .../general/actions/ActionsFragment.kt | 2 +- .../plugins/pump/combo/ComboPlugin.java | 36 +---- .../pump/insight/LocalInsightPlugin.java | 34 +--- .../plugins/pump/mdi/MDIPlugin.java | 33 +--- .../plugins/pump/virtual/VirtualPumpPlugin.kt | 89 +++------- .../pump/danaR/comm/MsgSettingBasalTest.kt | 2 +- .../androidaps/interfaces/PumpInterface.java | 152 ------------------ .../androidaps/interfaces/PumpInterface.kt | 101 ++++++++++++ .../general/actions/defs/CustomAction.kt | 7 +- .../pump/common/PumpPluginAbstract.java | 24 ++- .../danaRKorean/DanaRKoreanPlugin.java | 2 +- .../androidaps/danaRv2/DanaRv2Plugin.java | 6 +- .../androidaps/danar/AbstractDanaRPlugin.java | 37 +---- .../androidaps/danar/DanaRPlugin.java | 2 +- .../androidaps/danars/DanaRSPlugin.kt | 89 ++++------ .../pump/medtronic/MedtronicPumpPlugin.java | 16 +- .../omnipod/eros/OmnipodErosPumpPlugin.java | 16 +- 17 files changed, 208 insertions(+), 440 deletions(-) delete mode 100644 core/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java create mode 100644 core/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index 291971e428..f658956b51 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -312,7 +312,7 @@ class ActionsFragment : DaggerFragment() { private fun checkPumpCustomActions() { val activePump = activePlugin.activePump - val customActions = activePump.customActions ?: return + val customActions = activePump.getCustomActions() ?: return val currentContext = context ?: return removePumpCustomActions() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java index cee77a2303..eb80447c94 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java @@ -45,9 +45,6 @@ import info.nightscout.androidaps.logging.AAPSLogger; 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.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.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; @@ -224,11 +221,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr } @Override - public void finishHandshaking() { - } - - @Override - public void connect(String reason) { + public void connect(@NonNull String reason) { // ruffyscripter establishes a connection as needed. // ComboPlugin.runCommand performs on connect checks if needed, thus needs info on // whether a connection is there. @@ -240,7 +233,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr } @Override - public void disconnect(String reason) { + public void disconnect(@NonNull String reason) { getAapsLogger().debug(LTag.PUMP, "Disconnect called with reason: " + reason); ruffyScripter.disconnect(); } @@ -251,7 +244,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr } @NonNull @Override - public synchronized PumpEnactResult setNewBasalProfile(Profile profile) { + public synchronized PumpEnactResult setNewBasalProfile(@NonNull Profile profile) { if (!isInitialized()) { // 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 @@ -294,7 +287,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr } @Override - public boolean isThisProfileSet(Profile profile) { + public boolean isThisProfileSet(@NonNull Profile profile) { if (!isInitialized()) { /* This might be called too soon during boot. Return true to prevent a request 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. */ @Override - public synchronized void getPumpStatus(String reason) { + public synchronized void getPumpStatus(@NonNull String reason) { getAapsLogger().debug(LTag.PUMP, "getPumpStatus called"); if (!pump.initialized) { 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?) */ @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."); int unroundedPercentage = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue(); 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 */ @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); } @@ -794,7 +787,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr } @NonNull @Override - public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { + public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) { return OPERATION_NOT_SUPPORTED; } @@ -1388,19 +1381,6 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr return maxIob; } - @Override - public List getCustomActions() { - return null; - } - - @Override - public void executeCustomAction(CustomActionType customActionType) { - } - - @Nullable @Override public PumpEnactResult executeCustomCommand(CustomCommand customCommand) { - return null; - } - @Override public boolean canHandleDST() { return false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index 2459c7a4fa..f5b46ffc9e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -11,7 +11,6 @@ import android.os.IBinder; import android.os.Looper; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import org.json.JSONException; import org.json.JSONObject; @@ -54,8 +53,6 @@ import info.nightscout.androidaps.logging.AAPSLogger; 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.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.UploadQueue; 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.ParameterBlockUtil; 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.TimeChangeType; import info.nightscout.androidaps.utils.resources.ResourceHelper; @@ -343,11 +339,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, return false; } - @Override - public void finishHandshaking() { - - } - @Override public void connect(String reason) { if (connectionService != null && alertService != null) @@ -709,7 +700,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, } @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()); if (activeBasalRate == null) return result; if (activeBasalRate.getActiveBasalRate() == 0) return result; @@ -759,7 +750,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, } @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()); percent = (int) Math.round(((double) percent) / 10d) * 10; if (percent == 100) return cancelTempBasal(true); @@ -798,7 +789,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, } @NonNull @Override - public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { + public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) { PumpEnactResult result = cancelExtendedBolusOnly(); if (result.success) 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 - 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(); - if (connectionService == null) return null; + if (connectionService == null) return new JSONObject(); if (System.currentTimeMillis() - connectionService.getLastConnected() > (60 * 60 * 1000)) { - return null; + return new JSONObject(); } final JSONObject pump = new JSONObject(); @@ -1165,19 +1156,6 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, return new PumpEnactResult(getInjector()).success(true); } - @Override - public List getCustomActions() { - return null; - } - - @Override - public void executeCustomAction(CustomActionType customActionType) { - } - - @Nullable @Override public PumpEnactResult executeCustomCommand(CustomCommand customCommand) { - return null; - } - private void readHistory() { try { PumpTime pumpTime = connectionService.requestMessage(new GetDateTimeMessage()).await().getPumpTime(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java index c3aedab567..3da7a4af01 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java @@ -1,13 +1,10 @@ package info.nightscout.androidaps.plugins.pump.mdi; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import org.json.JSONException; import org.json.JSONObject; -import java.util.List; - import javax.inject.Inject; import javax.inject.Singleton; @@ -26,9 +23,6 @@ import info.nightscout.androidaps.logging.AAPSLogger; 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.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.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; @@ -116,10 +110,6 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface { return false; } - @Override - public void finishHandshaking() { - } - @Override public void connect(String reason) { } @@ -185,7 +175,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface { } @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()); result.success = false; result.comment = getResourceHelper().gs(R.string.pumperror); @@ -194,7 +184,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface { } @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()); result.success = false; result.comment = getResourceHelper().gs(R.string.pumperror); @@ -203,7 +193,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface { } @NonNull @Override - public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { + public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) { PumpEnactResult result = new PumpEnactResult(getInjector()); result.success = false; result.comment = getResourceHelper().gs(R.string.pumperror); @@ -230,7 +220,7 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface { } @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(); JSONObject pump = new JSONObject(); JSONObject status = new JSONObject(); @@ -277,26 +267,13 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface { return model().getModel(); } - @Override - public List getCustomActions() { - return null; - } - - @Override - public void executeCustomAction(CustomActionType customActionType) { - } - - @Nullable @Override public PumpEnactResult executeCustomCommand(CustomCommand customCommand) { - return null; - } - @Override public boolean canHandleDST() { return true; } @Override - public void timezoneOrDSTChanged(TimeChangeType changeType) { + public void timezoneOrDSTChanged(@NonNull TimeChangeType changeType) { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt index cdb27f376a..2cd35dfca8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt @@ -18,24 +18,21 @@ import info.nightscout.androidaps.logging.AAPSLogger 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.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.EventOverviewBolusProgress import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.plugins.pump.virtual.events.EventVirtualPumpUpdateGui 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.FabricPrivacy import info.nightscout.androidaps.utils.InstanceId.instanceId import info.nightscout.androidaps.utils.TimeChangeType -import io.reactivex.rxkotlin.plusAssign import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.disposables.CompositeDisposable +import io.reactivex.rxkotlin.plusAssign import org.json.JSONException import org.json.JSONObject import javax.inject.Inject @@ -75,7 +72,7 @@ class VirtualPumpPlugin @Inject constructor( var pumpType: PumpType? = null private set private var lastDataTime: Long = 0 - private val pumpDescription = PumpDescription() + override val pumpDescription = PumpDescription() init { pumpDescription.isBolusCapable = true @@ -129,49 +126,20 @@ class VirtualPumpPlugin @Inject constructor( uploadStatus.isVisible = !config.NSCLIENT } - override fun isFakingTempsByExtendedBoluses(): Boolean { - return config.NSCLIENT && getFakingStatus() - } + override val isFakingTempsByExtendedBoluses: Boolean + get() = config.NSCLIENT && getFakingStatus() override fun loadTDDs(): PumpEnactResult { //no result, could read DB in the future? return PumpEnactResult(injector) } - override fun getCustomActions(): List? { - return null - } + override val isInitialized: Boolean = true + 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) { //if (!Config.NSCLIENT) NSUpload.uploadDeviceStatus() lastDataTime = System.currentTimeMillis() @@ -179,7 +147,7 @@ class VirtualPumpPlugin @Inject constructor( override fun disconnect(reason: String) {} override fun stopConnecting() {} - override fun getPumpStatus(reason: String?) { + override fun getPumpStatus(reason: String) { lastDataTime = System.currentTimeMillis() } @@ -201,17 +169,14 @@ class VirtualPumpPlugin @Inject constructor( return lastDataTime } - override fun getBaseBasalRate(): Double { - return profileFunction.getProfile()?.basal ?: 0.0 - } + override val baseBasalRate: Double + get() = profileFunction.getProfile()?.basal ?: 0.0 - override fun getReservoirLevel(): Double { - return reservoirInUnits.toDouble() - } + override val reservoirLevel: Double + get() = reservoirInUnits.toDouble() - override fun getBatteryLevel(): Int { - return batteryPercent - } + override val batteryLevel: Int + get() = batteryPercent override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { val result = PumpEnactResult(injector) @@ -305,7 +270,7 @@ class VirtualPumpPlugin @Inject constructor( return result } - override fun cancelTempBasal(force: Boolean): PumpEnactResult { + override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult { val result = PumpEnactResult(injector) result.success = true result.isTempCancel = true @@ -392,10 +357,6 @@ class VirtualPumpPlugin @Inject constructor( return instanceId() } - override fun getPumpDescription(): PumpDescription { - return pumpDescription - } - override fun shortStatus(veryShort: Boolean): String { return "Virtual Pump" } @@ -405,15 +366,15 @@ class VirtualPumpPlugin @Inject constructor( } fun refreshConfiguration() { - val pumptype = sp.getString(R.string.key_virtualpump_type, PumpType.GenericAAPS.description) - val pumpTypeNew = PumpType.getByDescription(pumptype) - aapsLogger.debug(LTag.PUMP, "Pump in configuration: $pumptype, PumpType object: $pumpTypeNew") - if (pumpType == pumpTypeNew) return - aapsLogger.debug(LTag.PUMP, "New pump configuration found ($pumpTypeNew), changing from previous ($pumpType)") + val pumpType = sp.getString(R.string.key_virtualpump_type, PumpType.GenericAAPS.description) + val pumpTypeNew = PumpType.getByDescription(pumpType) + aapsLogger.debug(LTag.PUMP, "Pump in configuration: $pumpType, PumpType object: $pumpTypeNew") + if (this.pumpType == pumpTypeNew) return + aapsLogger.debug(LTag.PUMP, "New pump configuration found ($pumpTypeNew), changing from previous (${this.pumpType})") pumpDescription.setPumpDescription(pumpTypeNew) - pumpType = pumpTypeNew + this.pumpType = pumpTypeNew } - override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType?) {} + override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {} } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasalTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasalTest.kt index 7d281f6b50..4915e79dec 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasalTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingBasalTest.kt @@ -14,7 +14,7 @@ import org.powermock.modules.junit4.PowerMockRunner class MsgSettingBasalTest : DanaRTestBase() { @Test fun runTest() { - `when`(danaRPlugin.getPumpDescription()).thenReturn(PumpDescription()) + `when`(danaRPlugin.pumpDescription).thenReturn(PumpDescription()) val packet = MsgSettingBasal(injector) // test message decoding diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/core/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java deleted file mode 100644 index 3ea1479666..0000000000 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ /dev/null @@ -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 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; - } -} diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.kt new file mode 100644 index 0000000000..a8d1e886d7 --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.kt @@ -0,0 +1,101 @@ +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) + 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. + * Plese note that these actions will not be queued upon execution + * + * @return list of custom actions + */ + @JvmDefault fun getCustomActions(): List? = 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 +} \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.kt b/core/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.kt index be5e30496a..5a5cde8169 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.kt @@ -2,9 +2,8 @@ package info.nightscout.androidaps.plugins.general.actions.defs 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) { - - constructor(nameResourceId: Int, actionType: CustomActionType?, enabled: Boolean) : - this(nameResourceId, actionType, R.drawable.ic_actions_profileswitch, enabled) +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) : + this(nameResourceId, actionType, R.drawable.ic_actions_profileswitch, enabled) } \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java index 6d41ad4db0..b68234baee 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java +++ b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java @@ -44,7 +44,6 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.rx.AapsSchedulers; import info.nightscout.androidaps.utils.sharedPreferences.SP; import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.schedulers.Schedulers; /** * 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) * - * @return + * @return Class */ 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) aapsLogger.debug(LTag.PUMP, "connect (reason={}) [PumpPluginAbstract] - default (empty) implementation." + reason); } - public void disconnect(String reason) { + public void disconnect(@NonNull String reason) { if (displayConnectionMessages) 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 - @NonNull public PumpEnactResult setNewBasalProfile(Profile profile) { + @NonNull public PumpEnactResult setNewBasalProfile(@NonNull Profile profile) { aapsLogger.debug(LTag.PUMP, "setNewBasalProfile [PumpPluginAbstract] - Not implemented."); 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."); return true; } @@ -250,22 +249,20 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI @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) { aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute [PumpPluginAbstract] - Not implemented."); return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver); } @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) { aapsLogger.debug(LTag.PUMP, "setTempBasalPercent [PumpPluginAbstract] - Not implemented."); 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."); 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 - 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()) { 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(); } @@ -477,5 +474,4 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI private PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) { return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(resourceId)); } - } diff --git a/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.java b/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.java index bc73b69c61..32070359d4 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.java +++ b/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.java @@ -194,7 +194,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { // This is called from APS @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 //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()) { diff --git a/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java b/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java index e9f3f15da6..f27187a510 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java +++ b/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java @@ -220,7 +220,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { // This is called from APS @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 //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()) { @@ -251,7 +251,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { } 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. if (absoluteRate < 0.10d) percentRate = 0; if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue(); @@ -298,7 +298,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { } @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; PumpEnactResult result = new PumpEnactResult(getInjector()); percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value(); diff --git a/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java b/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java index dd34a34460..b5c7dd2278 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java +++ b/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java @@ -1,13 +1,11 @@ package info.nightscout.androidaps.danar; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import org.json.JSONException; import org.json.JSONObject; import java.util.Date; -import java.util.List; import dagger.android.HasAndroidInjector; 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.common.ManufacturerType; 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.EventNewNotification; 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.DecimalFormatter; import info.nightscout.androidaps.utils.Round; -import info.nightscout.androidaps.utils.TimeChangeType; import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.rx.AapsSchedulers; import info.nightscout.androidaps.utils.sharedPreferences.SP; @@ -223,7 +217,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump } @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; PumpEnactResult result = new PumpEnactResult(getInjector()); percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value(); @@ -271,7 +265,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump } @NonNull @Override - public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { + public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) { DanaPump pump = danaPump; insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value(); // needs to be rounded @@ -335,7 +329,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump } @Override - public void connect(String from) { + public void connect(@NonNull String from) { if (sExecutionService != null) { sExecutionService.connect(); pumpDescription.basalStep = danaPump.getBasalStep(); @@ -354,7 +348,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump } @Override - public void disconnect(String from) { + public void disconnect(@NonNull String from) { if (sExecutionService != null) sExecutionService.disconnect(from); } @@ -364,7 +358,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump } @Override - public void getPumpStatus(String reason) { + public void getPumpStatus(@NonNull String reason) { if (sExecutionService != null) { sExecutionService.getPumpStatus(); pumpDescription.basalStep = danaPump.getBasalStep(); @@ -373,7 +367,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump } @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; long now = 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 - - @Override - public List getCustomActions() { - return null; - } - - - @Override - public void executeCustomAction(CustomActionType customActionType) { - } - - @Nullable @Override public PumpEnactResult executeCustomCommand(CustomCommand customCommand) { - return null; - } - @Override public boolean canHandleDST() { return false; } - @Override - public void timezoneOrDSTChanged(TimeChangeType timeChangeType) { - } - @Override public void clearPairing() { } } diff --git a/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java b/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java index 277c09d0c2..3464d98e2a 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java +++ b/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java @@ -192,7 +192,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { // This is called from APS @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 //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()) { diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt b/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt index a0803d2a15..06f6e57e9c 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt @@ -24,14 +24,11 @@ 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.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.EventNewNotification 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.defs.PumpType -import info.nightscout.androidaps.queue.commands.CustomCommand import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers @@ -136,37 +133,28 @@ class DanaRSPlugin @Inject constructor( commandQueue.readStatus("DeviceChanged", null) } - override fun connect(from: String) { - aapsLogger.debug(LTag.PUMP, "RS connect from: $from") + override fun connect(reason: String) { + aapsLogger.debug(LTag.PUMP, "RS connect from: $reason") 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)) } } - override fun isConnected(): Boolean { - return danaRSService?.isConnected ?: false - } + override val isConnected: Boolean = danaRSService?.isConnected ?: false + override val isConnecting: Boolean = danaRSService?.isConnecting ?: false + override val isHandshakeInProgress: Boolean = false - override fun isConnecting(): Boolean { - return danaRSService?.isConnecting ?: false - } - - 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 disconnect(reason: String) { + aapsLogger.debug(LTag.PUMP, "RS disconnect from: $reason") + danaRSService?.disconnect(reason) } override fun stopConnecting() { danaRSService?.stopConnecting() } - override fun getPumpStatus(reason: String?) { + override fun getPumpStatus(reason: String) { danaRSService?.readPumpStatus() pumpDesc.basalStep = danaPump.basalStep pumpDesc.bolusStep = danaPump.bolusStep @@ -207,17 +195,14 @@ class DanaRSPlugin @Inject constructor( } // Pump interface - override fun isInitialized(): Boolean { - return danaPump.lastConnection > 0 && danaPump.maxBasal > 0 && danaPump.isRSPasswordOK - } + override val isInitialized: Boolean = + danaPump.lastConnection > 0 && danaPump.maxBasal > 0 && danaPump.isRSPasswordOK - override fun isSuspended(): Boolean { - return danaPump.pumpSuspended || danaPump.errorState != DanaPump.ErrorState.NONE - } + override val isSuspended: Boolean = + danaPump.pumpSuspended || danaPump.errorState != DanaPump.ErrorState.NONE - override fun isBusy(): Boolean { - return danaRSService?.isConnected ?: false || danaRSService?.isConnecting ?: false - } + override val isBusy: Boolean = + danaRSService?.isConnected ?: false || danaRSService?.isConnecting ?: false override fun setNewBasalProfile(profile: Profile): PumpEnactResult { val result = PumpEnactResult(injector) @@ -263,21 +248,10 @@ class DanaRSPlugin @Inject constructor( return true } - override fun lastDataTime(): Long { - return danaPump.lastConnection - } - - override fun getBaseBasalRate(): Double { - return danaPump.currentBasal - } - - override fun getReservoirLevel(): Double { - return danaPump.reservoirRemainingUnits - } - - override fun getBatteryLevel(): Int { - return danaPump.batteryRemaining - } + override fun lastDataTime(): Long = danaPump.lastConnection + override val baseBasalRate: Double = danaPump.currentBasal + override val reservoirLevel: Double = danaPump.reservoirRemainingUnits + override val batteryLevel: Int = danaPump.batteryRemaining @Synchronized override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { @@ -361,7 +335,7 @@ class DanaRSPlugin @Inject constructor( } if (doLowTemp || doHighTemp) { 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) { percentRate = java.lang.Double.valueOf(absoluteAfterConstrain / baseBasalRate * 100).toInt() } else { @@ -389,7 +363,7 @@ class DanaRSPlugin @Inject constructor( } } // 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) { setTempBasalPercent(percentRate, durationInMinutes, profile, enforceNew) } else { @@ -397,10 +371,10 @@ class DanaRSPlugin @Inject constructor( setHighTempBasalPercent(percentRate) } if (!result.success) { - aapsLogger.error("setTempBasalAbsolute: Failed to set hightemp basal") + aapsLogger.error("setTempBasalAbsolute: Failed to set high temp basal") return result } - aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: hightemp basal set ok") + aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: high temp basal set ok") return result } // We should never end here @@ -524,7 +498,7 @@ class DanaRSPlugin @Inject constructor( } @Synchronized - override fun cancelTempBasal(force: Boolean): PumpEnactResult { + override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult { val result = PumpEnactResult(injector) val runningTB = activePluginProvider.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis()) if (runningTB != null) { @@ -627,16 +601,15 @@ class DanaRSPlugin @Inject constructor( return danaPump.serialNumber } - override fun getPumpDescription(): PumpDescription { - return pumpDesc - } + override val pumpDescription: PumpDescription = pumpDesc + @Suppress("SpellCheckingInspection") override fun shortStatus(veryShort: Boolean): String { var ret = "" if (danaPump.lastConnection != 0L) { val agoMillis = System.currentTimeMillis() - danaPump.lastConnection val agoMin = (agoMillis / 60.0 / 1000.0).toInt() - ret += "LastConn: $agoMin minago\n" + ret += "LastConn: $agoMin minAgo\n" } if (danaPump.lastBolusTime != 0L) ret += "LastBolus: ${DecimalFormatter.to2Decimal(danaPump.lastBolusAmount)}U @${DateFormat.format("HH:mm", danaPump.lastBolusTime)}" @@ -657,13 +630,9 @@ class DanaRSPlugin @Inject constructor( 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 getCustomActions(): List? = null - override fun executeCustomAction(customActionType: CustomActionType) {} - override fun executeCustomCommand(customCommand: CustomCommand?): PumpEnactResult? = null override fun canHandleDST(): Boolean = false - override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType?) {} override fun clearPairing() { sp.remove(resourceHelper.gs(R.string.key_danars_pairingkey) + mDeviceName) sp.remove(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + mDeviceName) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java index 89aa6fcc7e..65d76859b1 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java @@ -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.util.MedtronicConst; 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.FabricPrivacy; import info.nightscout.androidaps.utils.TimeChangeType; @@ -648,7 +647,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter @Override - public boolean isThisProfileSet(Profile profile) { + public boolean isThisProfileSet(@NonNull Profile profile) { aapsLogger.debug(LTag.PUMP, "isThisProfileSet: basalInitalized=" + medtronicPumpStatus.basalProfileStatus); if (!isInitialized) @@ -875,7 +874,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter // LOG.debug("MedtronicPumpPlugin::deliverBolus - Show dialog. Context: " // + 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(); } @@ -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 false and the same rate is requested enacted=false and success=true is returned and TBR is not changed @NonNull @Override - public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, + public PumpEnactResult setTempBasalAbsolute(double absoluteRate, int durationInMinutes, Profile profile, boolean enforceNew) { setRefreshButtonEnabled(false); @@ -1070,8 +1069,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter @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) { if (percent == 0) { return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew); } else { @@ -1426,7 +1424,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter } @NonNull @Override - public PumpEnactResult setNewBasalProfile(Profile profile) { + public PumpEnactResult setNewBasalProfile(@NonNull Profile profile) { 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 @@ -1579,10 +1577,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter } - @Nullable @Override public PumpEnactResult executeCustomCommand(CustomCommand customCommand) { - return null; - } - @Override public void timezoneOrDSTChanged(TimeChangeType changeType) { diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPlugin.java b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPlugin.java index 2248faeada..43b5ba32e3 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPlugin.java +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPlugin.java @@ -17,7 +17,6 @@ import org.joda.time.Duration; import org.json.JSONException; import org.json.JSONObject; -import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Objects; @@ -51,7 +50,6 @@ import info.nightscout.androidaps.logging.AAPSLogger; 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.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.overview.events.EventDismissNotification; @@ -663,8 +661,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 @Override @NonNull - public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer - durationInMinutes, Profile profile, boolean enforceNew) { + public PumpEnactResult setTempBasalAbsolute(double absoluteRate, int durationInMinutes, Profile profile, boolean enforceNew) { aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes); if (durationInMinutes <= 0 || durationInMinutes % BASAL_STEP_DURATION.getStandardMinutes() != 0) { @@ -823,11 +820,6 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa return ret.trim(); } - @Override - public List getCustomActions() { - return Collections.emptyList(); - } - @Override public void executeCustomAction(CustomActionType customActionType) { aapsLogger.warn(LTag.PUMP, "Unknown custom action: " + customActionType); @@ -1033,8 +1025,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa aapsLogger.debug(LTag.PUMP, "stopConnecting [PumpPluginAbstract] - default (empty) implementation."); } - @NonNull @Override public PumpEnactResult setTempBasalPercent(Integer percent, Integer - durationInMinutes, Profile profile, boolean enforceNew) { + @NonNull @Override public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, @NonNull Profile profile, boolean enforceNew) { if (percent == 0) { return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew); } else { @@ -1045,8 +1036,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa } } - @NonNull @Override public PumpEnactResult setExtendedBolus(Double insulin, Integer - durationInMinutes) { + @NonNull @Override public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) { aapsLogger.debug(LTag.PUMP, "setExtendedBolus [OmnipodPumpPlugin] - Not implemented."); return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver); }