break interfaces -> ns-sdk dependency

This commit is contained in:
Milos Kozak 2023-09-18 00:41:34 +02:00
parent 688090fdcc
commit af8f2d8124
12 changed files with 35 additions and 80 deletions

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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()
}

View file

@ -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

View file

@ -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')

View file

@ -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()
)
)
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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