shared-tests #3

This commit is contained in:
Milos Kozak 2023-09-03 18:13:47 +02:00
parent bfb343f92b
commit 24c2f47e84
65 changed files with 377 additions and 283 deletions

View file

@ -1,7 +1,7 @@
package info.nightscout.sharedtests package info.nightscout.sharedtests
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.DetailedBolusInfo
import info.nightscout.interfaces.pump.Pump import info.nightscout.interfaces.pump.Pump

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.annotations package info.nightscout.annotations
/** /**
* This is the actual annotation that makes the class open. Don't use it directly, only through [OpenForTesting] * This is the actual annotation that makes the class open. Don't use it directly, only through [OpenForTesting]

View file

@ -1,6 +1,6 @@
package info.nightscout.rx.bus package info.nightscout.rx.bus
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.events.Event import info.nightscout.rx.events.Event
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger

View file

@ -4,10 +4,10 @@ import android.content.Context
import android.os.Build import android.os.Build
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.collection.LongSparseArray import androidx.collection.LongSparseArray
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.R import info.nightscout.shared.R
import info.nightscout.shared.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.shared.interfaces.ResourceHelper
import org.apache.commons.lang3.time.DateUtils.isSameDay import org.apache.commons.lang3.time.DateUtils.isSameDay
import org.joda.time.DateTime import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat import org.joda.time.format.DateTimeFormat

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.annotations package info.nightscout.annotations
/** /**
* Annotate a class with [OpenForTesting] if it should be extendable for testing. * Annotate a class with [OpenForTesting] if it should be extendable for testing.

View file

@ -1,37 +0,0 @@
package info.nightscout.androidaps
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.logging.AAPSLoggerTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.Mockito
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.jupiter.MockitoSettings
import org.mockito.quality.Strictness
import java.util.Locale
@ExtendWith(MockitoExtension::class)
@MockitoSettings(strictness = Strictness.LENIENT)
open class TestBase {
val aapsLogger = AAPSLoggerTest()
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
@BeforeEach
fun setupLocale() {
Locale.setDefault(Locale.ENGLISH)
System.setProperty("disableFirebase", "true")
}
// Workaround for Kotlin nullability.
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
fun <T> anyObject(): T {
Mockito.any<T>()
return uninitialized()
}
@Suppress("Unchecked_Cast")
fun <T> uninitialized(): T = null as T
}

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.utils.rx package info.nightscout.rx
import io.reactivex.rxjava3.android.plugins.RxAndroidPlugins import io.reactivex.rxjava3.android.plugins.RxAndroidPlugins
import io.reactivex.rxjava3.core.Scheduler import io.reactivex.rxjava3.core.Scheduler

View file

@ -1,14 +1,18 @@
package info.nightscout.rx.weardata package info.nightscout.rx.weardata
import info.nightscout.androidaps.TestBase
import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.ExperimentalSerializationApi
import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.jupiter.MockitoSettings
import org.mockito.quality.Strictness
@ExperimentalSerializationApi @ExperimentalSerializationApi
class EventDataTest : TestBase() { @ExtendWith(MockitoExtension::class)
@MockitoSettings(strictness = Strictness.LENIENT)
class EventDataTest {
@BeforeEach @BeforeEach
fun setUp() { fun setUp() {
@ -147,13 +151,13 @@ class EventDataTest : TestBase() {
EventData.TreatmentData( EventData.TreatmentData(
arrayListOf(EventData.TreatmentData.TempBasal(1, 2.0, 3, 4.0, 5.0)), arrayListOf(EventData.TreatmentData.TempBasal(1, 2.0, 3, 4.0, 5.0)),
arrayListOf(EventData.TreatmentData.Basal(1, 2, 3.0)), arrayListOf(EventData.TreatmentData.Basal(1, 2, 3.0)),
arrayListOf(EventData.TreatmentData.Treatment(1, 2.0, 3.0, true, true)), arrayListOf(EventData.TreatmentData.Treatment(1, 2.0, 3.0, true, isValid = true)),
arrayListOf(EventData.SingleBg(1, sgv = 2.0, high = 3.0, low = 4.0)) arrayListOf(EventData.SingleBg(1, sgv = 2.0, high = 3.0, low = 4.0))
).let { ).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
} }
EventData.Preferences(1, true, true, 2, 3, 4.0, 5.0, 6.0, 7, 8).let { EventData.Preferences(1, wearControl = true, true, 2, 3, 4.0, 5.0, 6.0, 7, 8).let {
Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte()))
Assertions.assertEquals(it, EventData.deserialize(it.serialize())) Assertions.assertEquals(it, EventData.deserialize(it.serialize()))
} }

View file

@ -1,6 +1,6 @@
package info.nightscout.shared package info.nightscout.shared
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
@ -8,105 +8,105 @@ class SafeParseTest {
@Test fun stringToDoubleTest() { @Test fun stringToDoubleTest() {
// correct values // correct values
assertEquals(0.1234, SafeParse.stringToDouble("0.1234"), 0.001) Assertions.assertEquals(0.1234, SafeParse.stringToDouble("0.1234"), 0.001)
assertEquals(0.1234, SafeParse.stringToDouble("0,1234"), 0.001) Assertions.assertEquals(0.1234, SafeParse.stringToDouble("0,1234"), 0.001)
assertEquals(0.5436564812, SafeParse.stringToDouble(".5436564812"), 0.001) Assertions.assertEquals(0.5436564812, SafeParse.stringToDouble(".5436564812"), 0.001)
assertEquals(0.5436564812, SafeParse.stringToDouble(",5436564812"), 0.001) Assertions.assertEquals(0.5436564812, SafeParse.stringToDouble(",5436564812"), 0.001)
assertEquals(1000500100900.0, SafeParse.stringToDouble("1000500100900"), 0.001) Assertions.assertEquals(1000500100900.0, SafeParse.stringToDouble("1000500100900"), 0.001)
assertEquals(42.0, SafeParse.stringToDouble("42"), 0.001) Assertions.assertEquals(42.0, SafeParse.stringToDouble("42"), 0.001)
// units or other extra values are not permitted // units or other extra values are not permitted
assertEquals(0.0, SafeParse.stringToDouble("12 U/h"), 0.001) Assertions.assertEquals(0.0, SafeParse.stringToDouble("12 U/h"), 0.001)
// strings are not parsable // strings are not parsable
assertEquals(0.0, SafeParse.stringToDouble("ala ma kota"), 0.001) Assertions.assertEquals(0.0, SafeParse.stringToDouble("ala ma kota"), 0.001)
// separator errors // separator errors
assertEquals(0.0, SafeParse.stringToDouble("0.1234.5678"), 0.001) Assertions.assertEquals(0.0, SafeParse.stringToDouble("0.1234.5678"), 0.001)
assertEquals(0.0, SafeParse.stringToDouble("0,1234,5678"), 0.001) Assertions.assertEquals(0.0, SafeParse.stringToDouble("0,1234,5678"), 0.001)
// various emptiness // various emptiness
assertEquals(0.0, SafeParse.stringToDouble(""), 0.001) Assertions.assertEquals(0.0, SafeParse.stringToDouble(""), 0.001)
assertEquals(0.0, SafeParse.stringToDouble(" "), 0.001) Assertions.assertEquals(0.0, SafeParse.stringToDouble(" "), 0.001)
assertEquals(0.0, SafeParse.stringToDouble("\n\r"), 0.001) Assertions.assertEquals(0.0, SafeParse.stringToDouble("\n\r"), 0.001)
} }
@Test fun stringToIntTest() { @Test fun stringToIntTest() {
// correct values // correct values
assertEquals(1052934, SafeParse.stringToInt("1052934")) Assertions.assertEquals(1052934, SafeParse.stringToInt("1052934"))
assertEquals(-42, SafeParse.stringToInt("-42")) Assertions.assertEquals(-42, SafeParse.stringToInt("-42"))
assertEquals(2147483647, SafeParse.stringToInt("2147483647")) Assertions.assertEquals(2147483647, SafeParse.stringToInt("2147483647"))
assertEquals(-2147483648, SafeParse.stringToInt("-2147483648")) Assertions.assertEquals(-2147483648, SafeParse.stringToInt("-2147483648"))
// outside Integer range // outside Integer range
assertEquals(0, SafeParse.stringToInt("2147483648")) Assertions.assertEquals(0, SafeParse.stringToInt("2147483648"))
assertEquals(0, SafeParse.stringToInt("-2147483649")) Assertions.assertEquals(0, SafeParse.stringToInt("-2147483649"))
// units or other extra values are not permitted // units or other extra values are not permitted
assertEquals(0, SafeParse.stringToInt("12 U/h")) Assertions.assertEquals(0, SafeParse.stringToInt("12 U/h"))
assertEquals(0, SafeParse.stringToInt("0.1234")) Assertions.assertEquals(0, SafeParse.stringToInt("0.1234"))
assertEquals(0, SafeParse.stringToInt("0,1234")) Assertions.assertEquals(0, SafeParse.stringToInt("0,1234"))
assertEquals(0, SafeParse.stringToInt(".5436564812")) Assertions.assertEquals(0, SafeParse.stringToInt(".5436564812"))
assertEquals(0, SafeParse.stringToInt(",5436564812")) Assertions.assertEquals(0, SafeParse.stringToInt(",5436564812"))
assertEquals(0, SafeParse.stringToInt("42.1234")) Assertions.assertEquals(0, SafeParse.stringToInt("42.1234"))
assertEquals(0, SafeParse.stringToInt("42,1234")) Assertions.assertEquals(0, SafeParse.stringToInt("42,1234"))
assertEquals(0, SafeParse.stringToInt("3212.5436564812")) Assertions.assertEquals(0, SafeParse.stringToInt("3212.5436564812"))
assertEquals(0, SafeParse.stringToInt("3212,5436564812")) Assertions.assertEquals(0, SafeParse.stringToInt("3212,5436564812"))
assertEquals(0, SafeParse.stringToInt("1000500100900")) Assertions.assertEquals(0, SafeParse.stringToInt("1000500100900"))
// strings are not parsable // strings are not parsable
assertEquals(0, SafeParse.stringToInt("ala ma kota")) Assertions.assertEquals(0, SafeParse.stringToInt("ala ma kota"))
// various emptiness // various emptiness
assertEquals(0, SafeParse.stringToInt("")) Assertions.assertEquals(0, SafeParse.stringToInt(""))
assertEquals(0, SafeParse.stringToInt(" ")) Assertions.assertEquals(0, SafeParse.stringToInt(" "))
assertEquals(0, SafeParse.stringToInt("\n\r")) Assertions.assertEquals(0, SafeParse.stringToInt("\n\r"))
} }
@Test fun stringToLongTest() { @Test fun stringToLongTest() {
// correct values // correct values
assertEquals(1052934L, SafeParse.stringToLong("1052934")) Assertions.assertEquals(1052934L, SafeParse.stringToLong("1052934"))
assertEquals(-42L, SafeParse.stringToLong("-42")) Assertions.assertEquals(-42L, SafeParse.stringToLong("-42"))
assertEquals(2147483647L, SafeParse.stringToLong("2147483647")) Assertions.assertEquals(2147483647L, SafeParse.stringToLong("2147483647"))
assertEquals(-2147483648L, SafeParse.stringToLong("-2147483648")) Assertions.assertEquals(-2147483648L, SafeParse.stringToLong("-2147483648"))
assertEquals(1000500100900L, SafeParse.stringToLong("1000500100900")) Assertions.assertEquals(1000500100900L, SafeParse.stringToLong("1000500100900"))
// outside Integer range // outside Integer range
assertEquals(2147483648L, SafeParse.stringToLong("2147483648")) Assertions.assertEquals(2147483648L, SafeParse.stringToLong("2147483648"))
assertEquals(-2147483649L, SafeParse.stringToLong("-2147483649")) Assertions.assertEquals(-2147483649L, SafeParse.stringToLong("-2147483649"))
// units or other extra values are not permitted // units or other extra values are not permitted
assertEquals(0L, SafeParse.stringToLong("12 U/h")) Assertions.assertEquals(0L, SafeParse.stringToLong("12 U/h"))
assertEquals(0L, SafeParse.stringToLong("0.1234")) Assertions.assertEquals(0L, SafeParse.stringToLong("0.1234"))
assertEquals(0L, SafeParse.stringToLong("0,1234")) Assertions.assertEquals(0L, SafeParse.stringToLong("0,1234"))
assertEquals(0L, SafeParse.stringToLong(".5436564812")) Assertions.assertEquals(0L, SafeParse.stringToLong(".5436564812"))
assertEquals(0L, SafeParse.stringToLong(",5436564812")) Assertions.assertEquals(0L, SafeParse.stringToLong(",5436564812"))
assertEquals(0L, SafeParse.stringToLong("42.1234")) Assertions.assertEquals(0L, SafeParse.stringToLong("42.1234"))
assertEquals(0L, SafeParse.stringToLong("42,1234")) Assertions.assertEquals(0L, SafeParse.stringToLong("42,1234"))
assertEquals(0L, SafeParse.stringToLong("3212.5436564812")) Assertions.assertEquals(0L, SafeParse.stringToLong("3212.5436564812"))
assertEquals(0L, SafeParse.stringToLong("3212,5436564812")) Assertions.assertEquals(0L, SafeParse.stringToLong("3212,5436564812"))
// strings are not parsable // strings are not parsable
assertEquals(0L, SafeParse.stringToLong("ala ma kota")) Assertions.assertEquals(0L, SafeParse.stringToLong("ala ma kota"))
// various emptiness // various emptiness
assertEquals(0L, SafeParse.stringToLong("")) Assertions.assertEquals(0L, SafeParse.stringToLong(""))
assertEquals(0L, SafeParse.stringToLong(" ")) Assertions.assertEquals(0L, SafeParse.stringToLong(" "))
assertEquals(0L, SafeParse.stringToLong("\n\r")) Assertions.assertEquals(0L, SafeParse.stringToLong("\n\r"))
} }
@Test @Test
fun stringToDoubleNullTest() { fun stringToDoubleNullTest() {
assertEquals(0.0, SafeParse.stringToDouble(null), 0.001) Assertions.assertEquals(0.0, SafeParse.stringToDouble(null), 0.001)
} }
@Test @Test
fun stringToIntNullTest() { fun stringToIntNullTest() {
assertEquals(0, SafeParse.stringToInt(null)) Assertions.assertEquals(0, SafeParse.stringToInt(null))
} }
@Test @Test
fun stringToLongNullTest() { fun stringToLongNullTest() {
assertEquals(0L, SafeParse.stringToLong(null)) Assertions.assertEquals(0L, SafeParse.stringToLong(null))
} }
} }

View file

@ -1,4 +1,4 @@
allOpen { allOpen {
// allows mocking for classes w/o directly opening them for release builds // allows mocking for classes w/o directly opening them for release builds
annotation 'info.nightscout.androidaps.annotations.OpenForTesting' annotation 'info.nightscout.annotations.OpenForTesting'
} }

View file

@ -1,7 +1,7 @@
package info.nightscout.core.wizard package info.nightscout.core.wizard
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.extensions.valueToUnits import info.nightscout.core.extensions.valueToUnits
import info.nightscout.core.iob.round import info.nightscout.core.iob.round
import info.nightscout.core.utils.MidnightUtils import info.nightscout.core.utils.MidnightUtils
@ -38,9 +38,11 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec
// for mock // for mock
@OpenForTesting @OpenForTesting
class Time { class Time {
fun secondsFromMidnight(): Int = MidnightUtils.secondsFromMidnight() fun secondsFromMidnight(): Int = MidnightUtils.secondsFromMidnight()
} }
var time = Time() var time = Time()
lateinit var storage: JSONObject lateinit var storage: JSONObject
@ -151,7 +153,26 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec
trend = true trend = true
} }
val percentage = if (usePercentage() == DEFAULT) sp.getInt(info.nightscout.core.utils.R.string.key_boluswizard_percentage, 100) else percentage() val percentage = if (usePercentage() == DEFAULT) sp.getInt(info.nightscout.core.utils.R.string.key_boluswizard_percentage, 100) else percentage()
return BolusWizard(injector).doCalc(profile, profileName, tempTarget, carbs(), cob, bg, 0.0, percentage, true, useCOB() == YES, bolusIOB, basalIOB, superBolus, useTempTarget() == YES, trend, false, buttonText(), quickWizard = true) //tbc, ok if only quickwizard, but if other sources elsewhere use Sources.QuickWizard return BolusWizard(injector).doCalc(
profile,
profileName,
tempTarget,
carbs(),
cob,
bg,
0.0,
percentage,
true,
useCOB() == YES,
bolusIOB,
basalIOB,
superBolus,
useTempTarget() == YES,
trend,
false,
buttonText(),
quickWizard = true
) //tbc, ok if only quickwizard, but if other sources elsewhere use Sources.QuickWizard
} }
fun guid(): String = safeGetString(storage, "guid", "") fun guid(): String = safeGetString(storage, "guid", "")

View file

@ -5,7 +5,7 @@ import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.crashlytics.FirebaseCrashlytics import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.ktx.Firebase import com.google.firebase.ktx.Firebase
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.utils.R import info.nightscout.core.utils.R
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag

View file

@ -6,7 +6,7 @@ import androidx.work.Data
import androidx.work.ExistingWorkPolicy import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequest import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager import androidx.work.WorkManager
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import javax.inject.Inject import javax.inject.Inject

View file

@ -1,6 +1,6 @@
package info.nightscout.implementation package info.nightscout.implementation
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.Constants import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.profile.DefaultValueHelper import info.nightscout.interfaces.profile.DefaultValueHelper

View file

@ -1,7 +1,7 @@
package info.nightscout.implementation package info.nightscout.implementation
import android.content.Context import android.content.Context
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.database.impl.transactions.InsertTherapyEventAnnouncementTransaction import info.nightscout.database.impl.transactions.InsertTherapyEventAnnouncementTransaction
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction

View file

@ -1,7 +1,7 @@
package info.nightscout.implementation package info.nightscout.implementation
import dagger.Reusable import dagger.Reusable
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.database.entities.UserEntry import info.nightscout.database.entities.UserEntry
import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry.Action
import info.nightscout.database.entities.UserEntry.Sources import info.nightscout.database.entities.UserEntry.Sources

View file

@ -1,7 +1,7 @@
package info.nightscout.implementation.iob package info.nightscout.implementation.iob
import dagger.Reusable import dagger.Reusable
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.iob.asRounded import info.nightscout.core.iob.asRounded
import info.nightscout.core.iob.log import info.nightscout.core.iob.log
import info.nightscout.interfaces.iob.GlucoseStatus import info.nightscout.interfaces.iob.GlucoseStatus
@ -73,7 +73,6 @@ class GlucoseStatusProviderImpl @Inject constructor(
// // short_deltas are calculated from everything ~5-15 minutes ago // // short_deltas are calculated from everything ~5-15 minutes ago
// } else // } else
if (2.5 < minutesAgo && minutesAgo < 17.5) { if (2.5 < minutesAgo && minutesAgo < 17.5) {
//console.error(minutesAgo, avgDelta);
shortDeltas.add(avgDel) shortDeltas.add(avgDel)
// last_deltas are calculated from everything ~5 minutes ago // last_deltas are calculated from everything ~5 minutes ago
if (2.5 < minutesAgo && minutesAgo < 7.5) { if (2.5 < minutesAgo && minutesAgo < 7.5) {
@ -191,7 +190,7 @@ class GlucoseStatusProviderImpl @Inject constructor(
fun average(array: ArrayList<Double>): Double { fun average(array: ArrayList<Double>): Double {
var sum = 0.0 var sum = 0.0
if (array.size == 0) return 0.0 if (array.isEmpty()) return 0.0
for (value in array) { for (value in array) {
sum += value sum += value
} }

View file

@ -1,7 +1,7 @@
package info.nightscout.implementation.logging package info.nightscout.implementation.logging
import dagger.Reusable import dagger.Reusable
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.logging.LoggerUtils import info.nightscout.interfaces.logging.LoggerUtils
import info.nightscout.interfaces.maintenance.PrefFileListProvider import info.nightscout.interfaces.maintenance.PrefFileListProvider
import javax.inject.Inject import javax.inject.Inject

View file

@ -1,7 +1,7 @@
package info.nightscout.implementation.profiling package info.nightscout.implementation.profiling
import dagger.Reusable import dagger.Reusable
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.profiling.Profiler import info.nightscout.interfaces.profiling.Profiler
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag

View file

@ -2,14 +2,14 @@ package info.nightscout.implementation.pump
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.implementation.R import info.nightscout.implementation.R
import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.DetailedBolusInfo
import info.nightscout.interfaces.pump.DetailedBolusInfoStorage import info.nightscout.interfaces.pump.DetailedBolusInfoStorage
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -39,7 +39,6 @@ class DetailedBolusInfoStorageImpl @Inject constructor(
// Look for info with bolus // Look for info with bolus
for (i in store.indices) { for (i in store.indices) {
val d = store[i] val d = store[i]
//aapsLogger.debug(LTag.PUMP, "Existing bolus info: " + store[i])
if (bolusTime > d.timestamp - T.mins(1).msecs() && bolusTime < d.timestamp + T.mins(1).msecs() && abs(store[i].insulin - bolus) < 0.01) { if (bolusTime > d.timestamp - T.mins(1).msecs() && bolusTime < d.timestamp + T.mins(1).msecs() && abs(store[i].insulin - bolus) < 0.01) {
aapsLogger.debug(LTag.PUMP, "Using & removing bolus info for time $bolusTime: ${store[i]}") aapsLogger.debug(LTag.PUMP, "Using & removing bolus info for time $bolusTime: ${store[i]}")
store.removeAt(i) store.removeAt(i)

View file

@ -1,8 +1,8 @@
package info.nightscout.implementation.pump package info.nightscout.implementation.pump
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.pump.TemporaryBasalStorage
import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.PumpSync
import info.nightscout.interfaces.pump.TemporaryBasalStorage
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T

View file

@ -8,7 +8,7 @@ import android.os.SystemClock
import android.text.Spanned import android.text.Spanned
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.events.EventNewNotification import info.nightscout.core.events.EventNewNotification
import info.nightscout.core.extensions.getCustomizedName import info.nightscout.core.extensions.getCustomizedName
import info.nightscout.core.profile.ProfileSealed import info.nightscout.core.profile.ProfileSealed
@ -319,7 +319,14 @@ class CommandQueueImplementation @Inject constructor(
// not when the Bolus command is starting. The command closes the dialog upon completion). // not when the Bolus command is starting. The command closes the dialog upon completion).
showBolusProgressDialog(detailedBolusInfo) showBolusProgressDialog(detailedBolusInfo)
// Notify Wear about upcoming bolus // Notify Wear about upcoming bolus
rxBus.send(EventMobileToWear(info.nightscout.rx.weardata.EventData.BolusProgress(percent = 0, status = rh.gs(info.nightscout.core.ui.R.string.goingtodeliver, detailedBolusInfo.insulin)))) rxBus.send(
EventMobileToWear(
info.nightscout.rx.weardata.EventData.BolusProgress(
percent = 0,
status = rh.gs(info.nightscout.core.ui.R.string.goingtodeliver, detailedBolusInfo.insulin)
)
)
)
} }
} }
notifyAboutNewCommand() notifyAboutNewCommand()
@ -609,10 +616,7 @@ class CommandQueueImplementation @Inject constructor(
override fun isCustomCommandRunning(customCommandType: Class<out CustomCommand>): Boolean { override fun isCustomCommandRunning(customCommandType: Class<out CustomCommand>): Boolean {
val performing = this.performing val performing = this.performing
if (performing is CommandCustomCommand && customCommandType.isInstance(performing.customCommand)) { return performing is CommandCustomCommand && customCommandType.isInstance(performing.customCommand)
return true
}
return false
} }
@Synchronized @Synchronized

View file

@ -2,7 +2,7 @@ package info.nightscout.implementation.receivers
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.receivers.ReceiverStatusStore import info.nightscout.interfaces.receivers.ReceiverStatusStore
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventChargingState import info.nightscout.rx.events.EventChargingState

View file

@ -13,7 +13,7 @@ import android.os.HandlerThread
import android.os.SystemClock import android.os.SystemClock
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.events.EventNewNotification import info.nightscout.core.events.EventNewNotification
import info.nightscout.core.extensions.convertedToAbsolute import info.nightscout.core.extensions.convertedToAbsolute
import info.nightscout.core.extensions.convertedToPercent import info.nightscout.core.extensions.convertedToPercent
@ -29,9 +29,9 @@ import info.nightscout.database.entities.ValueWithUnit
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.database.impl.transactions.InsertAndCancelCurrentOfflineEventTransaction import info.nightscout.database.impl.transactions.InsertAndCancelCurrentOfflineEventTransaction
import info.nightscout.database.impl.transactions.InsertTherapyEventAnnouncementTransaction import info.nightscout.database.impl.transactions.InsertTherapyEventAnnouncementTransaction
import info.nightscout.interfaces.ApsMode
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.Constants import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.ApsMode
import info.nightscout.interfaces.aps.APSResult import info.nightscout.interfaces.aps.APSResult
import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.aps.Loop.LastRun import info.nightscout.interfaces.aps.Loop.LastRun
@ -327,14 +327,22 @@ class LoopPlugin @Inject constructor(
0 0
) && carbsSuggestionsSuspendedUntil < System.currentTimeMillis() && !treatmentTimeThreshold(-15) ) && carbsSuggestionsSuspendedUntil < System.currentTimeMillis() && !treatmentTimeThreshold(-15)
) { ) {
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_enable_carbs_required_alert_local, true) && !sp.getBoolean(info.nightscout.core.ui.R.string.key_raise_notifications_as_android_notifications, true)) { if (sp.getBoolean(
info.nightscout.core.utils.R.string.key_enable_carbs_required_alert_local,
true
) && !sp.getBoolean(info.nightscout.core.ui.R.string.key_raise_notifications_as_android_notifications, true)
) {
val carbReqLocal = Notification(Notification.CARBS_REQUIRED, resultAfterConstraints.carbsRequiredText, Notification.NORMAL) val carbReqLocal = Notification(Notification.CARBS_REQUIRED, resultAfterConstraints.carbsRequiredText, Notification.NORMAL)
rxBus.send(EventNewNotification(carbReqLocal)) rxBus.send(EventNewNotification(carbReqLocal))
} }
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_create_announcements_from_carbs_req, false)) { if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_create_announcements_from_carbs_req, false)) {
disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(resultAfterConstraints.carbsRequiredText)).subscribe() disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(resultAfterConstraints.carbsRequiredText)).subscribe()
} }
if (sp.getBoolean(info.nightscout.core.utils.R.string.key_enable_carbs_required_alert_local, true) && sp.getBoolean(info.nightscout.core.ui.R.string.key_raise_notifications_as_android_notifications, true)) { if (sp.getBoolean(
info.nightscout.core.utils.R.string.key_enable_carbs_required_alert_local,
true
) && sp.getBoolean(info.nightscout.core.ui.R.string.key_raise_notifications_as_android_notifications, true)
) {
val intentAction5m = Intent(context, CarbSuggestionReceiver::class.java) val intentAction5m = Intent(context, CarbSuggestionReceiver::class.java)
intentAction5m.putExtra("ignoreDuration", 5) intentAction5m.putExtra("ignoreDuration", 5)
val pendingIntent5m = PendingIntent.getBroadcast(context, 1, intentAction5m, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) val pendingIntent5m = PendingIntent.getBroadcast(context, 1, intentAction5m, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)

View file

@ -2,7 +2,7 @@ package info.nightscout.plugins.aps.openAPSAMA
import android.content.Context import android.content.Context
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.extensions.target import info.nightscout.core.extensions.target
import info.nightscout.core.utils.MidnightUtils import info.nightscout.core.utils.MidnightUtils
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
@ -128,10 +128,22 @@ class OpenAPSAMAPlugin @Inject constructor(
val maxIob = constraintChecker.getMaxIOBAllowed().also { maxIOBAllowedConstraint -> val maxIob = constraintChecker.getMaxIOBAllowed().also { maxIOBAllowedConstraint ->
inputConstraints.copyReasons(maxIOBAllowedConstraint) inputConstraints.copyReasons(maxIOBAllowedConstraint)
}.value() }.value()
var minBg = hardLimits.verifyHardLimits(Round.roundTo(profile.getTargetLowMgdl(), 0.1), info.nightscout.core.ui.R.string.profile_low_target, HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]) var minBg =
hardLimits.verifyHardLimits(
Round.roundTo(profile.getTargetLowMgdl(), 0.1),
info.nightscout.core.ui.R.string.profile_low_target,
HardLimits.VERY_HARD_LIMIT_MIN_BG[0],
HardLimits.VERY_HARD_LIMIT_MIN_BG[1]
)
var maxBg = var maxBg =
hardLimits.verifyHardLimits(Round.roundTo(profile.getTargetHighMgdl(), 0.1), info.nightscout.core.ui.R.string.profile_high_target, HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]) hardLimits.verifyHardLimits(
var targetBg = hardLimits.verifyHardLimits(profile.getTargetMgdl(), info.nightscout.core.ui.R.string.temp_target_value, HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]) Round.roundTo(profile.getTargetHighMgdl(), 0.1),
info.nightscout.core.ui.R.string.profile_high_target,
HardLimits.VERY_HARD_LIMIT_MAX_BG[0],
HardLimits.VERY_HARD_LIMIT_MAX_BG[1]
)
var targetBg =
hardLimits.verifyHardLimits(profile.getTargetMgdl(), info.nightscout.core.ui.R.string.temp_target_value, HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1])
var isTempTarget = false var isTempTarget = false
val tempTarget = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet() val tempTarget = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet()
if (tempTarget is ValueWrapper.Existing) { if (tempTarget is ValueWrapper.Existing) {
@ -159,7 +171,13 @@ class OpenAPSAMAPlugin @Inject constructor(
) )
} }
if (!hardLimits.checkHardLimits(profile.dia, info.nightscout.core.ui.R.string.profile_dia, hardLimits.minDia(), hardLimits.maxDia())) return if (!hardLimits.checkHardLimits(profile.dia, info.nightscout.core.ui.R.string.profile_dia, hardLimits.minDia(), hardLimits.maxDia())) return
if (!hardLimits.checkHardLimits(profile.getIcTimeFromMidnight(MidnightUtils.secondsFromMidnight()), info.nightscout.core.ui.R.string.profile_carbs_ratio_value, hardLimits.minIC(), hardLimits.maxIC())) return if (!hardLimits.checkHardLimits(
profile.getIcTimeFromMidnight(MidnightUtils.secondsFromMidnight()),
info.nightscout.core.ui.R.string.profile_carbs_ratio_value,
hardLimits.minIC(),
hardLimits.maxIC()
)
) return
if (!hardLimits.checkHardLimits(profile.getIsfMgdl(), info.nightscout.core.ui.R.string.profile_sensitivity_value, HardLimits.MIN_ISF, HardLimits.MAX_ISF)) return if (!hardLimits.checkHardLimits(profile.getIsfMgdl(), info.nightscout.core.ui.R.string.profile_sensitivity_value, HardLimits.MIN_ISF, HardLimits.MAX_ISF)) return
if (!hardLimits.checkHardLimits(profile.getMaxDailyBasal(), info.nightscout.core.ui.R.string.profile_max_daily_basal_value, 0.02, hardLimits.maxBasal())) return if (!hardLimits.checkHardLimits(profile.getMaxDailyBasal(), info.nightscout.core.ui.R.string.profile_max_daily_basal_value, 0.02, hardLimits.maxBasal())) return
if (!hardLimits.checkHardLimits(pump.baseBasalRate, info.nightscout.core.ui.R.string.current_basal_value, 0.01, hardLimits.maxBasal())) return if (!hardLimits.checkHardLimits(pump.baseBasalRate, info.nightscout.core.ui.R.string.current_basal_value, 0.01, hardLimits.maxBasal())) return
@ -237,7 +255,12 @@ class OpenAPSAMAPlugin @Inject constructor(
// Check percentRate but absolute rate too, because we know real current basal in pump // Check percentRate but absolute rate too, because we know real current basal in pump
val maxBasalMultiplier = sp.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4.0) val maxBasalMultiplier = sp.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4.0)
val maxFromBasalMultiplier = floor(maxBasalMultiplier * profile.getBasal() * 100) / 100 val maxFromBasalMultiplier = floor(maxBasalMultiplier * profile.getBasal() * 100) / 100
absoluteRate.setIfSmaller(aapsLogger, maxFromBasalMultiplier, rh.gs(info.nightscout.core.ui.R.string.limitingbasalratio, maxFromBasalMultiplier, rh.gs(R.string.max_basal_multiplier)), this) absoluteRate.setIfSmaller(
aapsLogger,
maxFromBasalMultiplier,
rh.gs(info.nightscout.core.ui.R.string.limitingbasalratio, maxFromBasalMultiplier, rh.gs(R.string.max_basal_multiplier)),
this
)
val maxBasalFromDaily = sp.getDouble(R.string.key_openapsama_max_daily_safety_multiplier, 3.0) val maxBasalFromDaily = sp.getDouble(R.string.key_openapsama_max_daily_safety_multiplier, 3.0)
val maxFromDaily = floor(profile.getMaxDailyBasal() * maxBasalFromDaily * 100) / 100 val maxFromDaily = floor(profile.getMaxDailyBasal() * maxBasalFromDaily * 100) / 100
absoluteRate.setIfSmaller(aapsLogger, maxFromDaily, rh.gs(info.nightscout.core.ui.R.string.limitingbasalratio, maxFromDaily, rh.gs(R.string.max_daily_basal_multiplier)), this) absoluteRate.setIfSmaller(aapsLogger, maxFromDaily, rh.gs(info.nightscout.core.ui.R.string.limitingbasalratio, maxFromDaily, rh.gs(R.string.max_daily_basal_multiplier)), this)

View file

@ -4,7 +4,6 @@ import android.content.Context
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference import androidx.preference.SwitchPreference
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.core.extensions.target import info.nightscout.core.extensions.target
import info.nightscout.core.utils.MidnightUtils import info.nightscout.core.utils.MidnightUtils
import info.nightscout.database.ValueWrapper import info.nightscout.database.ValueWrapper
@ -40,9 +39,8 @@ import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
import kotlin.math.floor import kotlin.math.floor
@OpenForTesting
@Singleton @Singleton
class OpenAPSSMBPlugin @Inject constructor( open class OpenAPSSMBPlugin @Inject constructor(
injector: HasAndroidInjector, injector: HasAndroidInjector,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
private val rxBus: RxBus, private val rxBus: RxBus,
@ -142,10 +140,22 @@ class OpenAPSSMBPlugin @Inject constructor(
inputConstraints.copyReasons(maxIOBAllowedConstraint) inputConstraints.copyReasons(maxIOBAllowedConstraint)
}.value() }.value()
var minBg = hardLimits.verifyHardLimits(Round.roundTo(profile.getTargetLowMgdl(), 0.1), info.nightscout.core.ui.R.string.profile_low_target, HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]) var minBg =
hardLimits.verifyHardLimits(
Round.roundTo(profile.getTargetLowMgdl(), 0.1),
info.nightscout.core.ui.R.string.profile_low_target,
HardLimits.VERY_HARD_LIMIT_MIN_BG[0],
HardLimits.VERY_HARD_LIMIT_MIN_BG[1]
)
var maxBg = var maxBg =
hardLimits.verifyHardLimits(Round.roundTo(profile.getTargetHighMgdl(), 0.1), info.nightscout.core.ui.R.string.profile_high_target, HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]) hardLimits.verifyHardLimits(
var targetBg = hardLimits.verifyHardLimits(profile.getTargetMgdl(), info.nightscout.core.ui.R.string.temp_target_value, HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]) Round.roundTo(profile.getTargetHighMgdl(), 0.1),
info.nightscout.core.ui.R.string.profile_high_target,
HardLimits.VERY_HARD_LIMIT_MAX_BG[0],
HardLimits.VERY_HARD_LIMIT_MAX_BG[1]
)
var targetBg =
hardLimits.verifyHardLimits(profile.getTargetMgdl(), info.nightscout.core.ui.R.string.temp_target_value, HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1])
var isTempTarget = false var isTempTarget = false
val tempTarget = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet() val tempTarget = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet()
if (tempTarget is ValueWrapper.Existing) { if (tempTarget is ValueWrapper.Existing) {
@ -173,7 +183,13 @@ class OpenAPSSMBPlugin @Inject constructor(
) )
} }
if (!hardLimits.checkHardLimits(profile.dia, info.nightscout.core.ui.R.string.profile_dia, hardLimits.minDia(), hardLimits.maxDia())) return if (!hardLimits.checkHardLimits(profile.dia, info.nightscout.core.ui.R.string.profile_dia, hardLimits.minDia(), hardLimits.maxDia())) return
if (!hardLimits.checkHardLimits(profile.getIcTimeFromMidnight(MidnightUtils.secondsFromMidnight()), info.nightscout.core.ui.R.string.profile_carbs_ratio_value, hardLimits.minIC(), hardLimits.maxIC())) return if (!hardLimits.checkHardLimits(
profile.getIcTimeFromMidnight(MidnightUtils.secondsFromMidnight()),
info.nightscout.core.ui.R.string.profile_carbs_ratio_value,
hardLimits.minIC(),
hardLimits.maxIC()
)
) return
if (!hardLimits.checkHardLimits(profile.getIsfMgdl(), info.nightscout.core.ui.R.string.profile_sensitivity_value, HardLimits.MIN_ISF, HardLimits.MAX_ISF)) return if (!hardLimits.checkHardLimits(profile.getIsfMgdl(), info.nightscout.core.ui.R.string.profile_sensitivity_value, HardLimits.MIN_ISF, HardLimits.MAX_ISF)) return
if (!hardLimits.checkHardLimits(profile.getMaxDailyBasal(), info.nightscout.core.ui.R.string.profile_max_daily_basal_value, 0.02, hardLimits.maxBasal())) return if (!hardLimits.checkHardLimits(profile.getMaxDailyBasal(), info.nightscout.core.ui.R.string.profile_max_daily_basal_value, 0.02, hardLimits.maxBasal())) return
if (!hardLimits.checkHardLimits(pump.baseBasalRate, info.nightscout.core.ui.R.string.current_basal_value, 0.01, hardLimits.maxBasal())) return if (!hardLimits.checkHardLimits(pump.baseBasalRate, info.nightscout.core.ui.R.string.current_basal_value, 0.01, hardLimits.maxBasal())) return
@ -290,7 +306,12 @@ class OpenAPSSMBPlugin @Inject constructor(
// Check percentRate but absolute rate too, because we know real current basal in pump // Check percentRate but absolute rate too, because we know real current basal in pump
val maxBasalMultiplier = sp.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4.0) val maxBasalMultiplier = sp.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4.0)
val maxFromBasalMultiplier = floor(maxBasalMultiplier * profile.getBasal() * 100) / 100 val maxFromBasalMultiplier = floor(maxBasalMultiplier * profile.getBasal() * 100) / 100
absoluteRate.setIfSmaller(aapsLogger, maxFromBasalMultiplier, rh.gs(info.nightscout.core.ui.R.string.limitingbasalratio, maxFromBasalMultiplier, rh.gs(R.string.max_basal_multiplier)), this) absoluteRate.setIfSmaller(
aapsLogger,
maxFromBasalMultiplier,
rh.gs(info.nightscout.core.ui.R.string.limitingbasalratio, maxFromBasalMultiplier, rh.gs(R.string.max_basal_multiplier)),
this
)
val maxBasalFromDaily = sp.getDouble(R.string.key_openapsama_max_daily_safety_multiplier, 3.0) val maxBasalFromDaily = sp.getDouble(R.string.key_openapsama_max_daily_safety_multiplier, 3.0)
val maxFromDaily = floor(profile.getMaxDailyBasal() * maxBasalFromDaily * 100) / 100 val maxFromDaily = floor(profile.getMaxDailyBasal() * maxBasalFromDaily * 100) / 100
absoluteRate.setIfSmaller(aapsLogger, maxFromDaily, rh.gs(info.nightscout.core.ui.R.string.limitingbasalratio, maxFromDaily, rh.gs(R.string.max_daily_basal_multiplier)), this) absoluteRate.setIfSmaller(aapsLogger, maxFromDaily, rh.gs(info.nightscout.core.ui.R.string.limitingbasalratio, maxFromDaily, rh.gs(R.string.max_daily_basal_multiplier)), this)
@ -316,5 +337,5 @@ class OpenAPSSMBPlugin @Inject constructor(
return value return value
} }
fun provideDetermineBasalAdapter(): DetermineBasalAdapter = DetermineBasalAdapterSMBJS(ScriptReader(context), injector) open fun provideDetermineBasalAdapter(): DetermineBasalAdapter = DetermineBasalAdapterSMBJS(ScriptReader(context), injector)
} }

View file

@ -2,7 +2,7 @@ package info.nightscout.plugins.aps.openAPSSMBDynamicISF
import android.content.Context import android.content.Context
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.interfaces.aps.DetermineBasalAdapter import info.nightscout.interfaces.aps.DetermineBasalAdapter
import info.nightscout.interfaces.bgQualityCheck.BgQualityCheck import info.nightscout.interfaces.bgQualityCheck.BgQualityCheck

View file

@ -1,6 +1,6 @@
package info.nightscout.plugins.general.autotune package info.nightscout.plugins.general.autotune
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.logging.LoggerUtils import info.nightscout.interfaces.logging.LoggerUtils
import info.nightscout.plugins.general.autotune.data.ATProfile import info.nightscout.plugins.general.autotune.data.ATProfile
import info.nightscout.plugins.general.autotune.data.PreppedGlucose import info.nightscout.plugins.general.autotune.data.PreppedGlucose

View file

@ -5,7 +5,7 @@ import android.os.Handler
import android.os.HandlerThread import android.os.HandlerThread
import android.os.SystemClock import android.os.SystemClock
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.automation.actions.Action import info.nightscout.automation.actions.Action
import info.nightscout.automation.actions.ActionAlarm import info.nightscout.automation.actions.ActionAlarm
import info.nightscout.automation.actions.ActionCarePortalEvent import info.nightscout.automation.actions.ActionCarePortalEvent

View file

@ -1,7 +1,7 @@
package info.nightscout.automation.services package info.nightscout.automation.services
import android.location.Location import android.location.Location
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton

View file

@ -5,7 +5,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.ServiceConnection import android.content.ServiceConnection
import android.os.IBinder import android.os.IBinder
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.NotificationHolder import info.nightscout.interfaces.NotificationHolder
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton

View file

@ -3,15 +3,14 @@ package info.nightscout.automation.ui
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.provider.AlarmClock import android.provider.AlarmClock
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.automation.R import info.nightscout.automation.R
import info.nightscout.core.ui.toast.ToastUtils import info.nightscout.core.ui.toast.ToastUtils
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@OpenForTesting @OpenForTesting
@Singleton @Singleton class TimerUtil @Inject constructor(
open class TimerUtil @Inject constructor(
private val context: Context private val context: Context
) { ) {

View file

@ -4,7 +4,7 @@ import android.content.Context
import android.os.Environment import android.os.Environment
import dagger.Lazy import dagger.Lazy
import dagger.Reusable import dagger.Reusable
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.configuration.R import info.nightscout.configuration.R
import info.nightscout.configuration.maintenance.formats.EncryptedPrefsFormat import info.nightscout.configuration.maintenance.formats.EncryptedPrefsFormat
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
@ -42,6 +42,7 @@ class PrefFileListProviderImpl @Inject constructor(
private val sp: SP, private val sp: SP,
context: Context context: Context
) : PrefFileListProvider { ) : PrefFileListProvider {
private val path = File(Environment.getExternalStorageDirectory().toString()) private val path = File(Environment.getExternalStorageDirectory().toString())
private val aapsPath = File(path, "AAPS" + File.separator + "preferences") private val aapsPath = File(path, "AAPS" + File.separator + "preferences")
private val exportsPath = File(path, "AAPS" + File.separator + "exports") private val exportsPath = File(path, "AAPS" + File.separator + "exports")
@ -146,6 +147,7 @@ class PrefFileListProviderImpl @Inject constructor(
val timeLocal = LocalDateTime.now().toString(DateTimeFormat.forPattern("yyyy-MM-dd'_'HHmmss")) val timeLocal = LocalDateTime.now().toString(DateTimeFormat.forPattern("yyyy-MM-dd'_'HHmmss"))
return File(exportsPath, timeLocal + "_UserEntry.csv") return File(exportsPath, timeLocal + "_UserEntry.csv")
} }
override fun newCwfFile(filename: String): File { override fun newCwfFile(filename: String): File {
val timeLocal = LocalDateTime.now().toString(DateTimeFormat.forPattern("yyyy-MM-dd'_'HHmmss")) val timeLocal = LocalDateTime.now().toString(DateTimeFormat.forPattern("yyyy-MM-dd'_'HHmmss"))
return File(exportsPath, "${filename}_$timeLocal${ZipWatchfaceFormat.CWF_EXTENTION}") return File(exportsPath, "${filename}_$timeLocal${ZipWatchfaceFormat.CWF_EXTENTION}")

View file

@ -3,7 +3,7 @@ package info.nightscout.plugins.constraints.storage
import android.os.Environment import android.os.Environment
import android.os.StatFs import android.os.StatFs
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.Constants import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.constraints.Constraints

View file

@ -10,7 +10,7 @@ import androidx.preference.PreferenceFragmentCompat
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import androidx.work.workDataOf import androidx.work.workDataOf
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.events.EventNewNotification import info.nightscout.core.events.EventNewNotification
import info.nightscout.core.extensions.valueToUnitsString import info.nightscout.core.extensions.valueToUnitsString
import info.nightscout.core.iob.generateCOBString import info.nightscout.core.iob.generateCOBString
@ -882,7 +882,11 @@ class SmsCommunicatorPlugin @Inject constructor(
uel.log( uel.log(
Action.EXTENDED_BOLUS, Action.EXTENDED_BOLUS,
Sources.SMS, Sources.SMS,
activePlugin.activePump.shortStatus(true) + "\n" + rh.gs(R.string.smscommunicator_extended_set, aDouble, duration) + " / " + rh.gs(info.nightscout.core.ui.R.string.loopsuspended), activePlugin.activePump.shortStatus(true) + "\n" + rh.gs(
R.string.smscommunicator_extended_set,
aDouble,
duration
) + " / " + rh.gs(info.nightscout.core.ui.R.string.loopsuspended),
ValueWithUnit.Insulin(aDouble ?: 0.0), ValueWithUnit.Insulin(aDouble ?: 0.0),
ValueWithUnit.Minute(duration), ValueWithUnit.Minute(duration),
ValueWithUnit.SimpleString(rh.gsNotLocalised(info.nightscout.core.ui.R.string.loopsuspended)) ValueWithUnit.SimpleString(rh.gsNotLocalised(info.nightscout.core.ui.R.string.loopsuspended))

View file

@ -3,7 +3,7 @@ package info.nightscout.plugins.general.smsCommunicator.otp
import android.util.Base64 import android.util.Base64
import com.eatthepath.otp.HmacOneTimePasswordGenerator import com.eatthepath.otp.HmacOneTimePasswordGenerator
import com.google.common.io.BaseEncoding import com.google.common.io.BaseEncoding
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.Constants import info.nightscout.interfaces.Constants
import info.nightscout.plugins.R import info.nightscout.plugins.R
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
@ -107,7 +107,9 @@ class OneTimePassword @Inject constructor(
* Return URI used to provision Authenticator apps * Return URI used to provision Authenticator apps
*/ */
fun provisioningURI(): String? = fun provisioningURI(): String? =
key?.let { "otpauth://totp/AndroidAPS:" + URLEncoder.encode(name(), "utf-8").replace("+", "%20") + "?secret=" + BaseEncoding.base32().encode(it.encoded).replace("=", "") + "&issuer=AndroidAPS" } key?.let {
"otpauth://totp/AndroidAPS:" + URLEncoder.encode(name(), "utf-8").replace("+", "%20") + "?secret=" + BaseEncoding.base32().encode(it.encoded).replace("=", "") + "&issuer=AndroidAPS"
}
/** /**
* Return secret used to provision Authenticator apps, in Base32 format * Return secret used to provision Authenticator apps, in Base32 format

View file

@ -2,7 +2,7 @@ package info.nightscout.plugins.iob.iobCobCalculator
import androidx.collection.LongSparseArray import androidx.collection.LongSparseArray
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.extensions.convertedToAbsolute import info.nightscout.core.extensions.convertedToAbsolute
import info.nightscout.core.extensions.iobCalc import info.nightscout.core.extensions.iobCalc
import info.nightscout.core.extensions.toTemporaryBasal import info.nightscout.core.extensions.toTemporaryBasal

View file

@ -2,7 +2,7 @@ package info.nightscout.plugins.iob.iobCobCalculator.data
import androidx.collection.LongSparseArray import androidx.collection.LongSparseArray
import androidx.collection.size import androidx.collection.size
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
import info.nightscout.interfaces.aps.AutosensData import info.nightscout.interfaces.aps.AutosensData
import info.nightscout.interfaces.aps.AutosensDataStore import info.nightscout.interfaces.aps.AutosensDataStore
@ -232,7 +232,6 @@ class AutosensDataStoreObject : AutosensDataStore {
// after adjusting time may be newer. In this case use T-5min // after adjusting time may be newer. In this case use T-5min
currentTime = if (adjustedTime > currentTime) adjustedTime - T.mins(5).msecs() else adjustedTime currentTime = if (adjustedTime > currentTime) adjustedTime - T.mins(5).msecs() else adjustedTime
aapsLogger.debug("Adjusted time " + dateUtil.dateAndTimeAndSecondsString(currentTime)) aapsLogger.debug("Adjusted time " + dateUtil.dateAndTimeAndSecondsString(currentTime))
//log.debug("First reading: " + new Date(currentTime).toLocaleString());
while (true) { while (true) {
// test if current value is older than current time // test if current value is older than current time
val newer = findNewer(currentTime) val newer = findNewer(currentTime)
@ -248,7 +247,6 @@ class AutosensDataStoreObject : AutosensDataStore {
val currentBg = newer.value - timeDiffToNew.toDouble() / (newer.timestamp - older.timestamp) * bgDelta val currentBg = newer.value - timeDiffToNew.toDouble() / (newer.timestamp - older.timestamp) * bgDelta
val newBgReading = InMemoryGlucoseValue(currentTime, currentBg.roundToLong().toDouble(), filledGap = filledGap, sourceSensor = lastBg.sourceSensor) val newBgReading = InMemoryGlucoseValue(currentTime, currentBg.roundToLong().toDouble(), filledGap = filledGap, sourceSensor = lastBg.sourceSensor)
newBucketedData.add(newBgReading) newBucketedData.add(newBgReading)
//log.debug("BG: " + newBgReading.value + " (" + new Date(newBgReading.date).toLocaleString() + ") Prev: " + older.value + " (" + new Date(older.date).toLocaleString() + ") Newer: " + newer.value + " (" + new Date(newer.date).toLocaleString() + ")");
} }
currentTime -= T.mins(5).msecs() currentTime -= T.mins(5).msecs()
} }
@ -268,23 +266,19 @@ class AutosensDataStoreObject : AutosensDataStore {
for (i in 1 until bgReadings.size) { for (i in 1 until bgReadings.size) {
val bgTime = bgReadings[i].timestamp val bgTime = bgReadings[i].timestamp
var lastBgTime = bgReadings[i - 1].timestamp var lastBgTime = bgReadings[i - 1].timestamp
//log.error("Processing " + i + ": " + new Date(bgTime).toString() + " " + bgReadings.get(i).value + " Previous: " + new Date(lastBgTime).toString() + " " + bgReadings.get(i - 1).value);
var elapsedMinutes = (bgTime - lastBgTime) / (60 * 1000) var elapsedMinutes = (bgTime - lastBgTime) / (60 * 1000)
when { when {
abs(elapsedMinutes) > 8 -> { abs(elapsedMinutes) > 8 -> {
// interpolate missing data points // interpolate missing data points
var lastBgValue = bgReadings[i - 1].value var lastBgValue = bgReadings[i - 1].value
elapsedMinutes = abs(elapsedMinutes) elapsedMinutes = abs(elapsedMinutes)
//console.error(elapsed_minutes);
var nextBgTime: Long var nextBgTime: Long
while (elapsedMinutes > 5) { while (elapsedMinutes > 5) {
nextBgTime = lastBgTime - 5 * 60 * 1000 nextBgTime = lastBgTime - 5 * 60 * 1000
j++ j++
val gapDelta = bgReadings[i].value - lastBgValue val gapDelta = bgReadings[i].value - lastBgValue
//console.error(gapDelta, lastBg, elapsed_minutes);
val nextBg = lastBgValue + 5.0 / elapsedMinutes * gapDelta val nextBg = lastBgValue + 5.0 / elapsedMinutes * gapDelta
val newBgReading = InMemoryGlucoseValue(nextBgTime, nextBg.roundToLong().toDouble(), filledGap = true, sourceSensor = lastBg.sourceSensor) val newBgReading = InMemoryGlucoseValue(nextBgTime, nextBg.roundToLong().toDouble(), filledGap = true, sourceSensor = lastBg.sourceSensor)
//console.error("Interpolated", bData[j]);
bData.add(newBgReading) bData.add(newBgReading)
aapsLogger.debug(LTag.AUTOSENS) { "Adding. bgTime: ${dateUtil.toISOString(bgTime)} lastBgTime: ${dateUtil.toISOString(lastBgTime)} $newBgReading" } aapsLogger.debug(LTag.AUTOSENS) { "Adding. bgTime: ${dateUtil.toISOString(bgTime)} lastBgTime: ${dateUtil.toISOString(lastBgTime)} $newBgReading" }
elapsedMinutes -= 5 elapsedMinutes -= 5
@ -306,7 +300,6 @@ class AutosensDataStoreObject : AutosensDataStore {
else -> { else -> {
bData[j].value = (bData[j].value + bgReadings[i].value) / 2 bData[j].value = (bData[j].value + bgReadings[i].value) / 2
//log.error("***** Average");
} }
} }
} }

View file

@ -2,7 +2,7 @@ package info.nightscout.plugins.profile
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.extensions.blockFromJsonArray import info.nightscout.core.extensions.blockFromJsonArray
import info.nightscout.core.extensions.pureProfileFromJson import info.nightscout.core.extensions.pureProfileFromJson
import info.nightscout.core.profile.ProfileSealed import info.nightscout.core.profile.ProfileSealed

View file

@ -1,7 +1,7 @@
package info.nightscout.sensitivity package info.nightscout.sensitivity
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.utils.MidnightUtils import info.nightscout.core.utils.MidnightUtils
import info.nightscout.core.utils.Percentile import info.nightscout.core.utils.Percentile
import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.entities.TherapyEvent
@ -162,18 +162,30 @@ class SensitivityAAPSPlugin @Inject constructor(
override fun applyConfiguration(configuration: JSONObject) { override fun applyConfiguration(configuration: JSONObject) {
try { try {
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_absorption_maxtime))) sp.putDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_absorption_maxtime))) sp.putDouble(
info.nightscout.core.utils.R.string.key_absorption_maxtime, configuration.getDouble(rh.gs( info.nightscout.core.utils.R.string.key_absorption_maxtime, configuration.getDouble(
info.nightscout.core.utils.R.string.key_absorption_maxtime))) rh.gs(
info.nightscout.core.utils.R.string.key_absorption_maxtime
)
)
)
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_period))) sp.putDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_period))) sp.putDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_period, info.nightscout.core.utils.R.string.key_openapsama_autosens_period,
configuration.getDouble(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_period)) configuration.getDouble(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_period))
) )
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) sp.getDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) sp.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble(rh.gs( info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) rh.gs(
info.nightscout.core.utils.R.string.key_openapsama_autosens_max
)
)
)
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) sp.getDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) sp.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble(rh.gs( info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) rh.gs(
info.nightscout.core.utils.R.string.key_openapsama_autosens_min
)
)
)
} catch (e: JSONException) { } catch (e: JSONException) {
e.printStackTrace() e.printStackTrace()
} }

View file

@ -1,7 +1,7 @@
package info.nightscout.sensitivity package info.nightscout.sensitivity
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.utils.MidnightUtils import info.nightscout.core.utils.MidnightUtils
import info.nightscout.core.utils.Percentile import info.nightscout.core.utils.Percentile
import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.entities.TherapyEvent
@ -211,7 +211,10 @@ class SensitivityOref1Plugin @Inject constructor(
override fun configuration(): JSONObject { override fun configuration(): JSONObject {
val c = JSONObject() val c = JSONObject()
try { try {
c.put(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact), sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact)) c.put(
rh.gs(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact),
sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact)
)
c.put(rh.gs(info.nightscout.core.utils.R.string.key_absorption_cutoff), sp.getDouble(info.nightscout.core.utils.R.string.key_absorption_cutoff, Constants.DEFAULT_MAX_ABSORPTION_TIME)) c.put(rh.gs(info.nightscout.core.utils.R.string.key_absorption_cutoff), sp.getDouble(info.nightscout.core.utils.R.string.key_absorption_cutoff, Constants.DEFAULT_MAX_ABSORPTION_TIME))
c.put(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_max), sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_autosens_max, 1.2)) c.put(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_max), sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_autosens_max, 1.2))
c.put(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_min), sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_autosens_min, 0.7)) c.put(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_min), sp.getDouble(info.nightscout.core.utils.R.string.key_openapsama_autosens_min, 0.7))
@ -228,14 +231,26 @@ class SensitivityOref1Plugin @Inject constructor(
configuration.getDouble(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact)) configuration.getDouble(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_min_5m_carbimpact))
) )
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_absorption_cutoff))) sp.putDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_absorption_cutoff))) sp.putDouble(
info.nightscout.core.utils.R.string.key_absorption_cutoff, configuration.getDouble(rh.gs( info.nightscout.core.utils.R.string.key_absorption_cutoff, configuration.getDouble(
info.nightscout.core.utils.R.string.key_absorption_cutoff))) rh.gs(
info.nightscout.core.utils.R.string.key_absorption_cutoff
)
)
)
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) sp.getDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) sp.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble(rh.gs( info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) rh.gs(
info.nightscout.core.utils.R.string.key_openapsama_autosens_max
)
)
)
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) sp.getDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) sp.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble(rh.gs( info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) rh.gs(
info.nightscout.core.utils.R.string.key_openapsama_autosens_min
)
)
)
} catch (e: JSONException) { } catch (e: JSONException) {
e.printStackTrace() e.printStackTrace()
} }

View file

@ -2,7 +2,7 @@ package info.nightscout.sensitivity
import androidx.collection.LongSparseArray import androidx.collection.LongSparseArray
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.utils.MidnightUtils import info.nightscout.core.utils.MidnightUtils
import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.entities.TherapyEvent
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
@ -182,18 +182,30 @@ class SensitivityWeightedAveragePlugin @Inject constructor(
override fun applyConfiguration(configuration: JSONObject) { override fun applyConfiguration(configuration: JSONObject) {
try { try {
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_absorption_maxtime))) sp.putDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_absorption_maxtime))) sp.putDouble(
info.nightscout.core.utils.R.string.key_absorption_maxtime, configuration.getDouble(rh.gs( info.nightscout.core.utils.R.string.key_absorption_maxtime, configuration.getDouble(
info.nightscout.core.utils.R.string.key_absorption_maxtime))) rh.gs(
info.nightscout.core.utils.R.string.key_absorption_maxtime
)
)
)
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_period))) sp.putDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_period))) sp.putDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_period, info.nightscout.core.utils.R.string.key_openapsama_autosens_period,
configuration.getDouble(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_period)) configuration.getDouble(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_period))
) )
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) sp.getDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) sp.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble(rh.gs( info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) rh.gs(
info.nightscout.core.utils.R.string.key_openapsama_autosens_max
)
)
)
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) sp.getDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) sp.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble(rh.gs( info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) rh.gs(
info.nightscout.core.utils.R.string.key_openapsama_autosens_min
)
)
)
} catch (e: JSONException) { } catch (e: JSONException) {
e.printStackTrace() e.printStackTrace()
} }

View file

@ -1,7 +1,7 @@
package info.nightscout.smoothing package info.nightscout.smoothing
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
import info.nightscout.interfaces.iob.InMemoryGlucoseValue import info.nightscout.interfaces.iob.InMemoryGlucoseValue
import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginBase
@ -33,8 +33,7 @@ class AvgSmoothingPlugin @Inject constructor(
), Smoothing { ), Smoothing {
override fun smooth(data: MutableList<InMemoryGlucoseValue>): MutableList<InMemoryGlucoseValue> { override fun smooth(data: MutableList<InMemoryGlucoseValue>): MutableList<InMemoryGlucoseValue> {
if (data.lastIndex < 4) if (data.lastIndex < 4) {
{
aapsLogger.debug(LTag.GLUCOSE, "Not enough value's to smooth!") aapsLogger.debug(LTag.GLUCOSE, "Not enough value's to smooth!")
return data return data
} }
@ -60,6 +59,7 @@ class AvgSmoothingPlugin @Inject constructor(
// data[0].smoothed = data[0].value // data[0].smoothed = data[0].value
return data return data
} }
private fun isValid(n: Double): Boolean { private fun isValid(n: Double): Boolean {
// For Dexcom: Below 39 is LOW, above 401 Dexcom just says HI // For Dexcom: Below 39 is LOW, above 401 Dexcom just says HI
return n > 39 && n < 401 return n > 39 && n < 401

View file

@ -1,7 +1,7 @@
package info.nightscout.smoothing package info.nightscout.smoothing
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
import info.nightscout.interfaces.iob.InMemoryGlucoseValue import info.nightscout.interfaces.iob.InMemoryGlucoseValue
import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginBase
@ -123,11 +123,6 @@ class ExponentialSmoothingPlugin @Inject constructor(
// here // here
ssBG.add(o1_weight * o1_sBG[i] + (1 - o1_weight) * o2_sBG[i]) //MP build array of doubly smoothed bgs ssBG.add(o1_weight * o1_sBG[i] + (1 - o1_weight) * o2_sBG[i]) //MP build array of doubly smoothed bgs
} }
/*
for (i in 0 until ssBG.size - 1) {
ssD.add(ssBG[i] - ssBG[i + 1]) //MP build array of doubly smoothed bg deltas
}
*/
for (i in 0 until minOf(ssBG.size, data.size)) { // noise at the beginning of the smoothing window is the greatest, so only include the 10 most recent values in the output for (i in 0 until minOf(ssBG.size, data.size)) { // noise at the beginning of the smoothing window is the greatest, so only include the 10 most recent values in the output
data[i].smoothed = max(round(ssBG[i]), 39.0) //Make 39 the smallest value as smaller values trigger errors (xDrip error state = 38) data[i].smoothed = max(round(ssBG[i]), 39.0) //Make 39 the smallest value as smaller values trigger errors (xDrip error state = 38)
data[i].trendArrow = GlucoseValue.TrendArrow.NONE data[i].trendArrow = GlucoseValue.TrendArrow.NONE

View file

@ -1,7 +1,7 @@
package info.nightscout.smoothing package info.nightscout.smoothing
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.iob.InMemoryGlucoseValue import info.nightscout.interfaces.iob.InMemoryGlucoseValue
import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginDescription

View file

@ -4,7 +4,7 @@ import android.content.Context
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import androidx.work.workDataOf import androidx.work.workDataOf
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.utils.worker.LoggingWorker
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository

View file

@ -1,6 +1,6 @@
package info.nightscout.plugins.sync.nsShared package info.nightscout.plugins.sync.nsShared
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.database.entities.Food import info.nightscout.database.entities.Food
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
import info.nightscout.database.transactions.TransactionGlucoseValue import info.nightscout.database.transactions.TransactionGlucoseValue

View file

@ -1,6 +1,6 @@
package info.nightscout.plugins.sync.nsclient package info.nightscout.plugins.sync.nsclient
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.interfaces.receivers.ReceiverStatusStore import info.nightscout.interfaces.receivers.ReceiverStatusStore
import info.nightscout.plugins.sync.R import info.nightscout.plugins.sync.R

View file

@ -1,6 +1,6 @@
package info.nightscout.plugins.sync.nsclient.data package info.nightscout.plugins.sync.nsclient.data
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.configBuilder.RunningConfiguration import info.nightscout.interfaces.configBuilder.RunningConfiguration
import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData

View file

@ -3,7 +3,7 @@
package info.nightscout.plugins.sync.nsclient.data package info.nightscout.plugins.sync.nsclient.data
import android.content.Context import android.content.Context
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.dialogs.OKDialog
import info.nightscout.database.entities.UserEntry import info.nightscout.database.entities.UserEntry
import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry.Action

View file

@ -1,6 +1,6 @@
package info.nightscout.plugins.sync.nsclientV3 package info.nightscout.plugins.sync.nsclientV3
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.nsclient.StoreDataForDb import info.nightscout.interfaces.nsclient.StoreDataForDb

View file

@ -14,7 +14,7 @@ import androidx.work.WorkManager
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.database.ValueWrapper import info.nightscout.database.ValueWrapper
import info.nightscout.database.entities.interfaces.TraceableDBEntry import info.nightscout.database.entities.interfaces.TraceableDBEntry

View file

@ -2,7 +2,7 @@ package info.nightscout.plugins.sync.nsclientV3.workers
import android.content.Context import android.content.Context
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.utils.worker.LoggingWorker
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.plugins.sync.nsclientV3.DataSyncSelectorV3 import info.nightscout.plugins.sync.nsclientV3.DataSyncSelectorV3

View file

@ -2,7 +2,7 @@ package info.nightscout.plugins.sync.xdrip.workers
import android.content.Context import android.content.Context
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.utils.worker.LoggingWorker
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.plugins.sync.xdrip.DataSyncSelectorXdripImpl import info.nightscout.plugins.sync.xdrip.DataSyncSelectorXdripImpl

View file

@ -1,7 +1,7 @@
package info.nightscout.androidaps package info.nightscout.androidaps
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.DetailedBolusInfo
import info.nightscout.interfaces.pump.Pump import info.nightscout.interfaces.pump.Pump

View file

@ -6,10 +6,10 @@ import android.content.Intent
import android.content.ServiceConnection import android.content.ServiceConnection
import android.os.IBinder import android.os.IBinder
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.androidaps.danaRKorean.services.DanaRKoreanExecutionService import info.nightscout.androidaps.danaRKorean.services.DanaRKoreanExecutionService
import info.nightscout.androidaps.danar.AbstractDanaRPlugin import info.nightscout.androidaps.danar.AbstractDanaRPlugin
import info.nightscout.androidaps.danar.R import info.nightscout.androidaps.danar.R
import info.nightscout.annotations.OpenForTesting
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.constraints.Constraints
@ -130,7 +130,7 @@ class DanaRKoreanPlugin @Inject constructor(
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult {
detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(Constraint(detailedBolusInfo.insulin)).value() detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(Constraint(detailedBolusInfo.insulin)).value()
if (detailedBolusInfo.carbs > 0) throw IllegalArgumentException() require(detailedBolusInfo.carbs > 0)
return if (detailedBolusInfo.insulin > 0) { return if (detailedBolusInfo.insulin > 0) {
val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id) val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id)
var connectionOK = false var connectionOK = false
@ -142,7 +142,14 @@ class DanaRKoreanPlugin @Inject constructor(
val result = PumpEnactResult(injector) val result = PumpEnactResult(injector)
result.success(connectionOK && abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep) result.success(connectionOK && abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep)
.bolusDelivered(t.insulin) .bolusDelivered(t.insulin)
if (!result.success) result.comment(rh.gs(info.nightscout.pump.dana.R.string.boluserrorcode, detailedBolusInfo.insulin, t.insulin, danaPump.bolusStartErrorCode)) else result.comment(info.nightscout.core.ui.R.string.ok) if (!result.success) result.comment(
rh.gs(
info.nightscout.pump.dana.R.string.boluserrorcode,
detailedBolusInfo.insulin,
t.insulin,
danaPump.bolusStartErrorCode
)
) else result.comment(info.nightscout.core.ui.R.string.ok)
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered) aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered)
detailedBolusInfo.insulin = t.insulin detailedBolusInfo.insulin = t.insulin
detailedBolusInfo.timestamp = dateUtil.now() detailedBolusInfo.timestamp = dateUtil.now()

View file

@ -12,10 +12,10 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import dagger.android.HasAndroidInjector; import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.annotations.OpenForTesting;
import info.nightscout.androidaps.danaRv2.services.DanaRv2ExecutionService; import info.nightscout.androidaps.danaRv2.services.DanaRv2ExecutionService;
import info.nightscout.androidaps.danar.AbstractDanaRPlugin; import info.nightscout.androidaps.danar.AbstractDanaRPlugin;
import info.nightscout.androidaps.danar.R; import info.nightscout.androidaps.danar.R;
import info.nightscout.annotations.OpenForTesting;
import info.nightscout.core.utils.fabric.FabricPrivacy; import info.nightscout.core.utils.fabric.FabricPrivacy;
import info.nightscout.interfaces.constraints.Constraint; import info.nightscout.interfaces.constraints.Constraint;
import info.nightscout.interfaces.constraints.Constraints; import info.nightscout.interfaces.constraints.Constraints;
@ -232,8 +232,8 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
int percentRate = (int) (absoluteRate / getBaseBasalRate() * 100); int percentRate = (int) (absoluteRate / getBaseBasalRate() * 100);
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp. // Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp.
if (absoluteRate < 0.10d) percentRate = 0; if (absoluteRate < 0.10d) percentRate = 0;
if (percentRate < 100) percentRate = (int) Round.INSTANCE.ceilTo((double) percentRate, 10d); if (percentRate < 100) percentRate = (int) Round.INSTANCE.ceilTo(percentRate, 10d);
else percentRate = (int) Round.INSTANCE.floorTo((double) percentRate, 10d); else percentRate = (int) Round.INSTANCE.floorTo(percentRate, 10d);
if (percentRate > 500) // Special high temp 500/15min if (percentRate > 500) // Special high temp 500/15min
percentRate = 500; percentRate = 500;
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Calculated percent rate: " + percentRate); aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Calculated percent rate: " + percentRate);

View file

@ -12,8 +12,8 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import dagger.android.HasAndroidInjector; import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.annotations.OpenForTesting;
import info.nightscout.androidaps.danar.services.DanaRExecutionService; import info.nightscout.androidaps.danar.services.DanaRExecutionService;
import info.nightscout.annotations.OpenForTesting;
import info.nightscout.core.utils.fabric.FabricPrivacy; import info.nightscout.core.utils.fabric.FabricPrivacy;
import info.nightscout.interfaces.constraints.Constraint; import info.nightscout.interfaces.constraints.Constraint;
import info.nightscout.interfaces.constraints.Constraints; import info.nightscout.interfaces.constraints.Constraints;

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.pump.medtronic.driver package info.nightscout.androidaps.plugins.pump.medtronic.driver
import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem
@ -9,6 +8,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.BasalProfileStatus
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst
import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.pump.common.data.PumpStatus import info.nightscout.pump.common.data.PumpStatus
import info.nightscout.pump.common.sync.PumpDbEntryTBR import info.nightscout.pump.common.sync.PumpDbEntryTBR

View file

@ -1,10 +1,11 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.util package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.util
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import java.security.SecureRandom import java.security.SecureRandom
@OpenForTesting @OpenForTesting
class RandomByteGenerator { class RandomByteGenerator {
private val secureRandom = SecureRandom() private val secureRandom = SecureRandom()
fun nextBytes(length: Int): ByteArray = ByteArray(length).also(secureRandom::nextBytes) fun nextBytes(length: Int): ByteArray = ByteArray(length).also(secureRandom::nextBytes)

View file

@ -1,7 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.util package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.util
import com.google.crypto.tink.subtle.X25519 import com.google.crypto.tink.subtle.X25519
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
@OpenForTesting @OpenForTesting
class X25519KeyGenerator { class X25519KeyGenerator {

View file

@ -2,7 +2,7 @@ package info.nightscout.pump.common.sync
import com.thoughtworks.xstream.XStream import com.thoughtworks.xstream.XStream
import com.thoughtworks.xstream.security.AnyTypePermission import com.thoughtworks.xstream.security.AnyTypePermission
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.DetailedBolusInfo
import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.PumpSync
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
@ -24,6 +24,7 @@ class PumpSyncStorage @Inject constructor(
) { ) {
companion object { companion object {
const val pumpSyncStorageBolusKey: String = "pump_sync_storage_bolus" const val pumpSyncStorageBolusKey: String = "pump_sync_storage_bolus"
const val pumpSyncStorageTBRKey: String = "pump_sync_storage_tbr" const val pumpSyncStorageTBRKey: String = "pump_sync_storage_tbr"
} }
@ -80,7 +81,7 @@ class PumpSyncStorage @Inject constructor(
} }
fun saveStorageBolus() { fun saveStorageBolus() {
if (!pumpSyncStorageBolus.isEmpty()) { if (pumpSyncStorageBolus.isNotEmpty()) {
sp.putString(pumpSyncStorageBolusKey, xstream.toXML(pumpSyncStorageBolus)) sp.putString(pumpSyncStorageBolusKey, xstream.toXML(pumpSyncStorageBolus))
aapsLogger.debug(LTag.PUMP, "Saving Pump Sync Storage: boluses=${pumpSyncStorageBolus.size}") aapsLogger.debug(LTag.PUMP, "Saving Pump Sync Storage: boluses=${pumpSyncStorageBolus.size}")
} else { } else {
@ -90,7 +91,7 @@ class PumpSyncStorage @Inject constructor(
} }
fun saveStorageTBR() { fun saveStorageTBR() {
if (!pumpSyncStorageTBR.isEmpty()) { if (pumpSyncStorageTBR.isNotEmpty()) {
sp.putString(pumpSyncStorageTBRKey, xstream.toXML(pumpSyncStorageTBR)) sp.putString(pumpSyncStorageTBRKey, xstream.toXML(pumpSyncStorageTBR))
aapsLogger.debug(LTag.PUMP, "Saving Pump Sync Storage: tbr=${pumpSyncStorageTBR.size}") aapsLogger.debug(LTag.PUMP, "Saving Pump Sync Storage: tbr=${pumpSyncStorageTBR.size}")
} else { } else {
@ -124,23 +125,27 @@ class PumpSyncStorage @Inject constructor(
temporaryId, temporaryId,
detailedBolusInfo.bolusType, detailedBolusInfo.bolusType,
creator.model(), creator.model(),
creator.serialNumber()) creator.serialNumber()
)
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, "addBolusWithTempId [date=${detailedBolusInfo.timestamp}, temporaryId=$temporaryId, " + LTag.PUMP, "addBolusWithTempId [date=${detailedBolusInfo.timestamp}, temporaryId=$temporaryId, " +
"insulin=${detailedBolusInfo.insulin}, type=${detailedBolusInfo.bolusType}, pumpSerial=${creator.serialNumber()}] - " + "insulin=${detailedBolusInfo.insulin}, type=${detailedBolusInfo.bolusType}, pumpSerial=${creator.serialNumber()}] - " +
"Result: $result") "Result: $result"
)
if (detailedBolusInfo.carbs > 0.0) { if (detailedBolusInfo.carbs > 0.0) {
addCarbs(PumpDbEntryCarbs(detailedBolusInfo, creator)) addCarbs(PumpDbEntryCarbs(detailedBolusInfo, creator))
} }
if (result && writeToInternalHistory) { if (result && writeToInternalHistory) {
val dbEntry = PumpDbEntryBolus(temporaryId = temporaryId, val dbEntry = PumpDbEntryBolus(
temporaryId = temporaryId,
date = detailedBolusInfo.timestamp, date = detailedBolusInfo.timestamp,
pumpType = creator.model(), pumpType = creator.model(),
serialNumber = creator.serialNumber(), serialNumber = creator.serialNumber(),
detailedBolusInfo = detailedBolusInfo) detailedBolusInfo = detailedBolusInfo
)
aapsLogger.debug("PumpDbEntryBolus: $dbEntry") aapsLogger.debug("PumpDbEntryBolus: $dbEntry")
@ -156,11 +161,13 @@ class PumpSyncStorage @Inject constructor(
carbsDto.carbs, carbsDto.carbs,
null, null,
carbsDto.pumpType, carbsDto.pumpType,
carbsDto.serialNumber) carbsDto.serialNumber
)
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, "syncCarbsWithTimestamp [date=${carbsDto.date}, " + LTag.PUMP, "syncCarbsWithTimestamp [date=${carbsDto.date}, " +
"carbs=${carbsDto.carbs}, pumpSerial=${carbsDto.serialNumber}] - Result: $result") "carbs=${carbsDto.carbs}, pumpSerial=${carbsDto.serialNumber}] - Result: $result"
)
} }
fun addTemporaryBasalRateWithTempId(temporaryBasal: PumpDbEntryTBR, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator): Boolean { fun addTemporaryBasalRateWithTempId(temporaryBasal: PumpDbEntryTBR, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator): Boolean {
@ -175,15 +182,18 @@ class PumpSyncStorage @Inject constructor(
temporaryId, temporaryId,
temporaryBasal.tbrType, temporaryBasal.tbrType,
creator.model(), creator.model(),
creator.serialNumber()) creator.serialNumber()
)
if (response && writeToInternalHistory) { if (response && writeToInternalHistory) {
val dbEntry = PumpDbEntryTBR(temporaryId = temporaryId, val dbEntry = PumpDbEntryTBR(
temporaryId = temporaryId,
date = timeNow, date = timeNow,
pumpType = creator.model(), pumpType = creator.model(),
serialNumber = creator.serialNumber(), serialNumber = creator.serialNumber(),
entry = temporaryBasal, entry = temporaryBasal,
pumpId=null) pumpId = null
)
aapsLogger.debug("PumpDbEntryTBR: $dbEntry") aapsLogger.debug("PumpDbEntryTBR: $dbEntry")

View file

@ -1,6 +1,6 @@
package info.nightscout.androidaps.interaction.utils package info.nightscout.androidaps.interaction.utils
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import info.nightscout.rx.weardata.EventData import info.nightscout.rx.weardata.EventData

View file

@ -2,7 +2,7 @@ package info.nightscout.androidaps.interaction.utils
import android.content.Context import android.content.Context
import android.os.PowerManager import android.os.PowerManager
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.annotations.OpenForTesting
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag

View file

@ -1,8 +1,8 @@
package info.nightscout.androidaps.testing.mockers package info.nightscout.androidaps.testing.mockers
import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.androidaps.interaction.utils.Constants import info.nightscout.androidaps.interaction.utils.Constants
import info.nightscout.androidaps.interaction.utils.WearUtil import info.nightscout.androidaps.interaction.utils.WearUtil
import info.nightscout.annotations.OpenForTesting
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
import org.mockito.Mockito import org.mockito.Mockito