diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index 0db09d5348..fb5a073adf 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -34,15 +34,10 @@ import info.nightscout.androidaps.databinding.ActivityMainBinding import info.nightscout.androidaps.events.EventAppExit import info.nightscout.androidaps.events.EventPreferenceChange import info.nightscout.androidaps.events.EventRebuildTabs -import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.androidaps.interfaces.Config -import info.nightscout.androidaps.interfaces.IconsProvider -import info.nightscout.androidaps.interfaces.PluginType -import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin @@ -78,7 +73,7 @@ class MainActivity : NoSplashAppCompatActivity() { @Inject lateinit var sp: SP @Inject lateinit var versionCheckerUtils: VersionCheckerUtils @Inject lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin - @Inject lateinit var loopPlugin: LoopPlugin + @Inject lateinit var loop: Loop @Inject lateinit var nsSettingsStatus: NSSettingsStatus @Inject lateinit var buildHelper: BuildHelper @Inject lateinit var activePlugin: ActivePlugin @@ -124,7 +119,7 @@ class MainActivity : NoSplashAppCompatActivity() { }) //Check here if loop plugin is disabled. Else check via constraints - if (!loopPlugin.isEnabled()) versionCheckerUtils.triggerCheckVersion() + if (!(loop as PluginBase).isEnabled()) versionCheckerUtils.triggerCheckVersion() setUserStats() setupViews() disposable += rxBus diff --git a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt index 74d46d6b39..2a2bf5e03d 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.kt @@ -20,10 +20,10 @@ import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.extensions.toVisibility import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus import info.nightscout.androidaps.plugins.general.overview.OverviewData @@ -64,7 +64,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { @Inject lateinit var overviewMenus: OverviewMenus @Inject lateinit var dateUtil: DateUtil @Inject lateinit var config: Config - @Inject lateinit var loopPlugin: LoopPlugin + @Inject lateinit var loop: Loop @Inject lateinit var nsDeviceStatus: NSDeviceStatus @Inject lateinit var translator: Translator @@ -90,7 +90,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { // We don't want to use injected singletons but own instance working on top of different data iobCobCalculator = IobCobCalculatorPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, rh, profileFunction, activePlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy, dateUtil, repository) - overviewData = OverviewData(injector, aapsLogger, rh, dateUtil, sp, activePlugin, defaultValueHelper, profileFunction, config, loopPlugin, nsDeviceStatus, repository, overviewMenus, iobCobCalculator, translator) + overviewData = OverviewData(injector, aapsLogger, rh, dateUtil, sp, activePlugin, defaultValueHelper, profileFunction, config, loop, nsDeviceStatus, repository, overviewMenus, iobCobCalculator, translator) binding.left.setOnClickListener { adjustTimeRange(overviewData.fromTime - T.hours(rangeToDisplay.toLong()).msecs()) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt index 302db2bee6..af5f3d3742 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/LoopDialog.kt @@ -29,7 +29,6 @@ import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin @@ -54,7 +53,7 @@ class LoopDialog : DaggerDialogFragment() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var rh: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction - @Inject lateinit var loopPlugin: LoopPlugin + @Inject lateinit var loop: Loop @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var constraintChecker: ConstraintChecker @Inject lateinit var commandQueue: CommandQueue @@ -171,7 +170,7 @@ class LoopDialog : DaggerDialogFragment() { binding.overviewPump.visibility = View.GONE } - loopPlugin.isDisconnected -> { + loop.isDisconnected -> { binding.overviewLoop.visibility = View.GONE binding.overviewSuspend.visibility = View.GONE binding.overviewPump.visibility = View.VISIBLE @@ -180,7 +179,7 @@ class LoopDialog : DaggerDialogFragment() { binding.overviewReconnect.visibility = View.VISIBLE } - !loopPlugin.isEnabled() -> { + !(loop as PluginBase).isEnabled() -> { binding.overviewLoop.visibility = View.VISIBLE binding.overviewEnable.visibility = View.VISIBLE binding.overviewDisable.visibility = View.GONE @@ -189,7 +188,7 @@ class LoopDialog : DaggerDialogFragment() { binding.overviewReconnect.visibility = View.GONE } - loopPlugin.isSuspended -> { + loop.isSuspended -> { binding.overviewLoop.visibility = View.GONE binding.overviewSuspend.visibility = View.VISIBLE binding.overviewSuspendHeader.text = rh.gs(R.string.resumeloop) @@ -295,8 +294,8 @@ class LoopDialog : DaggerDialogFragment() { R.id.overview_disable -> { uel.log(Action.LOOP_DISABLED, Sources.LoopDialog) - loopPlugin.setPluginEnabled(PluginType.LOOP, false) - loopPlugin.setFragmentVisible(PluginType.LOOP, false) + (loop as PluginBase).setPluginEnabled(PluginType.LOOP, false) + (loop as PluginBase).setFragmentVisible(PluginType.LOOP, false) configBuilder.storeSettings("DisablingLoop") rxBus.send(EventRefreshOverview("suspend_menu")) commandQueue.cancelTempBasal(true, object : Callback() { @@ -318,8 +317,8 @@ class LoopDialog : DaggerDialogFragment() { R.id.overview_enable -> { uel.log(Action.LOOP_ENABLED, Sources.LoopDialog) - loopPlugin.setPluginEnabled(PluginType.LOOP, true) - loopPlugin.setFragmentVisible(PluginType.LOOP, true) + (loop as PluginBase).setPluginEnabled(PluginType.LOOP, true) + (loop as PluginBase).setFragmentVisible(PluginType.LOOP, true) configBuilder.storeSettings("EnablingLoop") rxBus.send(EventRefreshOverview("suspend_menu")) disposable += repository.runTransactionForResult(CancelCurrentOfflineEventIfAnyTransaction(dateUtil.now())) @@ -353,28 +352,28 @@ class LoopDialog : DaggerDialogFragment() { R.id.overview_suspend_1h -> { uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(1)) - loopPlugin.suspendLoop(T.hours(1).mins().toInt()) + loop.suspendLoop(T.hours(1).mins().toInt()) rxBus.send(EventRefreshOverview("suspend_menu")) return true } R.id.overview_suspend_2h -> { uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(2)) - loopPlugin.suspendLoop(T.hours(2).mins().toInt()) + loop.suspendLoop(T.hours(2).mins().toInt()) rxBus.send(EventRefreshOverview("suspend_menu")) return true } R.id.overview_suspend_3h -> { uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(3)) - loopPlugin.suspendLoop(T.hours(3).mins().toInt()) + loop.suspendLoop(T.hours(3).mins().toInt()) rxBus.send(EventRefreshOverview("suspend_menu")) return true } R.id.overview_suspend_10h -> { uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(10)) - loopPlugin.suspendLoop(T.hours(10).mins().toInt()) + loop.suspendLoop(T.hours(10).mins().toInt()) rxBus.send(EventRefreshOverview("suspend_menu")) return true } @@ -382,7 +381,7 @@ class LoopDialog : DaggerDialogFragment() { R.id.overview_disconnect_15m -> { profileFunction.getProfile()?.let { profile -> uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Minute(15)) - loopPlugin.goToZeroTemp(T.mins(15).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) + loop.goToZeroTemp(T.mins(15).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) rxBus.send(EventRefreshOverview("suspend_menu")) } return true @@ -391,7 +390,7 @@ class LoopDialog : DaggerDialogFragment() { R.id.overview_disconnect_30m -> { profileFunction.getProfile()?.let { profile -> uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Minute(30)) - loopPlugin.goToZeroTemp(T.mins(30).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) + loop.goToZeroTemp(T.mins(30).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) rxBus.send(EventRefreshOverview("suspend_menu")) } return true @@ -400,7 +399,7 @@ class LoopDialog : DaggerDialogFragment() { R.id.overview_disconnect_1h -> { profileFunction.getProfile()?.let { profile -> uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Hour(1)) - loopPlugin.goToZeroTemp(T.hours(1).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) + loop.goToZeroTemp(T.hours(1).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) rxBus.send(EventRefreshOverview("suspend_menu")) } sp.putBoolean(R.string.key_objectiveusedisconnect, true) @@ -410,7 +409,7 @@ class LoopDialog : DaggerDialogFragment() { R.id.overview_disconnect_2h -> { profileFunction.getProfile()?.let { profile -> uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Hour(2)) - loopPlugin.goToZeroTemp(T.hours(2).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) + loop.goToZeroTemp(T.hours(2).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) rxBus.send(EventRefreshOverview("suspend_menu")) } return true @@ -419,7 +418,7 @@ class LoopDialog : DaggerDialogFragment() { R.id.overview_disconnect_3h -> { profileFunction.getProfile()?.let { profile -> uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Hour(3)) - loopPlugin.goToZeroTemp(T.hours(3).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) + loop.goToZeroTemp(T.hours(3).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) rxBus.send(EventRefreshOverview("suspend_menu")) } return true diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/CarbSuggestionReceiver.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/CarbSuggestionReceiver.kt index 5382184d15..f1b906476d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/CarbSuggestionReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/CarbSuggestionReceiver.kt @@ -3,13 +3,15 @@ package info.nightscout.androidaps.plugins.aps.loop import android.content.Context import android.content.Intent import dagger.android.DaggerBroadcastReceiver +import info.nightscout.androidaps.interfaces.Loop import javax.inject.Inject class CarbSuggestionReceiver : DaggerBroadcastReceiver() { - @Inject lateinit var loopPlugin: LoopPlugin + @Inject lateinit var loop: Loop + override fun onReceive(context: Context, intent: Intent) { super.onReceive(context, intent) val duration = intent.getIntExtra("ignoreDuration", 5) - loopPlugin.disableCarbSuggestions(duration) + loop.disableCarbSuggestions(duration) } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt index 4b6a632913..eb55ddadb0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt @@ -8,6 +8,7 @@ import dagger.android.support.DaggerFragment import info.nightscout.androidaps.R import info.nightscout.androidaps.databinding.LoopFragmentBinding import info.nightscout.androidaps.interfaces.Constraint +import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui @@ -30,7 +31,7 @@ class LoopFragment : DaggerFragment() { @Inject lateinit var sp: SP @Inject lateinit var rh: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy - @Inject lateinit var loopPlugin: LoopPlugin + @Inject lateinit var loop: Loop @Inject lateinit var dateUtil: DateUtil private var disposable: CompositeDisposable = CompositeDisposable() @@ -52,7 +53,7 @@ class LoopFragment : DaggerFragment() { binding.run.setOnClickListener { binding.lastrun.text = rh.gs(R.string.executing) - Thread { loopPlugin.invoke("Loop button", true) }.start() + Thread { loop.invoke("Loop button", true) }.start() } } @@ -93,7 +94,7 @@ class LoopFragment : DaggerFragment() { @Synchronized fun updateGUI() { if (_binding == null) return - loopPlugin.lastRun?.let { + loop.lastRun?.let { binding.request.text = it.request?.toSpanned() ?: "" binding.constraintsprocessed.text = it.constraintsProcessed?.toSpanned() ?: "" binding.source.text = it.source ?: "" diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt index 827b8e81b9..394cf145d5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt @@ -175,7 +175,7 @@ class LoopPlugin @Inject constructor( setPluginEnabled(PluginType.LOOP, value) } - val isLGS: Boolean + override val isLGS: Boolean get() { val closedLoopEnabled = constraintChecker.isClosedLoopAllowed() val maxIobAllowed = constraintChecker.getMaxIOBAllowed().value() @@ -186,13 +186,13 @@ class LoopPlugin @Inject constructor( return isLGS } - val isSuperBolus: Boolean + override val isSuperBolus: Boolean get() { val offlineEventWrapped = repository.getOfflineEventActiveAt(dateUtil.now()).blockingGet() return offlineEventWrapped is ValueWrapper.Existing && offlineEventWrapped.value.reason == OfflineEvent.Reason.SUPER_BOLUS } - val isDisconnected: Boolean + override val isDisconnected: Boolean get() { val offlineEventWrapped = repository.getOfflineEventActiveAt(dateUtil.now()).blockingGet() return offlineEventWrapped is ValueWrapper.Existing && offlineEventWrapped.value.reason == OfflineEvent.Reason.DISCONNECT_PUMP @@ -208,10 +208,6 @@ class LoopPlugin @Inject constructor( return bool } - @Synchronized operator fun invoke(initiator: String, allowNotification: Boolean) { - invoke(initiator, allowNotification, false) - } - @Synchronized fun isEmptyQueue(): Boolean { val maxMinutes = 2L @@ -224,7 +220,7 @@ class LoopPlugin @Inject constructor( } @Synchronized - operator fun invoke(initiator: String, allowNotification: Boolean, tempBasalFallback: Boolean) { + override fun invoke(initiator: String, allowNotification: Boolean, tempBasalFallback: Boolean) { try { aapsLogger.debug(LTag.APS, "invoke from $initiator") val loopEnabled = constraintChecker.isLoopInvocationAllowed() @@ -443,7 +439,7 @@ class LoopPlugin @Inject constructor( } } - fun disableCarbSuggestions(durationMinutes: Int) { + override fun disableCarbSuggestions(durationMinutes: Int) { carbsSuggestionsSuspendedUntil = System.currentTimeMillis() + durationMinutes * 60 * 1000 dismissSuggestion() } @@ -479,7 +475,7 @@ class LoopPlugin @Inject constructor( rxBus.send(EventWearConfirmAction("cancelChangeRequest")) } - fun acceptChangeRequest() { + override fun acceptChangeRequest() { val profile = profileFunction.getProfile() ?: return lastRun?.let { lastRun -> lastRun.constraintsProcessed?.let { constraintsProcessed -> diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.kt index 3fbc8e009d..7880a30ac4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.kt @@ -5,7 +5,6 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification @@ -25,7 +24,7 @@ class DstHelperPlugin @Inject constructor( rh: ResourceHelper, private val sp: SP, private val activePlugin: ActivePlugin, - private val loopPlugin: LoopPlugin + private val loop: Loop ) : PluginBase(PluginDescription() .mainType(PluginType.CONSTRAINTS) .neverVisible(true) @@ -64,7 +63,7 @@ class DstHelperPlugin @Inject constructor( return value } if (wasDST(cal)) { - if (!loopPlugin.isSuspended) { + if (!loop.isSuspended) { val snoozedTo: Long = sp.getLong(R.string.key_snooze_loopdisabled, 0L) if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) { val notification = NotificationWithAction(injector, Notification.DST_LOOP_DISABLED, rh.gs(R.string.dst_loop_disabled_warning), Notification.LOW) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective0.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective0.kt index abb56ccf0f..bd2eb4d345 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective0.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective0.kt @@ -6,9 +6,8 @@ import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.IobCobCalculator +import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.interfaces.PluginBase -import info.nightscout.androidaps.interfaces.PluginType -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import javax.inject.Inject @@ -18,7 +17,7 @@ class Objective0(injector: HasAndroidInjector) : Objective(injector, "config", R @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var virtualPumpPlugin: VirtualPumpPlugin @Inject lateinit var repository: AppRepository - @Inject lateinit var loopPlugin: LoopPlugin + @Inject lateinit var loop: Loop @Inject lateinit var nsClientPlugin: NSClientPlugin @Inject lateinit var iobCobCalculator: IobCobCalculator @@ -54,7 +53,7 @@ class Objective0(injector: HasAndroidInjector) : Objective(injector, "config", R }) tasks.add(object : Task(this, R.string.loopenabled) { override fun isCompleted(): Boolean { - return loopPlugin.isEnabled() + return (loop as PluginBase).isEnabled() } }) tasks.add(object : Task(this, R.string.apsselected) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/dataBroadcaster/DataBroadcastPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/dataBroadcaster/DataBroadcastPlugin.kt index e4299709a7..89c95c3d6a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/dataBroadcaster/DataBroadcastPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/dataBroadcaster/DataBroadcastPlugin.kt @@ -13,7 +13,6 @@ import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.nsclient.data.DeviceStatusData import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus @@ -45,18 +44,19 @@ class DataBroadcastPlugin @Inject constructor( private val defaultValueHelper: DefaultValueHelper, private val nsDeviceStatus: NSDeviceStatus, private val deviceStatusData: DeviceStatusData, - private val loopPlugin: LoopPlugin, + private val loop: Loop, private val activePlugin: ActivePlugin, private var receiverStatusStore: ReceiverStatusStore, private val config: Config, private val glucoseStatusProvider: GlucoseStatusProvider -) : PluginBase(PluginDescription() - .mainType(PluginType.GENERAL) - .pluginName(R.string.databroadcaster) - .alwaysEnabled(true) - .neverVisible(true) - .showInList(false), +) : PluginBase( + PluginDescription() + .mainType(PluginType.GENERAL) + .pluginName(R.string.databroadcaster) + .alwaysEnabled(true) + .neverVisible(true) + .showInList(false), aapsLogger, rh, injector ) { @@ -64,33 +64,40 @@ class DataBroadcastPlugin @Inject constructor( override fun onStart() { super.onStart() disposable.add(rxBus - .toObservable(EventOpenAPSUpdateGui::class.java) - .observeOn(aapsSchedulers.io) - .subscribe({ sendData(it) }, fabricPrivacy::logException)) + .toObservable(EventOpenAPSUpdateGui::class.java) + .observeOn(aapsSchedulers.io) + .subscribe({ sendData(it) }, fabricPrivacy::logException) + ) disposable.add(rxBus - .toObservable(EventExtendedBolusChange::class.java) - .observeOn(aapsSchedulers.io) - .subscribe({ sendData(it) }, fabricPrivacy::logException)) + .toObservable(EventExtendedBolusChange::class.java) + .observeOn(aapsSchedulers.io) + .subscribe({ sendData(it) }, fabricPrivacy::logException) + ) disposable.add(rxBus - .toObservable(EventTempBasalChange::class.java) - .observeOn(aapsSchedulers.io) - .subscribe({ sendData(it) }, fabricPrivacy::logException)) + .toObservable(EventTempBasalChange::class.java) + .observeOn(aapsSchedulers.io) + .subscribe({ sendData(it) }, fabricPrivacy::logException) + ) disposable.add(rxBus - .toObservable(EventTreatmentChange::class.java) - .observeOn(aapsSchedulers.io) - .subscribe({ sendData(it) }, fabricPrivacy::logException)) + .toObservable(EventTreatmentChange::class.java) + .observeOn(aapsSchedulers.io) + .subscribe({ sendData(it) }, fabricPrivacy::logException) + ) disposable.add(rxBus - .toObservable(EventEffectiveProfileSwitchChanged::class.java) - .observeOn(aapsSchedulers.io) - .subscribe({ sendData(it) }, fabricPrivacy::logException)) + .toObservable(EventEffectiveProfileSwitchChanged::class.java) + .observeOn(aapsSchedulers.io) + .subscribe({ sendData(it) }, fabricPrivacy::logException) + ) disposable.add(rxBus - .toObservable(EventAutosensCalculationFinished::class.java) - .observeOn(aapsSchedulers.io) - .subscribe({ sendData(it) }, fabricPrivacy::logException)) + .toObservable(EventAutosensCalculationFinished::class.java) + .observeOn(aapsSchedulers.io) + .subscribe({ sendData(it) }, fabricPrivacy::logException) + ) disposable.add(rxBus - .toObservable(EventOverviewBolusProgress::class.java) - .observeOn(aapsSchedulers.io) - .subscribe({ sendData(it) }, fabricPrivacy::logException)) + .toObservable(EventOverviewBolusProgress::class.java) + .observeOn(aapsSchedulers.io) + .subscribe({ sendData(it) }, fabricPrivacy::logException) + ) } override fun onStop() { @@ -151,13 +158,15 @@ class DataBroadcastPlugin @Inject constructor( bundle.putInt("phoneBattery", receiverStatusStore.batteryLevel) bundle.putInt("rigBattery", nsDeviceStatus.uploaderStatus.replace("%", "").trim { it <= ' ' }.toInt()) - if (config.APS && loopPlugin.lastRun?.lastTBREnact != 0L) { //we are AndroidAPS - bundle.putLong("suggestedTimeStamp", loopPlugin.lastRun?.lastAPSRun ?: -1L) - bundle.putString("suggested", loopPlugin.lastRun?.request?.json().toString()) - if (loopPlugin.lastRun?.tbrSetByPump != null && loopPlugin.lastRun?.tbrSetByPump?.enacted == true) { - bundle.putLong("enactedTimeStamp", loopPlugin.lastRun?.lastTBREnact - ?: -1L) - bundle.putString("enacted", loopPlugin.lastRun?.request?.json().toString()) + if (config.APS && loop.lastRun?.lastTBREnact != 0L) { //we are AndroidAPS + bundle.putLong("suggestedTimeStamp", loop.lastRun?.lastAPSRun ?: -1L) + bundle.putString("suggested", loop.lastRun?.request?.json().toString()) + if (loop.lastRun?.tbrSetByPump != null && loop.lastRun?.tbrSetByPump?.enacted == true) { + bundle.putLong( + "enactedTimeStamp", loop.lastRun?.lastTBREnact + ?: -1L + ) + bundle.putString("enacted", loop.lastRun?.request?.json().toString()) } } else { //NSClient or remote val data = deviceStatusData.openAPSData diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewData.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewData.kt index c93d582d88..1d1d41b1cb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewData.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewData.kt @@ -10,12 +10,14 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.data.IobTotal import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.ValueWrapper -import info.nightscout.androidaps.database.entities.* +import info.nightscout.androidaps.database.entities.Bolus +import info.nightscout.androidaps.database.entities.GlucoseValue +import info.nightscout.androidaps.database.entities.TemporaryTarget +import info.nightscout.androidaps.database.entities.TherapyEvent import info.nightscout.androidaps.extensions.* import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus import info.nightscout.androidaps.plugins.general.overview.graphExtensions.* @@ -45,7 +47,7 @@ class OverviewData @Inject constructor( private val defaultValueHelper: DefaultValueHelper, private val profileFunction: ProfileFunction, private val config: Config, - private val loopPlugin: LoopPlugin, + private val loop: Loop, private val nsDeviceStatus: NSDeviceStatus, private val repository: AppRepository, private val overviewMenus: OverviewMenus, @@ -317,8 +319,8 @@ class OverviewData @Inject constructor( @Synchronized fun preparePredictions(from: String) { // val start = dateUtil.now() - val apsResult = if (config.APS) loopPlugin.lastRun?.constraintsProcessed else nsDeviceStatus.getAPSResult(injector) - val predictionsAvailable = if (config.APS) loopPlugin.lastRun?.request?.hasPredictions == true else config.NSCLIENT + val apsResult = if (config.APS) loop.lastRun?.constraintsProcessed else nsDeviceStatus.getAPSResult(injector) + val predictionsAvailable = if (config.APS) loop.lastRun?.request?.hasPredictions == true else config.NSCLIENT val menuChartSettings = overviewMenus.setting // align to hours val calendar = Calendar.getInstance().also { @@ -480,7 +482,7 @@ class OverviewData @Inject constructor( var toTime = toTime val targetsSeriesArray: MutableList = java.util.ArrayList() var lastTarget = -1.0 - loopPlugin.lastRun?.constraintsProcessed?.let { toTime = max(it.latestPredictionsTime, toTime) } + loop.lastRun?.constraintsProcessed?.let { toTime = max(it.latestPredictionsTime, toTime) } var time = fromTime while (time < toTime) { val tt = repository.getTemporaryTargetActiveAt(time).blockingGet() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index d9d0049edd..f06b0610c9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -46,7 +46,6 @@ import info.nightscout.androidaps.extensions.valueToUnitsString import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker @@ -99,7 +98,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList @Inject lateinit var constraintChecker: ConstraintChecker @Inject lateinit var statusLightHandler: StatusLightHandler @Inject lateinit var nsDeviceStatus: NSDeviceStatus - @Inject lateinit var loopPlugin: LoopPlugin + @Inject lateinit var loop: Loop @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var iobCobCalculator: IobCobCalculator @Inject lateinit var dexcomPlugin: DexcomPlugin @@ -409,10 +408,10 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList R.id.accept_temp_button -> { profileFunction.getProfile() ?: return - if (loopPlugin.isEnabled()) { + if ((loop as PluginBase).isEnabled()) { handler.post { - val lastRun = loopPlugin.lastRun - loopPlugin.invoke("Accept temp button", false) + val lastRun = loop.lastRun + loop.invoke("Accept temp button", false) if (lastRun?.lastAPSRun != null && lastRun.constraintsProcessed?.isChangeRequested == true) { protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { OKDialog.showConfirmation(activity, rh.gs(R.string.tempbasal_label), lastRun.constraintsProcessed?.toSpanned() @@ -421,7 +420,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList binding.buttonsLayout.acceptTempButton.visibility = View.GONE (context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).cancel(Constants.notificationID) rxBus.send(EventWearInitiateAction("cancelChangeRequest")) - Thread { loopPlugin.acceptChangeRequest() }.run() + Thread { loop.acceptChangeRequest() }.run() }) }) } @@ -524,7 +523,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } else binding.buttonsLayout.quickWizardButton.visibility = View.GONE // **** Temp button **** - val lastRun = loopPlugin.lastRun + val lastRun = loop.lastRun val closedLoopEnabled = constraintChecker.isClosedLoopAllowed() val showAcceptButton = !closedLoopEnabled.value() && // Open mode needed @@ -532,7 +531,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList (lastRun.lastOpenModeAccept == 0L || lastRun.lastOpenModeAccept < lastRun.lastAPSRun) &&// never accepted or before last result lastRun.constraintsProcessed?.isChangeRequested == true // change is requested - if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && loopPlugin.isEnabled()) { + if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && (loop as PluginBase).isEnabled()) { binding.buttonsLayout.acceptTempButton.visibility = View.VISIBLE binding.buttonsLayout.acceptTempButton.text = "${rh.gs(R.string.setbasalquestion)}\n${lastRun!!.constraintsProcessed}" } else { @@ -592,21 +591,21 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList binding.infoLayout.apsMode.visibility = View.VISIBLE binding.infoLayout.timeLayout.visibility = View.GONE when { - loopPlugin.isEnabled() && loopPlugin.isSuperBolus -> { + (loop as PluginBase).isEnabled() && loop.isSuperBolus -> { binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_superbolus) - binding.infoLayout.apsModeText.text = dateUtil.age(loopPlugin.minutesToEndOfSuspend() * 60000L, true, rh) + binding.infoLayout.apsModeText.text = dateUtil.age(loop.minutesToEndOfSuspend() * 60000L, true, rh) binding.infoLayout.apsModeText.visibility = View.VISIBLE } - loopPlugin.isDisconnected -> { + loop.isDisconnected -> { binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_disconnected) - binding.infoLayout.apsModeText.text = dateUtil.age(loopPlugin.minutesToEndOfSuspend() * 60000L, true, rh) + binding.infoLayout.apsModeText.text = dateUtil.age(loop.minutesToEndOfSuspend() * 60000L, true, rh) binding.infoLayout.apsModeText.visibility = View.VISIBLE } - loopPlugin.isEnabled() && loopPlugin.isSuspended -> { + (loop as PluginBase).isEnabled() && loop.isSuspended -> { binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_paused) - binding.infoLayout.apsModeText.text = dateUtil.age(loopPlugin.minutesToEndOfSuspend() * 60000L, true, rh) + binding.infoLayout.apsModeText.text = dateUtil.age(loop.minutesToEndOfSuspend() * 60000L, true, rh) binding.infoLayout.apsModeText.visibility = View.VISIBLE } @@ -623,17 +622,17 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList binding.infoLayout.apsModeText.visibility = View.GONE } - loopPlugin.isEnabled() && closedLoopEnabled.value() && loopPlugin.isLGS -> { + (loop as PluginBase).isEnabled() && closedLoopEnabled.value() && loop.isLGS -> { binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_lgs) binding.infoLayout.apsModeText.visibility = View.GONE } - loopPlugin.isEnabled() && closedLoopEnabled.value() -> { + (loop as PluginBase).isEnabled() && closedLoopEnabled.value() -> { binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_closed) binding.infoLayout.apsModeText.visibility = View.GONE } - loopPlugin.isEnabled() && !closedLoopEnabled.value() -> { + (loop as PluginBase).isEnabled() && !closedLoopEnabled.value() -> { binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_open) binding.infoLayout.apsModeText.visibility = View.GONE } @@ -837,8 +836,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList // cob var cobText = overviewData.cobInfo?.displayText(rh, dateUtil, buildHelper.isEngineeringMode()) ?: rh.gs(R.string.value_unavailable_short) - val constraintsProcessed = loopPlugin.lastRun?.constraintsProcessed - val lastRun = loopPlugin.lastRun + val constraintsProcessed = loop.lastRun?.constraintsProcessed + val lastRun = loop.lastRun if (config.APS && constraintsProcessed != null && lastRun != null) { if (constraintsProcessed.carbsReq > 0) { //only display carbsreq when carbs have not been entered recently @@ -868,7 +867,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } else { // If the target is not the same as set in the profile then oref has overridden it profileFunction.getProfile()?.let { profile -> - val targetUsed = loopPlugin.lastRun?.constraintsProcessed?.targetBG ?: 0.0 + val targetUsed = loop.lastRun?.constraintsProcessed?.targetBG ?: 0.0 if (targetUsed != 0.0 && abs(profile.getTargetMgdl() - targetUsed) > 0.01) { aapsLogger.debug("Adjusted target. Profile: ${profile.getTargetMgdl()} APS: $targetUsed") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewMenus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewMenus.kt index baf807f31c..fcf110da98 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewMenus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewMenus.kt @@ -9,11 +9,11 @@ import androidx.annotation.ColorRes import androidx.annotation.StringRes import androidx.appcompat.widget.PopupMenu import com.google.gson.Gson -import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.R import info.nightscout.androidaps.events.EventRefreshOverview +import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -28,7 +28,7 @@ class OverviewMenus @Inject constructor( private val sp: SP, private val rxBus: RxBus, private val buildHelper: BuildHelper, - private val loopPlugin: LoopPlugin, + private val loop: Loop, private val config: Config ) { @@ -92,7 +92,7 @@ class OverviewMenus @Inject constructor( chartButton.setOnClickListener { v: View -> val predictionsAvailable: Boolean = when { - config.APS -> loopPlugin.lastRun?.request?.hasPredictions ?: false + config.APS -> loop.lastRun?.request?.hasPredictions ?: false config.NSCLIENT -> true else -> false } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt index f3a5348a65..9b9a8df370 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt @@ -27,7 +27,6 @@ import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification @@ -64,7 +63,7 @@ class ActionStringHandler @Inject constructor( private val context: Context, private val constraintChecker: ConstraintChecker, private val profileFunction: ProfileFunction, - private val loopPlugin: LoopPlugin, + private val loop: Loop, private val wearPlugin: WearPlugin, private val fabricPrivacy: FabricPrivacy, private val commandQueue: CommandQueue, @@ -320,7 +319,7 @@ class ActionStringHandler @Inject constructor( } else if ("changeRequest" == act[0]) { ////////////////////////////////////////////// CHANGE REQUEST rTitle = rh.gs(R.string.openloop_newsuggestion) rAction = "changeRequest" - loopPlugin.lastRun?.let { + loop.lastRun?.let { rMessage += it.constraintsProcessed wearPlugin.requestChangeConfirmation(rTitle, rMessage, rAction) lastSentTimestamp = System.currentTimeMillis() @@ -424,7 +423,7 @@ class ActionStringHandler @Inject constructor( get() { var ret = "" // decide if enabled/disabled closed/open; what Plugin as APS? - if (loopPlugin.isEnabled(loopPlugin.getType())) { + if ((loop as PluginBase).isEnabled()) { ret += if (constraintChecker.isClosedLoopAllowed().value()) { "CLOSED LOOP\n" } else { @@ -432,7 +431,7 @@ class ActionStringHandler @Inject constructor( } val aps = activePlugin.activeAPS ret += "APS: " + (aps as PluginBase).name - val lastRun = loopPlugin.lastRun + val lastRun = loop.lastRun if (lastRun != null) { ret += "\nLast Run: " + dateUtil.timeString(lastRun.lastAPSRun) if (lastRun.lastTBREnact != 0L) ret += "\nLast Enact: " + dateUtil.timeString(lastRun.lastTBREnact) @@ -505,8 +504,8 @@ class ActionStringHandler @Inject constructor( doFillBolus(amount) } else if ("temptarget" == act[0]) { val duration = SafeParse.stringToInt(act[2]) - var low = SafeParse.stringToDouble(act[3]) - var high = SafeParse.stringToDouble(act[4]) + val low = SafeParse.stringToDouble(act[3]) + val high = SafeParse.stringToDouble(act[4]) generateTempTarget(duration, low, high) } else if ("wizard2" == act[0]) { if (lastBolusWizard != null) { //use last calculation as confirmed string matches @@ -529,7 +528,7 @@ class ActionStringHandler @Inject constructor( } else if ("dismissoverviewnotification" == act[0]) { rxBus.send(EventDismissNotification(SafeParse.stringToInt(act[1]))) } else if ("changeRequest" == act[0]) { - loopPlugin.acceptChangeRequest() + loop.acceptChangeRequest() val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager notificationManager.cancel(Constants.notificationID) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt index d7666098c5..3ae44c8ebb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/WearPlugin.kt @@ -6,12 +6,12 @@ import dagger.Lazy import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R import info.nightscout.androidaps.events.* +import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusProgressIfRunning import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress @@ -33,7 +33,7 @@ class WearPlugin @Inject constructor( private val sp: SP, private val ctx: Context, private val fabricPrivacy: FabricPrivacy, - private val loopPlugin: Lazy, + private val loop: Loop, private val rxBus: RxBus, private val actionStringHandler: Lazy @@ -88,7 +88,7 @@ class WearPlugin @Inject constructor( .toObservable(EventRefreshOverview::class.java) .observeOn(aapsSchedulers.io) .subscribe({ - if (WatchUpdaterService.shouldReportLoopStatus(loopPlugin.get().isEnabled())) + if (WatchUpdaterService.shouldReportLoopStatus((loop as PluginBase).isEnabled())) sendDataToWatch(status = true, basals = false, bgValue = false) }, fabricPrivacy::logException)) disposable.add(rxBus diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java index ca19f52fb1..af401aa92a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java @@ -42,6 +42,8 @@ import info.nightscout.androidaps.interfaces.ActivePlugin; import info.nightscout.androidaps.interfaces.Config; import info.nightscout.androidaps.interfaces.GlucoseUnit; import info.nightscout.androidaps.interfaces.IobCobCalculator; +import info.nightscout.androidaps.interfaces.Loop; +import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.Profile; import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.logging.AAPSLogger; @@ -73,7 +75,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog @Inject public DefaultValueHelper defaultValueHelper; @Inject public NSDeviceStatus nsDeviceStatus; @Inject public ActivePlugin activePlugin; - @Inject public LoopPlugin loopPlugin; + @Inject public Loop loop; @Inject public IobCobCalculator iobCobCalculator; @Inject public AppRepository repository; @Inject ReceiverStatusStore receiverStatusStore; @@ -509,7 +511,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog repository.getCarbsDataFromTimeExpanded(startTimeWindow, true).blockingGet() .forEach(carb -> boluses.add(treatmentMap(carb.getTimestamp(), 0, carb.getAmount(), false, carb.isValid()))); - final LoopPlugin.LastRun finalLastRun = loopPlugin.getLastRun(); + final LoopPlugin.LastRun finalLastRun = loop.getLastRun(); if (sp.getBoolean("wear_predictions", true) && finalLastRun != null && finalLastRun.getRequest().getHasPredictions() && finalLastRun.getConstraintsProcessed() != null) { List predArray = finalLastRun.getConstraintsProcessed().getPredictions() @@ -688,7 +690,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog //OpenAPS status if (config.getAPS()) { //we are AndroidAPS - openApsStatus = loopPlugin.getLastRun() != null && loopPlugin.getLastRun().getLastTBREnact() != 0 ? loopPlugin.getLastRun().getLastTBREnact() : -1; + openApsStatus = loop.getLastRun() != null && loop.getLastRun().getLastTBREnact() != 0 ? loop.getLastRun().getLastTBREnact() : -1; } else { //NSClient or remote openApsStatus = nsDeviceStatus.getOpenApsTimestamp(); @@ -741,7 +743,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog return status; } - if (!loopPlugin.isEnabled()) { + if (!((PluginBase)loop).isEnabled()) { status += rh.gs(R.string.disabledloop) + "\n"; lastLoopStatus = false; } else { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatusLinePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatusLinePlugin.kt index 5eb9ac1c47..2f7ad1fe31 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatusLinePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatusLinePlugin.kt @@ -9,7 +9,6 @@ import info.nightscout.androidaps.events.* import info.nightscout.androidaps.extensions.toStringShort import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.FabricPrivacy @@ -30,7 +29,7 @@ class StatusLinePlugin @Inject constructor( private val aapsSchedulers: AapsSchedulers, private val context: Context, private val fabricPrivacy: FabricPrivacy, - private val loopPlugin: LoopPlugin, + private val loop: Loop, private val iobCobCalculator: IobCobCalculator, private val rxBus: RxBus, aapsLogger: AAPSLogger @@ -66,7 +65,7 @@ class StatusLinePlugin @Inject constructor( super.onStart() disposable += rxBus.toObservable(EventRefreshOverview::class.java) .observeOn(aapsSchedulers.io) - .subscribe({ if (lastLoopStatus != loopPlugin.isEnabled()) sendStatus() }, fabricPrivacy::logException) + .subscribe({ if (lastLoopStatus != (loop as PluginBase).isEnabled()) sendStatus() }, fabricPrivacy::logException) disposable += rxBus.toObservable(EventExtendedBolusChange::class.java) .observeOn(aapsSchedulers.io) .subscribe({ sendStatus() }, fabricPrivacy::logException) @@ -113,12 +112,11 @@ class StatusLinePlugin @Inject constructor( private fun buildStatusString(profile: Profile): String { var status = "" - if (!loopPlugin.isEnabled()) { + if (!(loop as PluginBase).isEnabled()) { status += rh.gs(R.string.disabledloop) + "\n" lastLoopStatus = false - } else if (loopPlugin.isEnabled()) { - lastLoopStatus = true - } + } else lastLoopStatus = true + //Temp basal val activeTemp = iobCobCalculator.getTempBasalIncludingConvertedExtended(System.currentTimeMillis()) if (activeTemp != null) { diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt index 03e65fbc5a..9f76df12f1 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt @@ -14,17 +14,12 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.R import info.nightscout.androidaps.data.ProfileSealed -import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.events.EventProfileSwitchChanged import info.nightscout.androidaps.extensions.buildDeviceStatus -import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.androidaps.interfaces.CommandQueue -import info.nightscout.androidaps.interfaces.IobCobCalculator -import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.configBuilder.RunningConfiguration import info.nightscout.androidaps.plugins.general.maintenance.MaintenancePlugin @@ -64,7 +59,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { @Inject lateinit var repository: AppRepository @Inject lateinit var config: Config @Inject lateinit var iobCobCalculator: IobCobCalculator - @Inject lateinit var loopPlugin: LoopPlugin + @Inject lateinit var loop: Loop @Inject lateinit var dateUtil: DateUtil @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var profileFunction: ProfileFunction @@ -124,12 +119,12 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { var shouldUploadStatus = false if (config.NSCLIENT) return if (config.PUMPCONTROL) shouldUploadStatus = true - else if (!loopPlugin.isEnabled() || iobCobCalculator.ads.actualBg() == null) + else if (!(loop as PluginBase).isEnabled() || iobCobCalculator.ads.actualBg() == null) shouldUploadStatus = true else if (dateUtil.isOlderThan(activePlugin.activeAPS.lastAPSRun, 5)) shouldUploadStatus = true if (dateUtil.isOlderThan(lastIobUpload, IOB_UPDATE_FREQUENCY_IN_MINUTES) && shouldUploadStatus) { lastIobUpload = dateUtil.now() - buildDeviceStatus(dateUtil, loopPlugin, iobCobCalculator, profileFunction, + buildDeviceStatus(dateUtil, loop, iobCobCalculator, profileFunction, activePlugin.activePump, receiverStatusStore, runningConfiguration, BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION)?.also { repository.insert(it) @@ -149,7 +144,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { // sometimes keep alive broadcast stops // as as workaround test if readStatus was requested before an alarm is generated if (lastReadStatus != 0L && lastReadStatus > System.currentTimeMillis() - T.mins(5).msecs()) { - localAlertUtils.checkPumpUnreachableAlarm(lastConnection, isStatusOutdated, loopPlugin.isDisconnected) + localAlertUtils.checkPumpUnreachableAlarm(lastConnection, isStatusOutdated, loop.isDisconnected) } if (runningProfile == null || ((!pump.isThisProfileSet(requestedProfile) || !requestedProfile.isEqual(runningProfile)) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE))) { rxBus.send(EventProfileSwitchChanged()) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt index ccdef22e95..74950918f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt @@ -5,33 +5,30 @@ import android.content.Intent import android.text.Spanned import com.google.common.base.Joiner import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.data.DetailedBolusInfo -import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.BolusCalculatorResult import info.nightscout.androidaps.database.entities.OfflineEvent -import info.nightscout.androidaps.database.entities.ValueWithUnit import info.nightscout.androidaps.database.entities.TemporaryTarget import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Sources +import info.nightscout.androidaps.database.entities.ValueWithUnit import info.nightscout.androidaps.database.transactions.InsertOrUpdateBolusCalculatorResultTransaction import info.nightscout.androidaps.events.EventRefreshOverview +import info.nightscout.androidaps.extensions.formatColor import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider import info.nightscout.androidaps.queue.Callback -import info.nightscout.androidaps.utils.alertDialogs.OKDialog -import info.nightscout.androidaps.extensions.formatColor import info.nightscout.androidaps.utils.* +import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.disposables.CompositeDisposable @@ -52,7 +49,7 @@ class BolusWizard @Inject constructor( @Inject lateinit var constraintChecker: ConstraintChecker @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var commandQueue: CommandQueue - @Inject lateinit var loopPlugin: LoopPlugin + @Inject lateinit var loop: Loop @Inject lateinit var iobCobCalculator: IobCobCalculator @Inject lateinit var dateUtil: DateUtil @Inject lateinit var config: Config @@ -373,8 +370,8 @@ class BolusWizard @Inject constructor( if (insulinAfterConstraints > 0 || carbs > 0) { if (useSuperBolus) { uel.log(Action.SUPERBOLUS_TBR, Sources.WizardDialog) - if (loopPlugin.isEnabled()) { - loopPlugin.goToZeroTemp(2 * 60, profile, OfflineEvent.Reason.SUPER_BOLUS) + if ((loop as PluginBase).isEnabled()) { + loop.goToZeroTemp(2 * 60, profile, OfflineEvent.Reason.SUPER_BOLUS) rxBus.send(EventRefreshOverview("WizardDialog")) } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/wizard/QuickWizardEntry.kt b/app/src/main/java/info/nightscout/androidaps/utils/wizard/QuickWizardEntry.kt index f2217d20ad..e0d88db22d 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/wizard/QuickWizardEntry.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/wizard/QuickWizardEntry.kt @@ -7,10 +7,11 @@ import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.database.entities.GlucoseValue import info.nightscout.androidaps.extensions.valueToUnits import info.nightscout.androidaps.interfaces.IobCobCalculator +import info.nightscout.androidaps.interfaces.Loop +import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.JsonHelper.safeGetInt @@ -25,7 +26,7 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var sp: SP @Inject lateinit var profileFunction: ProfileFunction - @Inject lateinit var loopPlugin: LoopPlugin + @Inject lateinit var loop: Loop @Inject lateinit var iobCobCalculator: IobCobCalculator @Inject lateinit var repository: AppRepository @Inject lateinit var dateUtil: DateUtil @@ -107,7 +108,7 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec if (useSuperBolus() == YES && sp.getBoolean(R.string.key_usesuperbolus, false)) { superBolus = true } - if (loopPlugin.isEnabled(loopPlugin.getType()) && loopPlugin.isSuperBolus) superBolus = false + if ((loop as PluginBase).isEnabled() && loop.isSuperBolus) superBolus = false // Trend val glucoseStatus = glucoseStatusProvider.glucoseStatusData var trend = false diff --git a/app/src/test/java/info/nightscout/androidaps/data/QuickWizardTest.kt b/app/src/test/java/info/nightscout/androidaps/data/QuickWizardTest.kt index 61f30ea92e..5299f9ab21 100644 --- a/app/src/test/java/info/nightscout/androidaps/data/QuickWizardTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/data/QuickWizardTest.kt @@ -4,8 +4,8 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBase +import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.wizard.QuickWizard import info.nightscout.androidaps.utils.wizard.QuickWizardEntry @@ -20,7 +20,7 @@ class QuickWizardTest : TestBase() { @Mock lateinit var sp: SP @Mock lateinit var profileFunction: ProfileFunction - @Mock lateinit var loopPlugin: LoopPlugin + @Mock lateinit var loop: Loop private val data1 = "{\"buttonText\":\"Meal\",\"carbs\":36,\"validFrom\":0,\"validTo\":18000," + "\"useBG\":0,\"useCOB\":0,\"useBolusIOB\":0,\"useBasalIOB\":0,\"useTrend\":0,\"useSuperBolus\":0,\"useTemptarget\":0}" @@ -34,7 +34,7 @@ class QuickWizardTest : TestBase() { it.aapsLogger = aapsLogger it.sp = sp it.profileFunction = profileFunction - it.loopPlugin = loopPlugin + it.loop = loop } } } diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt index 68dd9ae32c..a7ebd22d07 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -30,7 +30,6 @@ import info.nightscout.androidaps.plugins.source.GlimpPlugin import info.nightscout.androidaps.utils.HardLimits import info.nightscout.androidaps.utils.Profiler import info.nightscout.androidaps.utils.buildHelper.BuildHelperImpl -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before @@ -131,17 +130,14 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { insightDbHelper = InsightDbHelper(insightDatabaseDao) danaPump = DanaPump(aapsLogger, sp, dateUtil, injector) hardLimits = HardLimits(aapsLogger, rxBus, sp, rh, context, repository) - objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, rh, activePlugin, sp, ConfigImpl(), dateUtil, uel) + objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, rh, activePlugin, sp, config, dateUtil, uel) comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, rh, profileFunction, sp, commandQueue, context, pumpSync, dateUtil) danaRPlugin = DanaRPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, rh, constraintChecker, activePlugin, sp, commandQueue, danaPump, dateUtil, fabricPrivacy, pumpSync) danaRSPlugin = DanaRSPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, rh, constraintChecker, profileFunction, sp, commandQueue, danaPump, pumpSync, detailedBolusInfoStorage, temporaryBasalStorage, fabricPrivacy, dateUtil) - insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, rh, sp, commandQueue, profileFunction, context, ConfigImpl(), dateUtil, insightDbHelper, pumpSync) + insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, rh, sp, commandQueue, profileFunction, context, config, dateUtil, insightDbHelper, pumpSync) openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, rh, profileFunction, context, activePlugin, iobCobCalculator, hardLimits, profiler, sp, dateUtil, repository, glucoseStatusProvider) openAPSAMAPlugin = OpenAPSAMAPlugin(injector, aapsLogger, rxBus, constraintChecker, rh, profileFunction, context, activePlugin, iobCobCalculator, hardLimits, profiler, fabricPrivacy, dateUtil, repository, glucoseStatusProvider) - safetyPlugin = SafetyPlugin(injector, aapsLogger, rh, sp, rxBus, constraintChecker, - openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, - hardLimits, BuildHelperImpl(ConfigImpl(), fileListProvider), iobCobCalculator, - ConfigImpl(), dateUtil) + safetyPlugin = SafetyPlugin(injector, aapsLogger, rh, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, BuildHelperImpl(config, fileListProvider), iobCobCalculator, config, dateUtil) val constraintsPluginsList = ArrayList() constraintsPluginsList.add(safetyPlugin) constraintsPluginsList.add(objectivesPlugin) @@ -249,7 +245,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { // Apply all limits val d = constraintChecker.getMaxBasalAllowed(validProfile) Assert.assertEquals(0.8, d.value(), 0.01) - Assert.assertEquals(6, d.reasonList.size) + Assert.assertEquals(3, d.reasonList.size) Assert.assertEquals("DanaR: Limiting max basal rate to 0.80 U/h because of pump limit", d.getMostLimitedReasons(aapsLogger)) } @@ -275,9 +271,9 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { // Apply all limits val i = constraintChecker.getMaxBasalPercentAllowed(validProfile) - Assert.assertEquals(100, i.value()) - Assert.assertEquals(9, i.reasonList.size) // 7x Safety & RS & R - Assert.assertEquals("Safety: Limiting max percent rate to 100% because of pump limit", i.getMostLimitedReasons(aapsLogger)) + Assert.assertEquals(200, i.value()) + Assert.assertEquals(6, i.reasonList.size) + Assert.assertEquals("Safety: Limiting max percent rate to 200% because of pump limit", i.getMostLimitedReasons(aapsLogger)) } // applyBolusConstraints tests diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt index 50f7692b8d..e613a040c0 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt @@ -16,7 +16,6 @@ import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.receivers.ReceiverStatusStore import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert @@ -44,13 +43,15 @@ class LoopPluginTest : TestBase() { @Mock lateinit var uel:UserEntryLogger @Mock lateinit var dateUtil: DateUtil @Mock lateinit var runningConfiguration: RunningConfiguration + @Mock lateinit var config: Config private lateinit var loopPlugin: LoopPlugin val injector = HasAndroidInjector { AndroidInjector { } } @Before fun prepareMock() { - loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, ConfigImpl(), constraintChecker, rh, profileFunction, context, commandQueue, activePlugin, virtualPumpPlugin, iobCobCalculator, receiverStatusStore, fabricPrivacy, dateUtil, uel, repository, runningConfiguration) + loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, config, + constraintChecker, rh, profileFunction, context, commandQueue, activePlugin, virtualPumpPlugin, iobCobCalculator, receiverStatusStore, fabricPrivacy, dateUtil, uel, repository, runningConfiguration) `when`(activePlugin.activePump).thenReturn(virtualPumpPlugin) `when`(context.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(notificationManager) } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPluginTest.kt index 69a9563dbb..7bf202c94e 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPluginTest.kt @@ -4,7 +4,7 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin +import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -21,7 +21,7 @@ class DstHelperPluginTest : TestBase() { @Mock lateinit var rh: ResourceHelper @Mock lateinit var sp: SP @Mock lateinit var activePlugin: ActivePlugin - @Mock lateinit var loopPlugin: LoopPlugin + @Mock lateinit var loop: Loop private lateinit var plugin: DstHelperPlugin @@ -30,7 +30,7 @@ class DstHelperPluginTest : TestBase() { @Before fun mock() { plugin = DstHelperPlugin(injector, aapsLogger, RxBus(aapsSchedulers, aapsLogger), rh, - sp, activePlugin, loopPlugin) + sp, activePlugin, loop) } @Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt index f8a24417d2..91b0abb662 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt @@ -5,11 +5,11 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert @@ -25,6 +25,7 @@ class ObjectivesPluginTest : TestBase() { @Mock lateinit var sp: SP @Mock lateinit var dateUtil: DateUtil @Mock lateinit var uel: UserEntryLogger + @Mock lateinit var config: Config private lateinit var objectivesPlugin: ObjectivesPlugin @@ -39,7 +40,7 @@ class ObjectivesPluginTest : TestBase() { } @Before fun prepareMock() { - objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, rh, activePlugin, sp, ConfigImpl(), dateUtil, uel) + objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, rh, activePlugin, sp, config, dateUtil, uel) objectivesPlugin.onStart() `when`(rh.gs(R.string.objectivenotstarted, 9)).thenReturn("Objective 9 not started") `when`(rh.gs(R.string.objectivenotstarted, 8)).thenReturn("Objective 8 not started") diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt index 703e3f9567..01a4f20313 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt @@ -17,7 +17,6 @@ import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin import info.nightscout.androidaps.plugins.source.GlimpPlugin import info.nightscout.androidaps.utils.HardLimits import info.nightscout.androidaps.utils.buildHelper.BuildHelper -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before @@ -69,7 +68,9 @@ class SafetyPluginTest : TestBaseWithProfile() { `when`(activePlugin.activePump).thenReturn(virtualPumpPlugin) `when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription) hardLimits = HardLimits(aapsLogger, rxBus, sp, rh, context, repository) - safetyPlugin = SafetyPlugin(injector, aapsLogger, rh, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, buildHelper, iobCobCalculator, ConfigImpl(), dateUtil) + `when`(config.APS).thenReturn(true) + safetyPlugin = SafetyPlugin(injector, aapsLogger, rh, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, buildHelper, + iobCobCalculator, config, dateUtil) } @Test fun pumpDescriptionShouldLimitLoopInvocation() { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt index fbf57cd467..5d3464d400 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt @@ -3,9 +3,9 @@ package info.nightscout.androidaps.plugins.general.maintenance import android.content.Context import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase +import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus import info.nightscout.androidaps.utils.buildHelper.BuildHelper -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert @@ -25,12 +25,13 @@ class MaintenancePluginTest : TestBase() { @Mock lateinit var buildHelper: BuildHelper @Mock lateinit var loggerUtils: LoggerUtils @Mock lateinit var fileListProvider: PrefFileListProvider + @Mock lateinit var config: Config lateinit var sut: MaintenancePlugin @Before fun mock() { - sut = MaintenancePlugin(injector, context, rh, sp, nsSettingsStatus, aapsLogger, buildHelper, ConfigImpl(), fileListProvider, loggerUtils) + sut = MaintenancePlugin(injector, context, rh, sp, nsSettingsStatus, aapsLogger, buildHelper, config, fileListProvider, loggerUtils) `when`(loggerUtils.suffix).thenReturn(".log.zip") `when`(loggerUtils.logDirectory).thenReturn("src/test/res/logger") `when`(fileListProvider.ensureTempDirExists()).thenReturn(File("src/test/res/logger")) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt index d71447e89c..651d71c7d3 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt @@ -30,7 +30,6 @@ import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.XDripBroadcast -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.Single import org.junit.Assert @@ -51,7 +50,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var activePlugin: ActivePlugin @Mock lateinit var commandQueue: CommandQueue - @Mock lateinit var loopPlugin: LoopPlugin + @Mock lateinit var loop: LoopPlugin @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin @Mock lateinit var localProfilePlugin: LocalProfilePlugin @Mock lateinit var otp: OneTimePassword @@ -99,7 +98,9 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { val glucoseStatusProvider = GlucoseStatusProvider(aapsLogger = aapsLogger, iobCobCalculator = iobCobCalculator, dateUtil = dateUtilMocked) smsCommunicatorPlugin = SmsCommunicatorPlugin(injector, aapsLogger, rh, smsManager, aapsSchedulers, sp, constraintChecker, rxBus, profileFunction, fabricPrivacy, activePlugin, commandQueue, - loopPlugin, iobCobCalculator, xDripBroadcast, otp, ConfigImpl(), dateUtilMocked, uel, glucoseStatusProvider, repository) + loop, iobCobCalculator, xDripBroadcast, + otp, config, dateUtilMocked, uel, + glucoseStatusProvider, repository) smsCommunicatorPlugin.setPluginEnabled(PluginType.GENERAL, true) Mockito.doAnswer { invocation: InvocationOnMock -> val callback = invocation.getArgument(1) @@ -298,7 +299,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { `when`(sp.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true) //LOOP STATUS : disabled - `when`(loopPlugin.enabled).thenReturn(false) + `when`(loop.enabled).thenReturn(false) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP STATUS") smsCommunicatorPlugin.processSms(sms) @@ -306,9 +307,9 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.messages[1].text) //LOOP STATUS : suspended - `when`(loopPlugin.minutesToEndOfSuspend()).thenReturn(10) - `when`(loopPlugin.enabled).thenReturn(true) - `when`(loopPlugin.isSuspended).thenReturn(true) + `when`(loop.minutesToEndOfSuspend()).thenReturn(10) + `when`(loop.enabled).thenReturn(true) + `when`(loop.isSuspended).thenReturn(true) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP STATUS") smsCommunicatorPlugin.processSms(sms) @@ -316,8 +317,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("Suspended (10 m)", smsCommunicatorPlugin.messages[1].text) //LOOP STATUS : enabled - `when`(loopPlugin.enabled).thenReturn(true) - `when`(loopPlugin.isSuspended).thenReturn(false) + `when`(loop.enabled).thenReturn(true) + `when`(loop.isSuspended).thenReturn(false) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP STATUS") smsCommunicatorPlugin.processSms(sms) @@ -326,7 +327,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.messages[1].text) //LOOP : wrong format - `when`(loopPlugin.enabled).thenReturn(true) + `when`(loop.enabled).thenReturn(true) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP") smsCommunicatorPlugin.processSms(sms) @@ -335,7 +336,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text) //LOOP DISABLE : already disabled - `when`(loopPlugin.enabled).thenReturn(false) + `when`(loop.enabled).thenReturn(false) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP DISABLE") smsCommunicatorPlugin.processSms(sms) @@ -345,11 +346,11 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { //LOOP DISABLE : from enabled hasBeenRun = false - `when`(loopPlugin.enabled).thenReturn(true) + `when`(loop.enabled).thenReturn(true) // PowerMockito.doAnswer(Answer { // hasBeenRun = true // null - // } as Answer<*>).`when`(loopPlugin).setPluginEnabled(PluginType.LOOP, false) + // } as Answer<*>).`when`(loop).setPluginEnabled(PluginType.LOOP, false) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP DISABLE") smsCommunicatorPlugin.processSms(sms) @@ -363,7 +364,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { //Assert.assertTrue(hasBeenRun) //LOOP ENABLE : already enabled - `when`(loopPlugin.enabled).thenReturn(true) + `when`(loop.enabled).thenReturn(true) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP ENABLE") smsCommunicatorPlugin.processSms(sms) @@ -373,11 +374,11 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { //LOOP ENABLE : from disabled hasBeenRun = false - `when`(loopPlugin.enabled).thenReturn(false) + `when`(loop.enabled).thenReturn(false) // PowerMockito.doAnswer(Answer { // hasBeenRun = true // null - // } as Answer<*>).`when`(loopPlugin).setPluginEnabled(PluginType.LOOP, true) + // } as Answer<*>).`when`(loop).setPluginEnabled(PluginType.LOOP, true) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP ENABLE") smsCommunicatorPlugin.processSms(sms) @@ -467,8 +468,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text) //NSCLIENT RESTART - `when`(loopPlugin.isEnabled()).thenReturn(true) - `when`(loopPlugin.isSuspended).thenReturn(false) + `when`((loop as PluginBase).isEnabled()).thenReturn(true) + `when`(loop.isSuspended).thenReturn(false) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "NSCLIENT RESTART") smsCommunicatorPlugin.processSms(sms) @@ -477,8 +478,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertTrue(smsCommunicatorPlugin.messages[1].text.contains("NSCLIENT RESTART")) //NSCLIENT BLA BLA - `when`(loopPlugin.isEnabled()).thenReturn(true) - `when`(loopPlugin.isSuspended).thenReturn(false) + `when`((loop as PluginBase).isEnabled()).thenReturn(true) + `when`(loop.isSuspended).thenReturn(false) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "NSCLIENT BLA BLA") smsCommunicatorPlugin.processSms(sms) @@ -487,8 +488,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text) //NSCLIENT BLABLA - `when`(loopPlugin.isEnabled()).thenReturn(true) - `when`(loopPlugin.isSuspended).thenReturn(false) + `when`((loop as PluginBase).isEnabled()).thenReturn(true) + `when`(loop.isSuspended).thenReturn(false) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "NSCLIENT BLABLA") smsCommunicatorPlugin.processSms(sms) @@ -524,7 +525,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { repository.runTransactionForResult(anyObject>()) ).thenReturn(Single.just(CancelCurrentOfflineEventIfAnyTransaction.TransactionResult().apply { })) - `when`(loopPlugin.enabled).thenReturn(true) + `when`(loop.enabled).thenReturn(true) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "PUMP CONNECT") smsCommunicatorPlugin.processSms(sms) @@ -871,7 +872,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { passCode = smsCommunicatorPlugin.messageToConfirm?.confirmCode!! smsCommunicatorPlugin.processSms(Sms("1234", passCode)) Assert.assertEquals(passCode, smsCommunicatorPlugin.messages[2].text) - Assert.assertEquals("Extended bolus 1.00U for 20 min started successfully\nnull\nVirtual Pump", smsCommunicatorPlugin.messages[3].text) + Assert.assertEquals("Extended bolus 1.00U for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.messages[3].text) } @Test fun processBolusTest() { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinLyumjevPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinLyumjevPluginTest.kt index 60f77e37c9..b89f0f4339 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinLyumjevPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinLyumjevPluginTest.kt @@ -3,11 +3,11 @@ package info.nightscout.androidaps.plugins.insulin import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R +import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Insulin +import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert.assertEquals import org.junit.Before @@ -30,6 +30,7 @@ class InsulinLyumjevPluginTest { @Mock lateinit var rxBus: RxBus @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var aapsLogger: AAPSLogger + @Mock lateinit var config: Config private var injector: HasAndroidInjector = HasAndroidInjector { AndroidInjector { @@ -38,7 +39,7 @@ class InsulinLyumjevPluginTest { @Before fun setup() { - sut = InsulinLyumjevPlugin(injector, rh, profileFunction, rxBus, aapsLogger, ConfigImpl()) + sut = InsulinLyumjevPlugin(injector, rh, profileFunction, rxBus, aapsLogger, config) } @Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePluginTest.kt index b6be2d882a..747f51fa89 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePluginTest.kt @@ -6,13 +6,13 @@ import info.nightscout.androidaps.Constants import info.nightscout.androidaps.data.Iob import info.nightscout.androidaps.database.entities.Bolus import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Insulin import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.Companion.MIN_DIA import info.nightscout.androidaps.utils.DefaultValueHelper -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.ResourceHelper import org.json.JSONObject import org.junit.Assert @@ -34,9 +34,10 @@ class InsulinOrefBasePluginTest { rh: ResourceHelper, profileFunction: ProfileFunction, rxBus: RxBus, - aapsLogger: AAPSLogger + aapsLogger: AAPSLogger, + config: Config ) : InsulinOrefBasePlugin( - injector, rh, profileFunction, rxBus, aapsLogger, ConfigImpl() + injector, rh, profileFunction, rxBus, aapsLogger, config ) { override fun sendShortDiaNotification(dia: Double) { @@ -67,6 +68,7 @@ class InsulinOrefBasePluginTest { @Mock lateinit var rxBus: RxBus @Mock lateinit var aapsLogger: AAPSLogger @Mock lateinit var activePlugin: ActivePlugin + @Mock lateinit var config: Config private var injector: HasAndroidInjector = HasAndroidInjector { AndroidInjector { @@ -75,7 +77,7 @@ class InsulinOrefBasePluginTest { @Before fun setUp() { - sut = InsulinBaseTest(injector, rh, profileFunction, rxBus, aapsLogger) + sut = InsulinBaseTest(injector, rh, profileFunction, rxBus, aapsLogger, config) } @Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPluginTest.kt index 1b47bb36f2..619655ffd0 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefFreePeakPluginTest.kt @@ -4,10 +4,10 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBase +import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Insulin import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert.assertEquals @@ -30,6 +30,7 @@ class InsulinOrefFreePeakPluginTest : TestBase() { @Mock lateinit var rh: ResourceHelper @Mock lateinit var rxBus: RxBus @Mock lateinit var profileFunction: ProfileFunction + @Mock lateinit var config: Config private var injector: HasAndroidInjector = HasAndroidInjector { AndroidInjector { @@ -38,15 +39,7 @@ class InsulinOrefFreePeakPluginTest : TestBase() { @Before fun setup() { - sut = InsulinOrefFreePeakPlugin( - injector, - sp, - rh, - profileFunction, - rxBus, - aapsLogger, - ConfigImpl() - ) + sut = InsulinOrefFreePeakPlugin( injector, sp, rh, profileFunction, rxBus, aapsLogger, config) } @Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPluginTest.kt index bbbde02c43..6192fb2ebd 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefRapidActingPluginTest.kt @@ -3,11 +3,11 @@ package info.nightscout.androidaps.plugins.insulin import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R +import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Insulin +import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert.assertEquals import org.junit.Before @@ -30,6 +30,7 @@ class InsulinOrefRapidActingPluginTest { @Mock lateinit var rxBus: RxBus @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var aapsLogger: AAPSLogger + @Mock lateinit var config: Config private var injector: HasAndroidInjector = HasAndroidInjector { AndroidInjector { @@ -38,7 +39,7 @@ class InsulinOrefRapidActingPluginTest { @Before fun setup() { - sut = InsulinOrefRapidActingPlugin(injector, rh, profileFunction, rxBus, aapsLogger, ConfigImpl()) + sut = InsulinOrefRapidActingPlugin(injector, rh, profileFunction, rxBus, aapsLogger, config) } @Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPluginTest.kt index c86183e09d..bedddb4aa8 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefUltraRapidActingPluginTest.kt @@ -3,11 +3,11 @@ package info.nightscout.androidaps.plugins.insulin import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R +import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Insulin +import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert.assertEquals import org.junit.Before @@ -30,6 +30,7 @@ class InsulinOrefUltraRapidActingPluginTest { @Mock lateinit var rxBus: RxBus @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var aapsLogger: AAPSLogger + @Mock lateinit var config: Config private var injector: HasAndroidInjector = HasAndroidInjector { AndroidInjector { @@ -38,7 +39,7 @@ class InsulinOrefUltraRapidActingPluginTest { @Before fun setup() { - sut = InsulinOrefUltraRapidActingPlugin(injector, rh, profileFunction, rxBus, aapsLogger, ConfigImpl()) + sut = InsulinOrefUltraRapidActingPlugin(injector, rh, profileFunction, rxBus, aapsLogger, config) } @Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPluginUTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPluginUTest.kt index 3545c1e258..7a5256ffa6 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPluginUTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPluginUTest.kt @@ -4,6 +4,7 @@ import dagger.android.AndroidInjector import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.interfaces.CommandQueue +import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.IobCobCalculator import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.PumpSync @@ -11,7 +12,6 @@ import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert @@ -31,12 +31,13 @@ class VirtualPumpPluginUTest : TestBase() { @Mock lateinit var commandQueue: CommandQueue @Mock lateinit var dateUtil: DateUtil @Mock lateinit var pumpSync: PumpSync + @Mock lateinit var config: Config lateinit var virtualPumpPlugin: VirtualPumpPlugin @Before fun prepareMocks() { - virtualPumpPlugin = VirtualPumpPlugin({ AndroidInjector { } }, aapsLogger, rxBus, fabricPrivacy, rh, aapsSchedulers, sp, profileFunction, iobCobCalculator, commandQueue, pumpSync, ConfigImpl(), dateUtil) + virtualPumpPlugin = VirtualPumpPlugin({ AndroidInjector { } }, aapsLogger, rxBus, fabricPrivacy, rh, aapsSchedulers, sp, profileFunction, iobCobCalculator, commandQueue, pumpSync, config, dateUtil) } @Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/source/NSClientPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/source/NSClientPluginTest.kt index 981c343bff..c2408fad32 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/source/NSClientPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/source/NSClientPluginTest.kt @@ -2,7 +2,7 @@ package info.nightscout.androidaps.plugins.source import dagger.android.AndroidInjector import info.nightscout.androidaps.TestBase -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl +import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert @@ -16,10 +16,11 @@ class NSClientPluginTest : TestBase() { @Mock lateinit var rh: ResourceHelper @Mock lateinit var sp: SP + @Mock lateinit var config: Config @Before fun setup() { - nsClientSourcePlugin = NSClientSourcePlugin({ AndroidInjector { } }, rh, aapsLogger, ConfigImpl()) + nsClientSourcePlugin = NSClientSourcePlugin({ AndroidInjector { } }, rh, aapsLogger, config) } @Test fun advancedFilteringSupported() { diff --git a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueImplementationTest.kt b/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueImplementationTest.kt index 4830daa3c8..48d7e4ded6 100644 --- a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueImplementationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueImplementationTest.kt @@ -26,7 +26,6 @@ import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.buildHelper.BuildHelperImpl -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -106,7 +105,8 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { fun prepare() { commandQueue = CommandQueueMocked(injector, aapsLogger, rxBus, aapsSchedulers, rh, constraintChecker, profileFunction, activePlugin, context, sp, - BuildHelperImpl(ConfigImpl(), fileListProvider), dateUtil, repository, + BuildHelperImpl(config, fileListProvider), dateUtil, + repository, fabricPrivacy, config) testPumpPlugin = TestPumpPlugin(injector) @@ -140,7 +140,8 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { fun commandIsPickedUp() { val commandQueue = CommandQueueImplementation(injector, aapsLogger, rxBus, aapsSchedulers, rh, constraintChecker, profileFunction, activePlugin, context, sp, - BuildHelperImpl(ConfigImpl(), fileListProvider), dateUtil, repository, + BuildHelperImpl(config, fileListProvider), + dateUtil, repository, fabricPrivacy, config) // start with empty queue Assert.assertEquals(0, commandQueue.size()) diff --git a/app/src/test/java/info/nightscout/androidaps/queue/QueueThreadTest.kt b/app/src/test/java/info/nightscout/androidaps/queue/QueueThreadTest.kt index 6281c576a3..8edc20aa4c 100644 --- a/app/src/test/java/info/nightscout/androidaps/queue/QueueThreadTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/queue/QueueThreadTest.kt @@ -17,7 +17,6 @@ import info.nightscout.androidaps.plugins.general.maintenance.PrefFileListProvid import info.nightscout.androidaps.queue.commands.Command import info.nightscout.androidaps.queue.commands.CommandTempBasalAbsolute import info.nightscout.androidaps.utils.buildHelper.BuildHelperImpl -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before @@ -58,7 +57,7 @@ class QueueThreadTest : TestBaseWithProfile() { commandQueue = CommandQueueImplementation( injector, aapsLogger, rxBus, aapsSchedulers, rh, constraintChecker, profileFunction, activePlugin, context, sp, - BuildHelperImpl(ConfigImpl(), fileListProvider), dateUtil, repository, fabricPrivacy, config + BuildHelperImpl(config, fileListProvider), dateUtil, repository, fabricPrivacy, config ) val pumpDescription = PumpDescription() diff --git a/app/src/test/java/info/nightscout/androidaps/utils/wizard/BolusWizardTest.kt b/app/src/test/java/info/nightscout/androidaps/utils/wizard/BolusWizardTest.kt index 3a3c67cdfa..6cec97fb42 100644 --- a/app/src/test/java/info/nightscout/androidaps/utils/wizard/BolusWizardTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/utils/wizard/BolusWizardTest.kt @@ -7,7 +7,6 @@ import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.data.IobTotal import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.Profile -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStore @@ -32,7 +31,7 @@ class BolusWizardTest : TestBase() { @Mock lateinit var context: Context @Mock lateinit var activePlugin: ActivePlugin @Mock lateinit var commandQueue: CommandQueue - @Mock lateinit var loopPlugin: LoopPlugin + @Mock lateinit var loop: Loop @Mock lateinit var iobCobCalculator: IobCobCalculator @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin @Mock lateinit var dateUtil: DateUtil @@ -48,7 +47,7 @@ class BolusWizardTest : TestBase() { it.constraintChecker = constraintChecker it.activePlugin = activePlugin it.commandQueue = commandQueue - it.loopPlugin = loopPlugin + it.loop = loop it.iobCobCalculator = iobCobCalculator it.glucoseStatusProvider = GlucoseStatusProvider(aapsLogger = aapsLogger, iobCobCalculator = iobCobCalculator, dateUtil = dateUtil) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt index a1c568b6a9..ea3f2aa978 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.kt @@ -22,7 +22,7 @@ import javax.inject.Inject class ActionLoopSuspend(injector: HasAndroidInjector) : Action(injector) { - @Inject lateinit var loopPlugin: Loop + @Inject lateinit var loop: Loop @Inject lateinit var rxBus: RxBus @Inject lateinit var uel: UserEntryLogger @@ -33,8 +33,8 @@ class ActionLoopSuspend(injector: HasAndroidInjector) : Action(injector) { @DrawableRes override fun icon(): Int = R.drawable.ic_pause_circle_outline_24dp override fun doAction(callback: Callback) { - if (!loopPlugin.isSuspended) { - loopPlugin.suspendLoop(minutes.getMinutes()) + if (!loop.isSuspended) { + loop.suspendLoop(minutes.getMinutes()) rxBus.send(EventRefreshOverview("ActionLoopSuspend")) uel.log( UserEntry.Action.SUSPEND, Sources.Automation, title + ": " + rh.gs(R.string.suspendloopforXmin, minutes.getMinutes()), diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt index 70f9462ce7..8ae0d90fc6 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt @@ -17,7 +17,8 @@ import org.junit.Before import org.mockito.Mock import org.mockito.Mockito.`when` -open class ActionsTestBase : TestBaseWithProfile() { +open class +ActionsTestBase : TestBaseWithProfile() { open class TestLoopPlugin( aapsLogger: AAPSLogger, @@ -31,16 +32,19 @@ open class ActionsTestBase : TestBaseWithProfile() { private var suspended = false override var lastRun: Loop.LastRun? = Loop.LastRun() override val isSuspended: Boolean = suspended + override val isLGS: Boolean = false + override val isSuperBolus: Boolean = false + override val isDisconnected: Boolean = false override var enabled: Boolean get() = true set(_) {} + override fun invoke(initiator: String, allowNotification: Boolean, tempBasalFallback: Boolean) {} + override fun acceptChangeRequest() {} override fun minutesToEndOfSuspend(): Int = 0 - - override fun goToZeroTemp(durationInMinutes: Int, profile: Profile, reason: OfflineEvent.Reason) { - } - + override fun goToZeroTemp(durationInMinutes: Int, profile: Profile, reason: OfflineEvent.Reason) {} override fun suspendLoop(durationInMinutes: Int) {} + override fun disableCarbSuggestions(durationMinutes: Int) {} } @Mock lateinit var sp: SP @@ -99,7 +103,7 @@ open class ActionsTestBase : TestBaseWithProfile() { } if (it is ActionLoopSuspend) { it.aapsLogger = aapsLogger - it.loopPlugin = loopPlugin + it.loop = loopPlugin it.rh = rh it.rxBus = rxBus it.uel = uel diff --git a/core/src/main/java/info/nightscout/androidaps/extensions/DeviceStatusExtension.kt b/core/src/main/java/info/nightscout/androidaps/extensions/DeviceStatusExtension.kt index 46aca076d5..b51883a639 100644 --- a/core/src/main/java/info/nightscout/androidaps/extensions/DeviceStatusExtension.kt +++ b/core/src/main/java/info/nightscout/androidaps/extensions/DeviceStatusExtension.kt @@ -28,7 +28,7 @@ fun DeviceStatus.toJson(dateUtil: DateUtil): JSONObject = fun buildDeviceStatus( dateUtil: DateUtil, - loopPlugin: Loop, + loop: Loop, iobCobCalculatorPlugin: IobCobCalculator, profileFunction: ProfileFunction, pump: Pump, @@ -39,7 +39,7 @@ fun buildDeviceStatus( val profile = profileFunction.getProfile() ?: return null val profileName = profileFunction.getProfileName() - val lastRun = loopPlugin.lastRun + val lastRun = loop.lastRun var apsResult: JSONObject? = null var iob: JSONObject? = null var enacted: JSONObject? = null diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/Loop.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/Loop.kt index a761e116b0..80e43e7e94 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/Loop.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/Loop.kt @@ -23,9 +23,16 @@ interface Loop { var lastRun: LastRun? val isSuspended: Boolean + val isLGS: Boolean + val isSuperBolus: Boolean + val isDisconnected: Boolean var enabled: Boolean + fun invoke(initiator: String, allowNotification: Boolean, tempBasalFallback: Boolean = false) + + fun acceptChangeRequest() fun minutesToEndOfSuspend(): Int fun goToZeroTemp(durationInMinutes: Int, profile: Profile, reason: OfflineEvent.Reason) fun suspendLoop(durationInMinutes: Int) + fun disableCarbSuggestions(durationMinutes: Int) } \ No newline at end of file