diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt index 39e461b388..e38068a115 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt @@ -10,7 +10,6 @@ import androidx.work.WorkQuery import androidx.work.WorkerParameters import androidx.work.workDataOf import com.google.common.util.concurrent.ListenableFuture -import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.R import info.nightscout.configuration.maintenance.MaintenancePlugin import info.nightscout.core.profile.ProfileSealed @@ -19,13 +18,11 @@ import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.Config import info.nightscout.interfaces.LocalAlertUtils import info.nightscout.interfaces.aps.Loop -import info.nightscout.interfaces.configBuilder.RunningConfiguration import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.queue.Command import info.nightscout.interfaces.queue.CommandQueue -import info.nightscout.interfaces.receivers.ReceiverStatusStore import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventProfileSwitchChanged import info.nightscout.rx.logging.LTag @@ -51,8 +48,6 @@ class KeepAliveWorker( @Inject lateinit var dateUtil: DateUtil @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var profileFunction: ProfileFunction - @Inject lateinit var runningConfiguration: RunningConfiguration - @Inject lateinit var receiverStatusStore: ReceiverStatusStore @Inject lateinit var rxBus: RxBus @Inject lateinit var commandQueue: CommandQueue @Inject lateinit var maintenancePlugin: MaintenancePlugin @@ -155,13 +150,7 @@ class KeepAliveWorker( else if (dateUtil.isOlderThan(activePlugin.activeAPS.lastAPSRun, 5)) shouldUploadStatus = true if (dateUtil.isOlderThan(lastIobUpload, IOB_UPDATE_FREQUENCY_IN_MINUTES) && shouldUploadStatus) { lastIobUpload = dateUtil.now() - loop.buildDeviceStatus( - dateUtil, loop, iobCobCalculator, profileFunction, - activePlugin.activePump, receiverStatusStore, runningConfiguration, - BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION - )?.also { - repository.insert(it) - } + loop.buildAndStoreDeviceStatus() } } @@ -193,8 +182,8 @@ class KeepAliveWorker( // do nothing if pump is disconnected } else if (runningProfile == null || ((!pump.isThisProfileSet(requestedProfile) || !requestedProfile.isEqual(runningProfile) || (runningProfile is ProfileSealed.EPS && runningProfile.value.originalEnd < dateUtil.now() && runningProfile.value.originalDuration != 0L)) - && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE))) - { + && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE)) + ) { rxBus.send(EventProfileSwitchChanged()) } else if (isStatusOutdated && !pump.isBusy()) { lastReadStatus = now diff --git a/app/src/test/java/info/nightscout/plugins/aps/loop/LoopPluginTest.kt b/app/src/test/java/info/nightscout/plugins/aps/loop/LoopPluginTest.kt index b6ed18b582..7f74063515 100644 --- a/app/src/test/java/info/nightscout/plugins/aps/loop/LoopPluginTest.kt +++ b/app/src/test/java/info/nightscout/plugins/aps/loop/LoopPluginTest.kt @@ -8,7 +8,7 @@ import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.ApsMode import info.nightscout.interfaces.Config -import info.nightscout.interfaces.configBuilder.RunningConfiguration +import info.nightscout.sdk.interfaces.RunningConfiguration import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.logging.UserEntryLogger diff --git a/core/interfaces/build.gradle b/core/interfaces/build.gradle index ba4be205c3..4cd1087543 100644 --- a/core/interfaces/build.gradle +++ b/core/interfaces/build.gradle @@ -22,7 +22,7 @@ dependencies { // (ResourceHelper, AAPSLogger interface) implementation project(':app-wear-shared:shared') implementation project(':database:entities') - implementation project(':core:ns-sdk') + // implementation project(':core:ns-sdk') api "androidx.appcompat:appcompat:$appcompat_version" diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/aps/Loop.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/aps/Loop.kt index c0eac9f4eb..cc62767c0a 100644 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/aps/Loop.kt +++ b/core/interfaces/src/main/java/info/nightscout/interfaces/aps/Loop.kt @@ -1,16 +1,9 @@ package info.nightscout.interfaces.aps -import info.nightscout.database.entities.DeviceStatus import info.nightscout.database.entities.OfflineEvent -import info.nightscout.interfaces.configBuilder.RunningConfiguration import info.nightscout.interfaces.constraints.Constraint -import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.profile.Profile -import info.nightscout.interfaces.profile.ProfileFunction -import info.nightscout.interfaces.pump.Pump import info.nightscout.interfaces.pump.PumpEnactResult -import info.nightscout.interfaces.receivers.ReceiverStatusStore -import info.nightscout.shared.utils.DateUtil interface Loop { @@ -47,14 +40,5 @@ interface Loop { fun goToZeroTemp(durationInMinutes: Int, profile: Profile, reason: OfflineEvent.Reason) fun suspendLoop(durationInMinutes: Int) fun disableCarbSuggestions(durationMinutes: Int) - fun buildDeviceStatus( - dateUtil: DateUtil, - loop: Loop, - iobCobCalculatorPlugin: IobCobCalculator, - profileFunction: ProfileFunction, - pump: Pump, - receiverStatusStore: ReceiverStatusStore, - runningConfiguration: RunningConfiguration, - version: String - ): DeviceStatus? + fun buildAndStoreDeviceStatus() } \ No newline at end of file diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/configBuilder/RunningConfiguration.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/interfaces/RunningConfiguration.kt similarity index 85% rename from core/interfaces/src/main/java/info/nightscout/interfaces/configBuilder/RunningConfiguration.kt rename to core/ns-sdk/src/main/java/info/nightscout/sdk/interfaces/RunningConfiguration.kt index 9e7ef843ca..cc5600a7d9 100644 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/configBuilder/RunningConfiguration.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/interfaces/RunningConfiguration.kt @@ -1,4 +1,4 @@ -package info.nightscout.interfaces.configBuilder +package info.nightscout.sdk.interfaces import info.nightscout.sdk.localmodel.devicestatus.NSDeviceStatus import org.json.JSONObject diff --git a/plugins/aps/build.gradle b/plugins/aps/build.gradle index 05bda637bf..633891e71c 100644 --- a/plugins/aps/build.gradle +++ b/plugins/aps/build.gradle @@ -20,6 +20,7 @@ dependencies { implementation project(':database:impl') implementation project(':core:main') implementation project(':core:interfaces') + implementation project(':core:ns-sdk') implementation project(':core:utils') implementation project(':core:ui') implementation project(':core:validators') diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt index 50969bf984..660b9b92e1 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt @@ -35,7 +35,6 @@ import info.nightscout.interfaces.Constants import info.nightscout.interfaces.aps.APSResult import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.aps.Loop.LastRun -import info.nightscout.interfaces.configBuilder.RunningConfiguration import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.iob.IobCobCalculator @@ -48,7 +47,6 @@ import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.pump.DetailedBolusInfo -import info.nightscout.interfaces.pump.Pump import info.nightscout.interfaces.pump.PumpEnactResult import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.VirtualPump @@ -72,6 +70,7 @@ import info.nightscout.rx.events.EventTempTargetChange import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.rx.weardata.EventData +import info.nightscout.sdk.interfaces.RunningConfiguration import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.utils.DateUtil @@ -106,7 +105,7 @@ class LoopPlugin @Inject constructor( private val uel: UserEntryLogger, private val repository: AppRepository, private val runningConfiguration: RunningConfiguration, - private val uiInteraction: UiInteraction + private val uiInteraction: UiInteraction, ) : PluginBase( PluginDescription() .mainType(PluginType.LOOP) @@ -300,13 +299,7 @@ class LoopPlugin @Inject constructor( lastRun.lastTBRRequest = 0 lastRun.lastSMBEnact = 0 lastRun.lastSMBRequest = 0 - buildDeviceStatus( - dateUtil, this, iobCobCalculator, profileFunction, - activePlugin.activePump, receiverStatusStore, runningConfiguration, - config.VERSION_NAME + "-" + config.BUILD_VERSION - )?.also { - repository.insert(it) - } + buildAndStoreDeviceStatus() if (isSuspended) { aapsLogger.debug(LTag.APS, rh.gs(info.nightscout.core.ui.R.string.loopsuspended)) @@ -524,13 +517,7 @@ class LoopPlugin @Inject constructor( lastRun.lastTBRRequest = lastRun.lastAPSRun lastRun.lastTBREnact = dateUtil.now() lastRun.lastOpenModeAccept = dateUtil.now() - buildDeviceStatus( - dateUtil, this@LoopPlugin, iobCobCalculator, profileFunction, - activePlugin.activePump, receiverStatusStore, runningConfiguration, - config.VERSION_NAME + "-" + config.BUILD_VERSION - )?.also { - repository.insert(it) - } + buildAndStoreDeviceStatus() sp.incInt(info.nightscout.core.utils.R.string.key_ObjectivesmanualEnacts) } rxBus.send(EventAcceptOpenLoopChange()) @@ -734,20 +721,12 @@ class LoopPlugin @Inject constructor( }) } - override fun buildDeviceStatus( - dateUtil: DateUtil, - loop: Loop, - iobCobCalculatorPlugin: IobCobCalculator, - profileFunction: ProfileFunction, - pump: Pump, - receiverStatusStore: ReceiverStatusStore, - runningConfiguration: RunningConfiguration, - version: String - ): DeviceStatus? { - val profile = profileFunction.getProfile() ?: return null + override fun buildAndStoreDeviceStatus() { + val version = config.VERSION_NAME + "-" + config.BUILD_VERSION + val profile = profileFunction.getProfile() ?: return val profileName = profileFunction.getProfileName() - val lastRun = loop.lastRun + val lastRun = lastRun var apsResult: JSONObject? = null var iob: JSONObject? = null var enacted: JSONObject? = null @@ -774,22 +753,24 @@ class LoopPlugin @Inject constructor( enacted?.put("smb", lastRun.tbrSetByPump?.bolusDelivered) } } else { - val calcIob = iobCobCalculatorPlugin.calculateIobArrayInDia(profile) + val calcIob = iobCobCalculator.calculateIobArrayInDia(profile) if (calcIob.isNotEmpty()) { iob = calcIob[0].json(dateUtil) iob.put("time", dateUtil.toISOString(dateUtil.now())) } } - return DeviceStatus( - timestamp = dateUtil.now(), - suggested = apsResult?.toString(), - iob = iob?.toString(), - enacted = enacted?.toString(), - device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL, - pump = pump.getJSONStatus(profile, profileName, version).toString(), - uploaderBattery = receiverStatusStore.batteryLevel, - isCharging = receiverStatusStore.isCharging, - configuration = runningConfiguration.configuration().toString() + repository.insert( + DeviceStatus( + timestamp = dateUtil.now(), + suggested = apsResult?.toString(), + iob = iob?.toString(), + enacted = enacted?.toString(), + device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL, + pump = activePlugin.activePump.getJSONStatus(profile, profileName, version).toString(), + uploaderBattery = receiverStatusStore.batteryLevel, + isCharging = receiverStatusStore.isCharging, + configuration = runningConfiguration.configuration().toString() + ) ) } diff --git a/plugins/automation/src/test/java/info/nightscout/automation/actions/ActionsTestBase.kt b/plugins/automation/src/test/java/info/nightscout/automation/actions/ActionsTestBase.kt index f1d920435b..f88729ed43 100644 --- a/plugins/automation/src/test/java/info/nightscout/automation/actions/ActionsTestBase.kt +++ b/plugins/automation/src/test/java/info/nightscout/automation/actions/ActionsTestBase.kt @@ -9,7 +9,7 @@ import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.ConfigBuilder import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.aps.Loop -import info.nightscout.interfaces.configBuilder.RunningConfiguration +import info.nightscout.sdk.interfaces.RunningConfiguration import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.logging.UserEntryLogger @@ -69,7 +69,7 @@ ActionsTestBase : TestBaseWithProfile() { profileFunction: ProfileFunction, pump: Pump, receiverStatusStore: ReceiverStatusStore, - runningConfiguration: RunningConfiguration, + runningConfiguration: info.nightscout.sdk.interfaces.RunningConfiguration, version: String ): DeviceStatus? = null diff --git a/plugins/configuration/src/main/java/info/nightscout/configuration/configBuilder/RunningConfigurationImpl.kt b/plugins/configuration/src/main/java/info/nightscout/configuration/configBuilder/RunningConfigurationImpl.kt index 1696e5c6a0..a8f0a5908c 100644 --- a/plugins/configuration/src/main/java/info/nightscout/configuration/configBuilder/RunningConfigurationImpl.kt +++ b/plugins/configuration/src/main/java/info/nightscout/configuration/configBuilder/RunningConfigurationImpl.kt @@ -4,7 +4,7 @@ import info.nightscout.configuration.R import info.nightscout.interfaces.Config import info.nightscout.interfaces.ConfigBuilder import info.nightscout.interfaces.aps.Sensitivity -import info.nightscout.interfaces.configBuilder.RunningConfiguration +import info.nightscout.sdk.interfaces.RunningConfiguration import info.nightscout.interfaces.insulin.Insulin import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.plugin.ActivePlugin diff --git a/plugins/configuration/src/main/java/info/nightscout/configuration/di/ConfigurationModule.kt b/plugins/configuration/src/main/java/info/nightscout/configuration/di/ConfigurationModule.kt index bc85399a39..7825ca1c00 100644 --- a/plugins/configuration/src/main/java/info/nightscout/configuration/di/ConfigurationModule.kt +++ b/plugins/configuration/src/main/java/info/nightscout/configuration/di/ConfigurationModule.kt @@ -17,7 +17,7 @@ import info.nightscout.configuration.maintenance.activities.PrefImportListActivi import info.nightscout.configuration.maintenance.formats.EncryptedPrefsFormat import info.nightscout.interfaces.AndroidPermission import info.nightscout.interfaces.ConfigBuilder -import info.nightscout.interfaces.configBuilder.RunningConfiguration +import info.nightscout.sdk.interfaces.RunningConfiguration import info.nightscout.interfaces.maintenance.ImportExportPrefs import info.nightscout.interfaces.maintenance.PrefFileListProvider diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/NSDeviceStatusHandler.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/NSDeviceStatusHandler.kt index adf88bf940..b62eb70c96 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/NSDeviceStatusHandler.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/NSDeviceStatusHandler.kt @@ -2,7 +2,7 @@ package info.nightscout.plugins.sync.nsclient.data import info.nightscout.annotations.OpenForTesting import info.nightscout.interfaces.Config -import info.nightscout.interfaces.configBuilder.RunningConfiguration +import info.nightscout.sdk.interfaces.RunningConfiguration import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData import info.nightscout.interfaces.utils.HtmlHelper import info.nightscout.interfaces.utils.JsonHelper diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/DeviceStatusExtensionKtTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/DeviceStatusExtensionKtTest.kt index 6f536526f2..9edd9225db 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/DeviceStatusExtensionKtTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/DeviceStatusExtensionKtTest.kt @@ -2,7 +2,7 @@ package info.nightscout.plugins.sync.nsclientV3.extensions import info.nightscout.database.entities.DeviceStatus import info.nightscout.interfaces.Config -import info.nightscout.interfaces.configBuilder.RunningConfiguration +import info.nightscout.sdk.interfaces.RunningConfiguration import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData import info.nightscout.interfaces.profile.Instantiator import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler