Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ProcessedTbrEbData in Garmin /sgv.json endpoint, resolves #3745 #3785

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import app.aaps.core.data.ue.ValueWithUnit
import app.aaps.core.interfaces.aps.Loop
import app.aaps.core.interfaces.constraints.ConstraintsChecker
import app.aaps.core.interfaces.db.PersistenceLayer
import app.aaps.core.interfaces.db.ProcessedTbrEbData
import app.aaps.core.interfaces.iob.IobCobCalculator
import app.aaps.core.interfaces.logging.AAPSLogger
import app.aaps.core.interfaces.logging.LTag
Expand Down Expand Up @@ -45,7 +46,8 @@ class LoopHubImpl @Inject constructor(
private val profileUtil: ProfileUtil,
private val persistenceLayer: PersistenceLayer,
private val userEntryLogger: UserEntryLogger,
private val preferences: Preferences
private val preferences: Preferences,
private val processedTbrEbData: ProcessedTbrEbData
) : LoopHub {

val disposable = CompositeDisposable()
Expand Down Expand Up @@ -89,8 +91,8 @@ class LoopHubImpl @Inject constructor(
/** Returns the factor by which the basal rate is currently raised (> 1) or lowered (< 1). */
override val temporaryBasal: Double
get() {
val apsResult = loop.lastRun?.constraintsProcessed
return if (apsResult == null) Double.NaN else apsResult.percent / 100.0
val tbr = processedTbrEbData.getTempBasalIncludingConvertedExtended(System.currentTimeMillis())?.rate
return if (tbr == null) Double.NaN else tbr / 100.0
}

override val lowGlucoseMark get() = profileUtil.convertToMgdl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import app.aaps.core.interfaces.aps.Loop
import app.aaps.core.interfaces.constraints.Constraint
import app.aaps.core.interfaces.constraints.ConstraintsChecker
import app.aaps.core.interfaces.db.PersistenceLayer
import app.aaps.core.interfaces.db.ProcessedTbrEbData
import app.aaps.core.interfaces.iob.IobCobCalculator
import app.aaps.core.interfaces.logging.UserEntryLogger
import app.aaps.core.interfaces.profile.Profile
Expand Down Expand Up @@ -63,6 +64,7 @@ class LoopHubTest : TestBase() {
@Mock lateinit var persistenceLayer: PersistenceLayer
@Mock lateinit var userEntryLogger: UserEntryLogger
@Mock lateinit var preferences: Preferences
@Mock lateinit var processedTbrEbData: ProcessedTbrEbData

private lateinit var loopHub: LoopHubImpl
private val clock = Clock.fixed(Instant.ofEpochMilli(10_000), ZoneId.of("UTC"))
Expand All @@ -76,7 +78,7 @@ class LoopHubTest : TestBase() {
}
loopHub = LoopHubImpl(
aapsLogger, commandQueue, constraints, iobCobCalculator, loop,
profileFunction, profileUtil, persistenceLayer, userEntryLogger, preferences
profileFunction, profileUtil, persistenceLayer, userEntryLogger, preferences, processedTbrEbData
)
loopHub.clock = clock
}
Expand Down