diff --git a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/LoopHubImpl.kt b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/LoopHubImpl.kt index e3b97154af9..345c058230a 100644 --- a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/LoopHubImpl.kt +++ b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/garmin/LoopHubImpl.kt @@ -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 @@ -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() @@ -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( diff --git a/plugins/sync/src/test/kotlin/app/aaps/plugins/sync/garmin/LoopHubTest.kt b/plugins/sync/src/test/kotlin/app/aaps/plugins/sync/garmin/LoopHubTest.kt index d00c1828979..19ed30c958b 100644 --- a/plugins/sync/src/test/kotlin/app/aaps/plugins/sync/garmin/LoopHubTest.kt +++ b/plugins/sync/src/test/kotlin/app/aaps/plugins/sync/garmin/LoopHubTest.kt @@ -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 @@ -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")) @@ -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 }