more CommandQueue tests
This commit is contained in:
parent
341a536011
commit
749bc49ad5
13 changed files with 393 additions and 61 deletions
|
@ -846,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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ 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.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;
|
||||||
|
@ -44,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
|
||||||
|
@ -76,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
|
||||||
|
@ -111,11 +108,15 @@ public class MDIPlugin extends PumpPluginBase implements PumpInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(String reason) {
|
public void connect(@NonNull String reason) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect(String reason) {
|
public void disconnect(@NonNull String reason) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public int waitForDisconnectionInSeconds() {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,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;
|
||||||
|
@ -135,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,6 +145,7 @@ class VirtualPumpPlugin @Inject constructor(
|
||||||
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) {
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -127,7 +127,7 @@ class QueueThread internal constructor(
|
||||||
}
|
}
|
||||||
if (queue.size() == 0 && queue.performing() == null) {
|
if (queue.size() == 0 && queue.performing() == null) {
|
||||||
val secondsFromLastCommand = (System.currentTimeMillis() - lastCommandTime) / 1000
|
val secondsFromLastCommand = (System.currentTimeMillis() - lastCommandTime) / 1000
|
||||||
if (secondsFromLastCommand >= 5) {
|
if (secondsFromLastCommand >= pump.waitForDisconnectionInSeconds()) {
|
||||||
waitingForDisconnect = true
|
waitingForDisconnect = true
|
||||||
aapsLogger.debug(LTag.PUMPQUEUE, "queue empty. disconnect")
|
aapsLogger.debug(LTag.PUMPQUEUE, "queue empty. disconnect")
|
||||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
|
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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) {}
|
||||||
|
}
|
|
@ -7,20 +7,24 @@ 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.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
|
||||||
|
@ -42,34 +46,67 @@ class CommandQueueTest : TestBaseWithProfile() {
|
||||||
@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
|
@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 {
|
||||||
if (it is Command) {
|
if (it is Command) {
|
||||||
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`(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)
|
||||||
|
@ -85,6 +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() {
|
||||||
|
|
||||||
|
@ -115,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
|
||||||
|
@ -225,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
|
||||||
|
@ -272,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
|
||||||
|
|
|
@ -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())
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,6 +25,7 @@ interface PumpInterface {
|
||||||
@JvmDefault fun finishHandshaking() {} // set initial handshake completed
|
@JvmDefault fun finishHandshaking() {} // set initial handshake completed
|
||||||
fun connect(reason: String)
|
fun connect(reason: String)
|
||||||
fun disconnect(reason: String)
|
fun disconnect(reason: String)
|
||||||
|
@JvmDefault fun waitForDisconnectionInSeconds(): Int = 5 // wait [x] second after last command before sending disconnect
|
||||||
fun stopConnecting()
|
fun stopConnecting()
|
||||||
fun getPumpStatus(reason: String)
|
fun getPumpStatus(reason: String)
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ interface PumpInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a list of custom actions to be displayed in the Actions tab.
|
* Provides a list of custom actions to be displayed in the Actions tab.
|
||||||
* Plese note that these actions will not be queued upon execution
|
* Please note that these actions will not be queued upon execution
|
||||||
*
|
*
|
||||||
* @return list of custom actions
|
* @return list of custom actions
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,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;
|
||||||
|
@ -137,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;
|
||||||
|
@ -175,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) //
|
||||||
|
@ -204,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);
|
||||||
|
|
||||||
|
@ -560,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;
|
||||||
|
@ -581,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);
|
||||||
|
@ -590,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
|
||||||
|
@ -661,7 +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, int durationInMinutes, Profile profile, boolean enforceNew) {
|
public PumpEnactResult setTempBasalAbsolute(double absoluteRate, int durationInMinutes, @NonNull 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) {
|
||||||
|
@ -709,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();
|
||||||
|
@ -821,12 +817,12 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements PumpInterfa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeCustomAction(CustomActionType customActionType) {
|
public void executeCustomAction(@NonNull 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()));
|
||||||
|
@ -1010,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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue