From 24c2f47e841bd4d7f4031f253e57dfae769b4acd Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 3 Sep 2023 18:13:47 +0200 Subject: [PATCH] shared-tests #3 --- .../nightscout/sharedtests/TestPumpPlugin.kt | 2 +- .../annotations/OpenForTesting.kt | 2 +- .../main/java/info/nightscout/rx/bus/RxBus.kt | 2 +- .../info/nightscout/shared/utils/DateUtil.kt | 8 +- .../annotations/OpenForTesting.kt | 2 +- .../info/nightscout/androidaps/TestBase.kt | 37 ------ .../utils => }/rx/RxSchedulerRule.kt | 2 +- .../nightscout/rx/weardata/EventDataTest.kt | 14 ++- .../info/nightscout/shared/SafeParseTest.kt | 114 +++++++++--------- core/main/allopen_dependencies.gradle | 2 +- .../core/wizard/QuickWizardEntry.kt | 25 +++- .../core/utils/fabric/FabricPrivacy.kt | 2 +- .../core/utils/receivers/DataWorkerStorage.kt | 2 +- .../implementation/DefaultValueHelperImpl.kt | 2 +- .../implementation/HardLimitsImpl.kt | 2 +- .../implementation/UserEntryLoggerImpl.kt | 2 +- .../iob/GlucoseStatusProviderImpl.kt | 5 +- .../implementation/logging/LoggerUtilsImpl.kt | 2 +- .../implementation/profiling/ProfilerImpl.kt | 2 +- .../pump/DetailedBolusInfoStorageImpl.kt | 5 +- .../pump/TemporaryBasalStorageImpl.kt | 4 +- .../queue/CommandQueueImplementation.kt | 16 ++- .../receivers/ReceiverStatusStoreImpl.kt | 2 +- .../nightscout/plugins/aps/loop/LoopPlugin.kt | 16 ++- .../aps/openAPSAMA/OpenAPSAMAPlugin.kt | 35 +++++- .../aps/openAPSSMB/OpenAPSSMBPlugin.kt | 51 +++++--- .../OpenAPSSMBDynamicISFPlugin.kt | 2 +- .../plugins/general/autotune/AutotuneFS.kt | 6 +- .../nightscout/automation/AutomationPlugin.kt | 2 +- .../services/LastLocationDataContainer.kt | 2 +- .../services/LocationServiceHelper.kt | 2 +- .../nightscout/automation/ui/TimerUtil.kt | 5 +- .../maintenance/PrefFileListProviderImpl.kt | 4 +- .../storage/StorageConstraintPlugin.kt | 2 +- .../smsCommunicator/SmsCommunicatorPlugin.kt | 18 +-- .../smsCommunicator/otp/OneTimePassword.kt | 6 +- .../IobCobCalculatorPlugin.kt | 2 +- .../data/AutosensDataStoreObject.kt | 9 +- .../plugins/profile/ProfilePlugin.kt | 20 +-- .../sensitivity/SensitivityAAPSPlugin.kt | 26 ++-- .../sensitivity/SensitivityOref1Plugin.kt | 31 +++-- .../SensitivityWeightedAveragePlugin.kt | 26 ++-- .../smoothing/AvgSmoothingPlugin.kt | 8 +- .../smoothing/ExponentialSmoothingPlugin.kt | 7 +- .../nightscout/smoothing/NoSmoothingPlugin.kt | 2 +- .../info/nightscout/source/GlimpPlugin.kt | 2 +- .../sync/nsShared/NsIncomingDataProcessor.kt | 2 +- .../plugins/sync/nsclient/ReceiverDelegate.kt | 2 +- .../nsclient/data/NSDeviceStatusHandler.kt | 2 +- .../nsclient/data/NSSettingsStatusImpl.kt | 2 +- .../sync/nsclientV3/DataSyncSelectorV3.kt | 2 +- .../sync/nsclientV3/NSClientV3Plugin.kt | 2 +- .../sync/nsclientV3/workers/DataSyncWorker.kt | 2 +- .../sync/xdrip/workers/XdripDataSyncWorker.kt | 2 +- .../nightscout/androidaps/TestPumpPlugin.kt | 2 +- .../danaRKorean/DanaRKoreanPlugin.kt | 29 +++-- .../androidaps/danaRv2/DanaRv2Plugin.java | 6 +- .../androidaps/danar/DanaRPlugin.java | 2 +- .../medtronic/driver/MedtronicPumpStatus.kt | 2 +- .../driver/pod/util/RandomByteGenerator.kt | 3 +- .../driver/pod/util/X25519KeyGenerator.kt | 2 +- .../pump/common/sync/PumpSyncStorage.kt | 50 +++++--- .../interaction/utils/Persistence.kt | 4 +- .../androidaps/interaction/utils/WearUtil.kt | 2 +- .../testing/mockers/WearUtilMocker.kt | 2 +- 65 files changed, 377 insertions(+), 283 deletions(-) rename app-wear-shared/shared/src/debug/java/info/nightscout/{androidaps => }/annotations/OpenForTesting.kt (89%) rename app-wear-shared/shared/src/release/java/info/nightscout/{androidaps => }/annotations/OpenForTesting.kt (80%) delete mode 100644 app-wear-shared/shared/src/test/java/info/nightscout/androidaps/TestBase.kt rename app-wear-shared/shared/src/test/java/info/nightscout/{androidaps/utils => }/rx/RxSchedulerRule.kt (96%) diff --git a/app-wear-shared/shared-tests/src/main/java/info/nightscout/sharedtests/TestPumpPlugin.kt b/app-wear-shared/shared-tests/src/main/java/info/nightscout/sharedtests/TestPumpPlugin.kt index 069b001052..ad064b6342 100644 --- a/app-wear-shared/shared-tests/src/main/java/info/nightscout/sharedtests/TestPumpPlugin.kt +++ b/app-wear-shared/shared-tests/src/main/java/info/nightscout/sharedtests/TestPumpPlugin.kt @@ -1,7 +1,7 @@ package info.nightscout.sharedtests 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.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.Pump diff --git a/app-wear-shared/shared/src/debug/java/info/nightscout/androidaps/annotations/OpenForTesting.kt b/app-wear-shared/shared/src/debug/java/info/nightscout/annotations/OpenForTesting.kt similarity index 89% rename from app-wear-shared/shared/src/debug/java/info/nightscout/androidaps/annotations/OpenForTesting.kt rename to app-wear-shared/shared/src/debug/java/info/nightscout/annotations/OpenForTesting.kt index 47be2222ad..70d2a79124 100644 --- a/app-wear-shared/shared/src/debug/java/info/nightscout/androidaps/annotations/OpenForTesting.kt +++ b/app-wear-shared/shared/src/debug/java/info/nightscout/annotations/OpenForTesting.kt @@ -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] diff --git a/app-wear-shared/shared/src/main/java/info/nightscout/rx/bus/RxBus.kt b/app-wear-shared/shared/src/main/java/info/nightscout/rx/bus/RxBus.kt index e294e9b443..438fad7ed9 100644 --- a/app-wear-shared/shared/src/main/java/info/nightscout/rx/bus/RxBus.kt +++ b/app-wear-shared/shared/src/main/java/info/nightscout/rx/bus/RxBus.kt @@ -1,6 +1,6 @@ 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.events.Event import info.nightscout.rx.logging.AAPSLogger diff --git a/app-wear-shared/shared/src/main/java/info/nightscout/shared/utils/DateUtil.kt b/app-wear-shared/shared/src/main/java/info/nightscout/shared/utils/DateUtil.kt index 27e75a8c2e..361a52b600 100644 --- a/app-wear-shared/shared/src/main/java/info/nightscout/shared/utils/DateUtil.kt +++ b/app-wear-shared/shared/src/main/java/info/nightscout/shared/utils/DateUtil.kt @@ -4,10 +4,10 @@ import android.content.Context import android.os.Build import androidx.annotation.RequiresApi import androidx.collection.LongSparseArray -import info.nightscout.androidaps.annotations.OpenForTesting -import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.annotations.OpenForTesting import info.nightscout.shared.R import info.nightscout.shared.SafeParse +import info.nightscout.shared.interfaces.ResourceHelper import org.apache.commons.lang3.time.DateUtils.isSameDay import org.joda.time.DateTime import org.joda.time.format.DateTimeFormat @@ -119,10 +119,10 @@ class DateUtil @Inject constructor(private val context: Context) { val beginOfToday = beginOfDay(now()) return if (mills < now()) // Past when { - mills > beginOfToday -> rh.gs(R.string.today) + mills > beginOfToday -> rh.gs(R.string.today) mills > beginOfToday - T.days(1).msecs() -> rh.gs(R.string.yesterday) mills > beginOfToday - T.days(7).msecs() -> dayAgo(mills, rh, true) - else -> day + else -> day } else // Future when { diff --git a/app-wear-shared/shared/src/release/java/info/nightscout/androidaps/annotations/OpenForTesting.kt b/app-wear-shared/shared/src/release/java/info/nightscout/annotations/OpenForTesting.kt similarity index 80% rename from app-wear-shared/shared/src/release/java/info/nightscout/androidaps/annotations/OpenForTesting.kt rename to app-wear-shared/shared/src/release/java/info/nightscout/annotations/OpenForTesting.kt index 10911a3e95..4b300365c9 100644 --- a/app-wear-shared/shared/src/release/java/info/nightscout/androidaps/annotations/OpenForTesting.kt +++ b/app-wear-shared/shared/src/release/java/info/nightscout/annotations/OpenForTesting.kt @@ -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. diff --git a/app-wear-shared/shared/src/test/java/info/nightscout/androidaps/TestBase.kt b/app-wear-shared/shared/src/test/java/info/nightscout/androidaps/TestBase.kt deleted file mode 100644 index 4fd2aef548..0000000000 --- a/app-wear-shared/shared/src/test/java/info/nightscout/androidaps/TestBase.kt +++ /dev/null @@ -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 anyObject(): T { - Mockito.any() - return uninitialized() - } - - @Suppress("Unchecked_Cast") - fun uninitialized(): T = null as T -} \ No newline at end of file diff --git a/app-wear-shared/shared/src/test/java/info/nightscout/androidaps/utils/rx/RxSchedulerRule.kt b/app-wear-shared/shared/src/test/java/info/nightscout/rx/RxSchedulerRule.kt similarity index 96% rename from app-wear-shared/shared/src/test/java/info/nightscout/androidaps/utils/rx/RxSchedulerRule.kt rename to app-wear-shared/shared/src/test/java/info/nightscout/rx/RxSchedulerRule.kt index 79abe4692a..1e10a5e6f7 100644 --- a/app-wear-shared/shared/src/test/java/info/nightscout/androidaps/utils/rx/RxSchedulerRule.kt +++ b/app-wear-shared/shared/src/test/java/info/nightscout/rx/RxSchedulerRule.kt @@ -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.core.Scheduler diff --git a/app-wear-shared/shared/src/test/java/info/nightscout/rx/weardata/EventDataTest.kt b/app-wear-shared/shared/src/test/java/info/nightscout/rx/weardata/EventDataTest.kt index bd81d3d5cd..0ff0c07f33 100644 --- a/app-wear-shared/shared/src/test/java/info/nightscout/rx/weardata/EventDataTest.kt +++ b/app-wear-shared/shared/src/test/java/info/nightscout/rx/weardata/EventDataTest.kt @@ -1,14 +1,18 @@ package info.nightscout.rx.weardata -import info.nightscout.androidaps.TestBase import kotlinx.serialization.ExperimentalSerializationApi import org.junit.jupiter.api.Assertions - import org.junit.jupiter.api.BeforeEach 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 -class EventDataTest : TestBase() { +@ExtendWith(MockitoExtension::class) +@MockitoSettings(strictness = Strictness.LENIENT) +class EventDataTest { @BeforeEach fun setUp() { @@ -147,13 +151,13 @@ class EventDataTest : TestBase() { EventData.TreatmentData( arrayListOf(EventData.TreatmentData.TempBasal(1, 2.0, 3, 4.0, 5.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)) ).let { Assertions.assertEquals(it, EventData.deserializeByte(it.serializeByte())) 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.deserialize(it.serialize())) } diff --git a/app-wear-shared/shared/src/test/java/info/nightscout/shared/SafeParseTest.kt b/app-wear-shared/shared/src/test/java/info/nightscout/shared/SafeParseTest.kt index c2f8355ea6..791347e426 100644 --- a/app-wear-shared/shared/src/test/java/info/nightscout/shared/SafeParseTest.kt +++ b/app-wear-shared/shared/src/test/java/info/nightscout/shared/SafeParseTest.kt @@ -1,6 +1,6 @@ package info.nightscout.shared -import org.junit.Assert.assertEquals +import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test @Suppress("SpellCheckingInspection") @@ -8,105 +8,105 @@ class SafeParseTest { @Test fun stringToDoubleTest() { // correct values - assertEquals(0.1234, SafeParse.stringToDouble("0.1234"), 0.001) - assertEquals(0.1234, SafeParse.stringToDouble("0,1234"), 0.001) - assertEquals(0.5436564812, SafeParse.stringToDouble(".5436564812"), 0.001) - assertEquals(0.5436564812, SafeParse.stringToDouble(",5436564812"), 0.001) - assertEquals(1000500100900.0, SafeParse.stringToDouble("1000500100900"), 0.001) - assertEquals(42.0, SafeParse.stringToDouble("42"), 0.001) + Assertions.assertEquals(0.1234, SafeParse.stringToDouble("0.1234"), 0.001) + Assertions.assertEquals(0.1234, SafeParse.stringToDouble("0,1234"), 0.001) + Assertions.assertEquals(0.5436564812, SafeParse.stringToDouble(".5436564812"), 0.001) + Assertions.assertEquals(0.5436564812, SafeParse.stringToDouble(",5436564812"), 0.001) + Assertions.assertEquals(1000500100900.0, SafeParse.stringToDouble("1000500100900"), 0.001) + Assertions.assertEquals(42.0, SafeParse.stringToDouble("42"), 0.001) // 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 - assertEquals(0.0, SafeParse.stringToDouble("ala ma kota"), 0.001) + Assertions.assertEquals(0.0, SafeParse.stringToDouble("ala ma kota"), 0.001) // separator errors - 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) + Assertions.assertEquals(0.0, SafeParse.stringToDouble("0,1234,5678"), 0.001) // various emptiness - assertEquals(0.0, SafeParse.stringToDouble(""), 0.001) - assertEquals(0.0, SafeParse.stringToDouble(" "), 0.001) - assertEquals(0.0, SafeParse.stringToDouble("\n\r"), 0.001) + Assertions.assertEquals(0.0, SafeParse.stringToDouble(""), 0.001) + Assertions.assertEquals(0.0, SafeParse.stringToDouble(" "), 0.001) + Assertions.assertEquals(0.0, SafeParse.stringToDouble("\n\r"), 0.001) } @Test fun stringToIntTest() { // correct values - assertEquals(1052934, SafeParse.stringToInt("1052934")) - assertEquals(-42, SafeParse.stringToInt("-42")) - assertEquals(2147483647, SafeParse.stringToInt("2147483647")) - assertEquals(-2147483648, SafeParse.stringToInt("-2147483648")) + Assertions.assertEquals(1052934, SafeParse.stringToInt("1052934")) + Assertions.assertEquals(-42, SafeParse.stringToInt("-42")) + Assertions.assertEquals(2147483647, SafeParse.stringToInt("2147483647")) + Assertions.assertEquals(-2147483648, SafeParse.stringToInt("-2147483648")) // outside Integer range - assertEquals(0, SafeParse.stringToInt("2147483648")) - assertEquals(0, SafeParse.stringToInt("-2147483649")) + Assertions.assertEquals(0, SafeParse.stringToInt("2147483648")) + Assertions.assertEquals(0, SafeParse.stringToInt("-2147483649")) // units or other extra values are not permitted - assertEquals(0, SafeParse.stringToInt("12 U/h")) - assertEquals(0, SafeParse.stringToInt("0.1234")) - assertEquals(0, SafeParse.stringToInt("0,1234")) - assertEquals(0, SafeParse.stringToInt(".5436564812")) - assertEquals(0, SafeParse.stringToInt(",5436564812")) - assertEquals(0, SafeParse.stringToInt("42.1234")) - assertEquals(0, SafeParse.stringToInt("42,1234")) - assertEquals(0, SafeParse.stringToInt("3212.5436564812")) - assertEquals(0, SafeParse.stringToInt("3212,5436564812")) - assertEquals(0, SafeParse.stringToInt("1000500100900")) + Assertions.assertEquals(0, SafeParse.stringToInt("12 U/h")) + Assertions.assertEquals(0, SafeParse.stringToInt("0.1234")) + Assertions.assertEquals(0, SafeParse.stringToInt("0,1234")) + Assertions.assertEquals(0, SafeParse.stringToInt(".5436564812")) + Assertions.assertEquals(0, SafeParse.stringToInt(",5436564812")) + Assertions.assertEquals(0, SafeParse.stringToInt("42.1234")) + Assertions.assertEquals(0, SafeParse.stringToInt("42,1234")) + Assertions.assertEquals(0, SafeParse.stringToInt("3212.5436564812")) + Assertions.assertEquals(0, SafeParse.stringToInt("3212,5436564812")) + Assertions.assertEquals(0, SafeParse.stringToInt("1000500100900")) // strings are not parsable - assertEquals(0, SafeParse.stringToInt("ala ma kota")) + Assertions.assertEquals(0, SafeParse.stringToInt("ala ma kota")) // various emptiness - assertEquals(0, SafeParse.stringToInt("")) - assertEquals(0, SafeParse.stringToInt(" ")) - assertEquals(0, SafeParse.stringToInt("\n\r")) + Assertions.assertEquals(0, SafeParse.stringToInt("")) + Assertions.assertEquals(0, SafeParse.stringToInt(" ")) + Assertions.assertEquals(0, SafeParse.stringToInt("\n\r")) } @Test fun stringToLongTest() { // correct values - assertEquals(1052934L, SafeParse.stringToLong("1052934")) - assertEquals(-42L, SafeParse.stringToLong("-42")) - assertEquals(2147483647L, SafeParse.stringToLong("2147483647")) - assertEquals(-2147483648L, SafeParse.stringToLong("-2147483648")) - assertEquals(1000500100900L, SafeParse.stringToLong("1000500100900")) + Assertions.assertEquals(1052934L, SafeParse.stringToLong("1052934")) + Assertions.assertEquals(-42L, SafeParse.stringToLong("-42")) + Assertions.assertEquals(2147483647L, SafeParse.stringToLong("2147483647")) + Assertions.assertEquals(-2147483648L, SafeParse.stringToLong("-2147483648")) + Assertions.assertEquals(1000500100900L, SafeParse.stringToLong("1000500100900")) // outside Integer range - assertEquals(2147483648L, SafeParse.stringToLong("2147483648")) - assertEquals(-2147483649L, SafeParse.stringToLong("-2147483649")) + Assertions.assertEquals(2147483648L, SafeParse.stringToLong("2147483648")) + Assertions.assertEquals(-2147483649L, SafeParse.stringToLong("-2147483649")) // units or other extra values are not permitted - assertEquals(0L, SafeParse.stringToLong("12 U/h")) - assertEquals(0L, SafeParse.stringToLong("0.1234")) - assertEquals(0L, SafeParse.stringToLong("0,1234")) - assertEquals(0L, SafeParse.stringToLong(".5436564812")) - assertEquals(0L, SafeParse.stringToLong(",5436564812")) - assertEquals(0L, SafeParse.stringToLong("42.1234")) - assertEquals(0L, SafeParse.stringToLong("42,1234")) - assertEquals(0L, SafeParse.stringToLong("3212.5436564812")) - assertEquals(0L, SafeParse.stringToLong("3212,5436564812")) + Assertions.assertEquals(0L, SafeParse.stringToLong("12 U/h")) + Assertions.assertEquals(0L, SafeParse.stringToLong("0.1234")) + Assertions.assertEquals(0L, SafeParse.stringToLong("0,1234")) + Assertions.assertEquals(0L, SafeParse.stringToLong(".5436564812")) + Assertions.assertEquals(0L, SafeParse.stringToLong(",5436564812")) + Assertions.assertEquals(0L, SafeParse.stringToLong("42.1234")) + Assertions.assertEquals(0L, SafeParse.stringToLong("42,1234")) + Assertions.assertEquals(0L, SafeParse.stringToLong("3212.5436564812")) + Assertions.assertEquals(0L, SafeParse.stringToLong("3212,5436564812")) // strings are not parsable - assertEquals(0L, SafeParse.stringToLong("ala ma kota")) + Assertions.assertEquals(0L, SafeParse.stringToLong("ala ma kota")) // various emptiness - assertEquals(0L, SafeParse.stringToLong("")) - assertEquals(0L, SafeParse.stringToLong(" ")) - assertEquals(0L, SafeParse.stringToLong("\n\r")) + Assertions.assertEquals(0L, SafeParse.stringToLong("")) + Assertions.assertEquals(0L, SafeParse.stringToLong(" ")) + Assertions.assertEquals(0L, SafeParse.stringToLong("\n\r")) } @Test fun stringToDoubleNullTest() { - assertEquals(0.0, SafeParse.stringToDouble(null), 0.001) + Assertions.assertEquals(0.0, SafeParse.stringToDouble(null), 0.001) } @Test fun stringToIntNullTest() { - assertEquals(0, SafeParse.stringToInt(null)) + Assertions.assertEquals(0, SafeParse.stringToInt(null)) } @Test fun stringToLongNullTest() { - assertEquals(0L, SafeParse.stringToLong(null)) + Assertions.assertEquals(0L, SafeParse.stringToLong(null)) } } \ No newline at end of file diff --git a/core/main/allopen_dependencies.gradle b/core/main/allopen_dependencies.gradle index 002600b6c0..7fc69d2430 100644 --- a/core/main/allopen_dependencies.gradle +++ b/core/main/allopen_dependencies.gradle @@ -1,4 +1,4 @@ allOpen { // allows mocking for classes w/o directly opening them for release builds - annotation 'info.nightscout.androidaps.annotations.OpenForTesting' + annotation 'info.nightscout.annotations.OpenForTesting' } diff --git a/core/main/src/main/java/info/nightscout/core/wizard/QuickWizardEntry.kt b/core/main/src/main/java/info/nightscout/core/wizard/QuickWizardEntry.kt index c06673da2b..e529442e93 100644 --- a/core/main/src/main/java/info/nightscout/core/wizard/QuickWizardEntry.kt +++ b/core/main/src/main/java/info/nightscout/core/wizard/QuickWizardEntry.kt @@ -1,7 +1,7 @@ package info.nightscout.core.wizard 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.iob.round import info.nightscout.core.utils.MidnightUtils @@ -38,9 +38,11 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec // for mock @OpenForTesting class Time { + fun secondsFromMidnight(): Int = MidnightUtils.secondsFromMidnight() } + var time = Time() lateinit var storage: JSONObject @@ -151,7 +153,26 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec trend = true } 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", "") diff --git a/core/utils/src/main/java/info/nightscout/core/utils/fabric/FabricPrivacy.kt b/core/utils/src/main/java/info/nightscout/core/utils/fabric/FabricPrivacy.kt index 227d12daa1..81542cd91f 100644 --- a/core/utils/src/main/java/info/nightscout/core/utils/fabric/FabricPrivacy.kt +++ b/core/utils/src/main/java/info/nightscout/core/utils/fabric/FabricPrivacy.kt @@ -5,7 +5,7 @@ import com.google.firebase.analytics.FirebaseAnalytics import com.google.firebase.analytics.ktx.analytics import com.google.firebase.crashlytics.FirebaseCrashlytics 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.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag diff --git a/core/utils/src/main/java/info/nightscout/core/utils/receivers/DataWorkerStorage.kt b/core/utils/src/main/java/info/nightscout/core/utils/receivers/DataWorkerStorage.kt index 5bd44bfb5a..83649bb3fb 100644 --- a/core/utils/src/main/java/info/nightscout/core/utils/receivers/DataWorkerStorage.kt +++ b/core/utils/src/main/java/info/nightscout/core/utils/receivers/DataWorkerStorage.kt @@ -6,7 +6,7 @@ import androidx.work.Data import androidx.work.ExistingWorkPolicy import androidx.work.OneTimeWorkRequest import androidx.work.WorkManager -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import org.json.JSONArray import org.json.JSONObject import javax.inject.Inject diff --git a/implementation/src/main/java/info/nightscout/implementation/DefaultValueHelperImpl.kt b/implementation/src/main/java/info/nightscout/implementation/DefaultValueHelperImpl.kt index 254e6685c8..f5ddce9f2c 100644 --- a/implementation/src/main/java/info/nightscout/implementation/DefaultValueHelperImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/DefaultValueHelperImpl.kt @@ -1,6 +1,6 @@ package info.nightscout.implementation -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import info.nightscout.interfaces.Constants import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.profile.DefaultValueHelper diff --git a/implementation/src/main/java/info/nightscout/implementation/HardLimitsImpl.kt b/implementation/src/main/java/info/nightscout/implementation/HardLimitsImpl.kt index de47f10267..9778cb6c80 100644 --- a/implementation/src/main/java/info/nightscout/implementation/HardLimitsImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/HardLimitsImpl.kt @@ -1,7 +1,7 @@ package info.nightscout.implementation 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.transactions.InsertTherapyEventAnnouncementTransaction import info.nightscout.interfaces.ui.UiInteraction diff --git a/implementation/src/main/java/info/nightscout/implementation/UserEntryLoggerImpl.kt b/implementation/src/main/java/info/nightscout/implementation/UserEntryLoggerImpl.kt index 41e76ca0d6..d7448f40ec 100644 --- a/implementation/src/main/java/info/nightscout/implementation/UserEntryLoggerImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/UserEntryLoggerImpl.kt @@ -1,7 +1,7 @@ package info.nightscout.implementation 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.Action import info.nightscout.database.entities.UserEntry.Sources diff --git a/implementation/src/main/java/info/nightscout/implementation/iob/GlucoseStatusProviderImpl.kt b/implementation/src/main/java/info/nightscout/implementation/iob/GlucoseStatusProviderImpl.kt index 2013c5800d..07b04c2788 100644 --- a/implementation/src/main/java/info/nightscout/implementation/iob/GlucoseStatusProviderImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/iob/GlucoseStatusProviderImpl.kt @@ -1,7 +1,7 @@ package info.nightscout.implementation.iob 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.log import info.nightscout.interfaces.iob.GlucoseStatus @@ -73,7 +73,6 @@ class GlucoseStatusProviderImpl @Inject constructor( // // short_deltas are calculated from everything ~5-15 minutes ago // } else if (2.5 < minutesAgo && minutesAgo < 17.5) { - //console.error(minutesAgo, avgDelta); shortDeltas.add(avgDel) // last_deltas are calculated from everything ~5 minutes ago if (2.5 < minutesAgo && minutesAgo < 7.5) { @@ -191,7 +190,7 @@ class GlucoseStatusProviderImpl @Inject constructor( fun average(array: ArrayList): Double { var sum = 0.0 - if (array.size == 0) return 0.0 + if (array.isEmpty()) return 0.0 for (value in array) { sum += value } diff --git a/implementation/src/main/java/info/nightscout/implementation/logging/LoggerUtilsImpl.kt b/implementation/src/main/java/info/nightscout/implementation/logging/LoggerUtilsImpl.kt index 2a2b350e06..7ec805f1f4 100644 --- a/implementation/src/main/java/info/nightscout/implementation/logging/LoggerUtilsImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/logging/LoggerUtilsImpl.kt @@ -1,7 +1,7 @@ package info.nightscout.implementation.logging import dagger.Reusable -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import info.nightscout.interfaces.logging.LoggerUtils import info.nightscout.interfaces.maintenance.PrefFileListProvider import javax.inject.Inject diff --git a/implementation/src/main/java/info/nightscout/implementation/profiling/ProfilerImpl.kt b/implementation/src/main/java/info/nightscout/implementation/profiling/ProfilerImpl.kt index a3e092607a..465bd81920 100644 --- a/implementation/src/main/java/info/nightscout/implementation/profiling/ProfilerImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/profiling/ProfilerImpl.kt @@ -1,7 +1,7 @@ package info.nightscout.implementation.profiling import dagger.Reusable -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import info.nightscout.interfaces.profiling.Profiler import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag diff --git a/implementation/src/main/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageImpl.kt b/implementation/src/main/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageImpl.kt index 1657944589..27191d08e2 100644 --- a/implementation/src/main/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageImpl.kt @@ -2,14 +2,14 @@ package info.nightscout.implementation.pump import com.google.gson.Gson 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.interfaces.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.DetailedBolusInfoStorage import info.nightscout.rx.logging.AAPSLogger -import info.nightscout.shared.sharedPreferences.SP import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.utils.T import javax.inject.Inject import javax.inject.Singleton @@ -39,7 +39,6 @@ class DetailedBolusInfoStorageImpl @Inject constructor( // Look for info with bolus for (i in store.indices) { 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) { aapsLogger.debug(LTag.PUMP, "Using & removing bolus info for time $bolusTime: ${store[i]}") store.removeAt(i) diff --git a/implementation/src/main/java/info/nightscout/implementation/pump/TemporaryBasalStorageImpl.kt b/implementation/src/main/java/info/nightscout/implementation/pump/TemporaryBasalStorageImpl.kt index b38ac96a56..a81073c577 100644 --- a/implementation/src/main/java/info/nightscout/implementation/pump/TemporaryBasalStorageImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/pump/TemporaryBasalStorageImpl.kt @@ -1,8 +1,8 @@ package info.nightscout.implementation.pump -import info.nightscout.androidaps.annotations.OpenForTesting -import info.nightscout.interfaces.pump.TemporaryBasalStorage +import info.nightscout.annotations.OpenForTesting import info.nightscout.interfaces.pump.PumpSync +import info.nightscout.interfaces.pump.TemporaryBasalStorage import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.utils.T diff --git a/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt b/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt index 63ebd67901..30bf77da5d 100644 --- a/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt @@ -8,7 +8,7 @@ import android.os.SystemClock import android.text.Spanned import androidx.appcompat.app.AppCompatActivity 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.extensions.getCustomizedName 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). showBolusProgressDialog(detailedBolusInfo) // 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() @@ -609,10 +616,7 @@ class CommandQueueImplementation @Inject constructor( override fun isCustomCommandRunning(customCommandType: Class): Boolean { val performing = this.performing - if (performing is CommandCustomCommand && customCommandType.isInstance(performing.customCommand)) { - return true - } - return false + return performing is CommandCustomCommand && customCommandType.isInstance(performing.customCommand) } @Synchronized diff --git a/implementation/src/main/java/info/nightscout/implementation/receivers/ReceiverStatusStoreImpl.kt b/implementation/src/main/java/info/nightscout/implementation/receivers/ReceiverStatusStoreImpl.kt index 08bb16cbf0..4d1afe9419 100644 --- a/implementation/src/main/java/info/nightscout/implementation/receivers/ReceiverStatusStoreImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/receivers/ReceiverStatusStoreImpl.kt @@ -2,7 +2,7 @@ package info.nightscout.implementation.receivers import android.content.Context import android.content.Intent -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import info.nightscout.interfaces.receivers.ReceiverStatusStore import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventChargingState diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt index 6e0cd97baa..50969bf984 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt @@ -13,7 +13,7 @@ import android.os.HandlerThread import android.os.SystemClock import androidx.core.app.NotificationCompat 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.extensions.convertedToAbsolute 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.transactions.InsertAndCancelCurrentOfflineEventTransaction import info.nightscout.database.impl.transactions.InsertTherapyEventAnnouncementTransaction +import info.nightscout.interfaces.ApsMode import info.nightscout.interfaces.Config import info.nightscout.interfaces.Constants -import info.nightscout.interfaces.ApsMode import info.nightscout.interfaces.aps.APSResult import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.aps.Loop.LastRun @@ -327,14 +327,22 @@ class LoopPlugin @Inject constructor( 0 ) && 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) rxBus.send(EventNewNotification(carbReqLocal)) } if (sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_create_announcements_from_carbs_req, false)) { 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) intentAction5m.putExtra("ignoreDuration", 5) val pendingIntent5m = PendingIntent.getBroadcast(context, 1, intentAction5m, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt index 34da305bb7..61af8fa1b6 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt @@ -2,7 +2,7 @@ package info.nightscout.plugins.aps.openAPSAMA import android.content.Context 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.utils.MidnightUtils import info.nightscout.core.utils.fabric.FabricPrivacy @@ -128,10 +128,22 @@ class OpenAPSAMAPlugin @Inject constructor( val maxIob = constraintChecker.getMaxIOBAllowed().also { maxIOBAllowedConstraint -> inputConstraints.copyReasons(maxIOBAllowedConstraint) }.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 = - 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]) - 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]) + 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] + ) + 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 val tempTarget = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet() 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.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.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 @@ -237,7 +255,12 @@ class OpenAPSAMAPlugin @Inject constructor( // 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 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 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) diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt index 7019ef8e7a..bb75f3bbd9 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt @@ -4,7 +4,6 @@ import android.content.Context import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreference import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.core.extensions.target import info.nightscout.core.utils.MidnightUtils import info.nightscout.database.ValueWrapper @@ -40,9 +39,8 @@ import javax.inject.Inject import javax.inject.Singleton import kotlin.math.floor -@OpenForTesting @Singleton -class OpenAPSSMBPlugin @Inject constructor( +open class OpenAPSSMBPlugin @Inject constructor( injector: HasAndroidInjector, aapsLogger: AAPSLogger, private val rxBus: RxBus, @@ -74,12 +72,12 @@ class OpenAPSSMBPlugin @Inject constructor( ), APS, Constraints { // DynamicISF specific - var tdd1D : Double? = null - var tdd7D : Double? = null - var tddLast24H : Double? = null - var tddLast4H : Double? = null - var tddLast8to4H : Double? = null - var dynIsfEnabled : Constraint = Constraint(false) + var tdd1D: Double? = null + var tdd7D: Double? = null + var tddLast24H: Double? = null + var tddLast4H: Double? = null + var tddLast8to4H: Double? = null + var dynIsfEnabled: Constraint = Constraint(false) // last values override var lastAPSRun: Long = 0 @@ -142,10 +140,22 @@ class OpenAPSSMBPlugin @Inject constructor( inputConstraints.copyReasons(maxIOBAllowedConstraint) }.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 = - 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]) - 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]) + 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] + ) + 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 val tempTarget = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet() 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.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.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 @@ -290,7 +306,12 @@ class OpenAPSSMBPlugin @Inject constructor( // 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 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 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) @@ -316,5 +337,5 @@ class OpenAPSSMBPlugin @Inject constructor( return value } - fun provideDetermineBasalAdapter(): DetermineBasalAdapter = DetermineBasalAdapterSMBJS(ScriptReader(context), injector) + open fun provideDetermineBasalAdapter(): DetermineBasalAdapter = DetermineBasalAdapterSMBJS(ScriptReader(context), injector) } \ No newline at end of file diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMBDynamicISF/OpenAPSSMBDynamicISFPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMBDynamicISF/OpenAPSSMBDynamicISFPlugin.kt index 750d9a46d7..2b83d11856 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMBDynamicISF/OpenAPSSMBDynamicISFPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMBDynamicISF/OpenAPSSMBDynamicISFPlugin.kt @@ -2,7 +2,7 @@ package info.nightscout.plugins.aps.openAPSSMBDynamicISF import android.content.Context import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.aps.DetermineBasalAdapter import info.nightscout.interfaces.bgQualityCheck.BgQualityCheck diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFS.kt b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFS.kt index 69d655462d..828fa618b8 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFS.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFS.kt @@ -1,6 +1,6 @@ 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.plugins.general.autotune.data.ATProfile import info.nightscout.plugins.general.autotune.data.PreppedGlucose @@ -25,9 +25,9 @@ import javax.inject.Singleton @Singleton @OpenForTesting class AutotuneFS @Inject constructor( - private val rh: ResourceHelper, + private val rh: ResourceHelper, private val loggerUtils: LoggerUtils - ) { +) { val AUTOTUNEFOLDER = "autotune" val SETTINGSFOLDER = "settings" diff --git a/plugins/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt b/plugins/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt index eb894dbd0a..725788bebb 100644 --- a/plugins/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt +++ b/plugins/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt @@ -5,7 +5,7 @@ import android.os.Handler import android.os.HandlerThread import android.os.SystemClock 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.ActionAlarm import info.nightscout.automation.actions.ActionCarePortalEvent diff --git a/plugins/automation/src/main/java/info/nightscout/automation/services/LastLocationDataContainer.kt b/plugins/automation/src/main/java/info/nightscout/automation/services/LastLocationDataContainer.kt index d81e60cba4..dcce6eedd3 100644 --- a/plugins/automation/src/main/java/info/nightscout/automation/services/LastLocationDataContainer.kt +++ b/plugins/automation/src/main/java/info/nightscout/automation/services/LastLocationDataContainer.kt @@ -1,7 +1,7 @@ package info.nightscout.automation.services import android.location.Location -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import javax.inject.Inject import javax.inject.Singleton diff --git a/plugins/automation/src/main/java/info/nightscout/automation/services/LocationServiceHelper.kt b/plugins/automation/src/main/java/info/nightscout/automation/services/LocationServiceHelper.kt index 9cf6e64b01..e905e42b0e 100644 --- a/plugins/automation/src/main/java/info/nightscout/automation/services/LocationServiceHelper.kt +++ b/plugins/automation/src/main/java/info/nightscout/automation/services/LocationServiceHelper.kt @@ -5,7 +5,7 @@ import android.content.Context import android.content.Intent import android.content.ServiceConnection import android.os.IBinder -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import info.nightscout.interfaces.NotificationHolder import javax.inject.Inject import javax.inject.Singleton diff --git a/plugins/automation/src/main/java/info/nightscout/automation/ui/TimerUtil.kt b/plugins/automation/src/main/java/info/nightscout/automation/ui/TimerUtil.kt index 861e4ebf42..3be56d6c11 100644 --- a/plugins/automation/src/main/java/info/nightscout/automation/ui/TimerUtil.kt +++ b/plugins/automation/src/main/java/info/nightscout/automation/ui/TimerUtil.kt @@ -3,15 +3,14 @@ package info.nightscout.automation.ui import android.content.Context import android.content.Intent import android.provider.AlarmClock -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import info.nightscout.automation.R import info.nightscout.core.ui.toast.ToastUtils import javax.inject.Inject import javax.inject.Singleton @OpenForTesting -@Singleton -open class TimerUtil @Inject constructor( +@Singleton class TimerUtil @Inject constructor( private val context: Context ) { diff --git a/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/PrefFileListProviderImpl.kt b/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/PrefFileListProviderImpl.kt index 588ef1034f..93e23dee1b 100644 --- a/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/PrefFileListProviderImpl.kt +++ b/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/PrefFileListProviderImpl.kt @@ -4,7 +4,7 @@ import android.content.Context import android.os.Environment import dagger.Lazy import dagger.Reusable -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import info.nightscout.configuration.R import info.nightscout.configuration.maintenance.formats.EncryptedPrefsFormat import info.nightscout.interfaces.Config @@ -42,6 +42,7 @@ class PrefFileListProviderImpl @Inject constructor( private val sp: SP, context: Context ) : PrefFileListProvider { + private val path = File(Environment.getExternalStorageDirectory().toString()) private val aapsPath = File(path, "AAPS" + File.separator + "preferences") 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")) return File(exportsPath, timeLocal + "_UserEntry.csv") } + override fun newCwfFile(filename: String): File { val timeLocal = LocalDateTime.now().toString(DateTimeFormat.forPattern("yyyy-MM-dd'_'HHmmss")) return File(exportsPath, "${filename}_$timeLocal${ZipWatchfaceFormat.CWF_EXTENTION}") diff --git a/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/storage/StorageConstraintPlugin.kt b/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/storage/StorageConstraintPlugin.kt index 7fbc119539..53d10c5296 100644 --- a/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/storage/StorageConstraintPlugin.kt +++ b/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/storage/StorageConstraintPlugin.kt @@ -3,7 +3,7 @@ package info.nightscout.plugins.constraints.storage import android.os.Environment import android.os.StatFs import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import info.nightscout.interfaces.Constants import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index eeb1d3b561..9f5bf71c88 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -10,7 +10,7 @@ import androidx.preference.PreferenceFragmentCompat import androidx.work.WorkerParameters import androidx.work.workDataOf 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.extensions.valueToUnitsString import info.nightscout.core.iob.generateCOBString @@ -418,7 +418,7 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true } - "STATUS" -> { + "STATUS" -> { val reply = if (loop.enabled) { if (loop.isSuspended) rh.gs(R.string.sms_loop_suspended_for, loop.minutesToEndOfSuspend()) else rh.gs(R.string.smscommunicator_loop_is_enabled) + " - " + getApsModeText() @@ -456,7 +456,7 @@ class SmsCommunicatorPlugin @Inject constructor( }) } - "SUSPEND" -> { + "SUSPEND" -> { var duration = 0 if (divided.size == 3) duration = SafeParse.stringToInt(divided[2]) duration = max(0, duration) @@ -504,7 +504,7 @@ class SmsCommunicatorPlugin @Inject constructor( } } - "LGS" -> { + "LGS" -> { val passCode = generatePassCode() val reply = rh.gs(R.string.smscommunicator_set_lgs_reply_with_code, passCode) receivedSms.processed = true @@ -519,7 +519,7 @@ class SmsCommunicatorPlugin @Inject constructor( }) } - "CLOSED" -> { + "CLOSED" -> { val passCode = generatePassCode() val reply = rh.gs(R.string.smscommunicator_set_closed_loop_reply_with_code, passCode) receivedSms.processed = true @@ -534,7 +534,7 @@ class SmsCommunicatorPlugin @Inject constructor( }) } - else -> sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format))) + else -> sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format))) } } @@ -882,7 +882,11 @@ class SmsCommunicatorPlugin @Inject constructor( uel.log( Action.EXTENDED_BOLUS, 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.Minute(duration), ValueWithUnit.SimpleString(rh.gsNotLocalised(info.nightscout.core.ui.R.string.loopsuspended)) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/otp/OneTimePassword.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/otp/OneTimePassword.kt index edcb6db942..dd612b3882 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/otp/OneTimePassword.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/otp/OneTimePassword.kt @@ -3,7 +3,7 @@ package info.nightscout.plugins.general.smsCommunicator.otp import android.util.Base64 import com.eatthepath.otp.HmacOneTimePasswordGenerator 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.plugins.R import info.nightscout.shared.interfaces.ResourceHelper @@ -107,7 +107,9 @@ class OneTimePassword @Inject constructor( * Return URI used to provision Authenticator apps */ 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 diff --git a/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt index 2f80bc8425..d5fd54b272 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt @@ -2,7 +2,7 @@ package info.nightscout.plugins.iob.iobCobCalculator import androidx.collection.LongSparseArray 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.iobCalc import info.nightscout.core.extensions.toTemporaryBasal diff --git a/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/data/AutosensDataStoreObject.kt b/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/data/AutosensDataStoreObject.kt index 4d5fb7159a..0e04a6f7d6 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/data/AutosensDataStoreObject.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/data/AutosensDataStoreObject.kt @@ -2,7 +2,7 @@ package info.nightscout.plugins.iob.iobCobCalculator.data import androidx.collection.LongSparseArray import androidx.collection.size -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import info.nightscout.database.entities.GlucoseValue import info.nightscout.interfaces.aps.AutosensData 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 currentTime = if (adjustedTime > currentTime) adjustedTime - T.mins(5).msecs() else adjustedTime aapsLogger.debug("Adjusted time " + dateUtil.dateAndTimeAndSecondsString(currentTime)) - //log.debug("First reading: " + new Date(currentTime).toLocaleString()); while (true) { // test if current value is older than current time val newer = findNewer(currentTime) @@ -248,7 +247,6 @@ class AutosensDataStoreObject : AutosensDataStore { val currentBg = newer.value - timeDiffToNew.toDouble() / (newer.timestamp - older.timestamp) * bgDelta val newBgReading = InMemoryGlucoseValue(currentTime, currentBg.roundToLong().toDouble(), filledGap = filledGap, sourceSensor = lastBg.sourceSensor) 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() } @@ -268,23 +266,19 @@ class AutosensDataStoreObject : AutosensDataStore { for (i in 1 until bgReadings.size) { val bgTime = bgReadings[i].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) when { abs(elapsedMinutes) > 8 -> { // interpolate missing data points var lastBgValue = bgReadings[i - 1].value elapsedMinutes = abs(elapsedMinutes) - //console.error(elapsed_minutes); var nextBgTime: Long while (elapsedMinutes > 5) { nextBgTime = lastBgTime - 5 * 60 * 1000 j++ val gapDelta = bgReadings[i].value - lastBgValue - //console.error(gapDelta, lastBg, elapsed_minutes); val nextBg = lastBgValue + 5.0 / elapsedMinutes * gapDelta val newBgReading = InMemoryGlucoseValue(nextBgTime, nextBg.roundToLong().toDouble(), filledGap = true, sourceSensor = lastBg.sourceSensor) - //console.error("Interpolated", bData[j]); bData.add(newBgReading) aapsLogger.debug(LTag.AUTOSENS) { "Adding. bgTime: ${dateUtil.toISOString(bgTime)} lastBgTime: ${dateUtil.toISOString(lastBgTime)} $newBgReading" } elapsedMinutes -= 5 @@ -306,7 +300,6 @@ class AutosensDataStoreObject : AutosensDataStore { else -> { bData[j].value = (bData[j].value + bgReadings[i].value) / 2 - //log.error("***** Average"); } } } diff --git a/plugins/main/src/main/java/info/nightscout/plugins/profile/ProfilePlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/profile/ProfilePlugin.kt index 90967d245f..eab1010de6 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/profile/ProfilePlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/profile/ProfilePlugin.kt @@ -2,7 +2,7 @@ package info.nightscout.plugins.profile import androidx.fragment.app.FragmentActivity 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.pureProfileFromJson import info.nightscout.core.profile.ProfileSealed @@ -171,15 +171,15 @@ class ProfilePlugin @Inject constructor( override fun storeSettings(activity: FragmentActivity?, timestamp: Long) { for (i in 0 until numOfProfiles) { profiles[i].run { - val localProfileNumbered = Constants.LOCAL_PROFILE + "_" + i + "_" - sp.putString(localProfileNumbered + "name", name) - sp.putBoolean(localProfileNumbered + "mgdl", mgdl) - sp.putDouble(localProfileNumbered + "dia", dia) - sp.putString(localProfileNumbered + "ic", ic.toString()) - sp.putString(localProfileNumbered + "isf", isf.toString()) - sp.putString(localProfileNumbered + "basal", basal.toString()) - sp.putString(localProfileNumbered + "targetlow", targetLow.toString()) - sp.putString(localProfileNumbered + "targethigh", targetHigh.toString()) + val localProfileNumbered = Constants.LOCAL_PROFILE + "_" + i + "_" + sp.putString(localProfileNumbered + "name", name) + sp.putBoolean(localProfileNumbered + "mgdl", mgdl) + sp.putDouble(localProfileNumbered + "dia", dia) + sp.putString(localProfileNumbered + "ic", ic.toString()) + sp.putString(localProfileNumbered + "isf", isf.toString()) + sp.putString(localProfileNumbered + "basal", basal.toString()) + sp.putString(localProfileNumbered + "targetlow", targetLow.toString()) + sp.putString(localProfileNumbered + "targethigh", targetHigh.toString()) } } sp.putInt(Constants.LOCAL_PROFILE + "_profiles", numOfProfiles) diff --git a/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityAAPSPlugin.kt b/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityAAPSPlugin.kt index 77a198cbd1..cade8c08a2 100644 --- a/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityAAPSPlugin.kt +++ b/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityAAPSPlugin.kt @@ -1,7 +1,7 @@ package info.nightscout.sensitivity 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.Percentile import info.nightscout.database.entities.TherapyEvent @@ -162,18 +162,30 @@ class SensitivityAAPSPlugin @Inject constructor( override fun applyConfiguration(configuration: JSONObject) { try { 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))) + info.nightscout.core.utils.R.string.key_absorption_maxtime, configuration.getDouble( + 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( 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( - info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble(rh.gs( - info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) + info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble( + 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( - info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble(rh.gs( - info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) + info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble( + rh.gs( + info.nightscout.core.utils.R.string.key_openapsama_autosens_min + ) + ) + ) } catch (e: JSONException) { e.printStackTrace() } diff --git a/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityOref1Plugin.kt b/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityOref1Plugin.kt index 31cf111e86..f98681d3b8 100644 --- a/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityOref1Plugin.kt +++ b/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityOref1Plugin.kt @@ -1,7 +1,7 @@ package info.nightscout.sensitivity 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.Percentile import info.nightscout.database.entities.TherapyEvent @@ -211,7 +211,10 @@ class SensitivityOref1Plugin @Inject constructor( override fun configuration(): JSONObject { val c = JSONObject() 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_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)) @@ -228,14 +231,26 @@ class SensitivityOref1Plugin @Inject constructor( 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( - info.nightscout.core.utils.R.string.key_absorption_cutoff, configuration.getDouble(rh.gs( - info.nightscout.core.utils.R.string.key_absorption_cutoff))) + info.nightscout.core.utils.R.string.key_absorption_cutoff, configuration.getDouble( + 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( - info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble(rh.gs( - info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) + info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble( + 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( - info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble(rh.gs( - info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) + info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble( + rh.gs( + info.nightscout.core.utils.R.string.key_openapsama_autosens_min + ) + ) + ) } catch (e: JSONException) { e.printStackTrace() } diff --git a/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityWeightedAveragePlugin.kt b/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityWeightedAveragePlugin.kt index daac5740c5..b7b915ad6c 100644 --- a/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityWeightedAveragePlugin.kt +++ b/plugins/sensitivity/src/main/java/info/nightscout/sensitivity/SensitivityWeightedAveragePlugin.kt @@ -2,7 +2,7 @@ package info.nightscout.sensitivity import androidx.collection.LongSparseArray import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import info.nightscout.core.utils.MidnightUtils import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.impl.AppRepository @@ -182,18 +182,30 @@ class SensitivityWeightedAveragePlugin @Inject constructor( override fun applyConfiguration(configuration: JSONObject) { try { 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))) + info.nightscout.core.utils.R.string.key_absorption_maxtime, configuration.getDouble( + 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( 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( - info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble(rh.gs( - info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) + info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble( + 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( - info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble(rh.gs( - info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) + info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble( + rh.gs( + info.nightscout.core.utils.R.string.key_openapsama_autosens_min + ) + ) + ) } catch (e: JSONException) { e.printStackTrace() } diff --git a/plugins/smoothing/src/main/java/info/nightscout/smoothing/AvgSmoothingPlugin.kt b/plugins/smoothing/src/main/java/info/nightscout/smoothing/AvgSmoothingPlugin.kt index 0214c39b5b..3894ac7593 100644 --- a/plugins/smoothing/src/main/java/info/nightscout/smoothing/AvgSmoothingPlugin.kt +++ b/plugins/smoothing/src/main/java/info/nightscout/smoothing/AvgSmoothingPlugin.kt @@ -1,7 +1,7 @@ package info.nightscout.smoothing import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import info.nightscout.database.entities.GlucoseValue import info.nightscout.interfaces.iob.InMemoryGlucoseValue import info.nightscout.interfaces.plugin.PluginBase @@ -33,13 +33,12 @@ class AvgSmoothingPlugin @Inject constructor( ), Smoothing { override fun smooth(data: MutableList): MutableList { - if (data.lastIndex < 4) - { + if (data.lastIndex < 4) { aapsLogger.debug(LTag.GLUCOSE, "Not enough value's to smooth!") return data } - for (i in data.lastIndex -1 downTo 1) { + for (i in data.lastIndex - 1 downTo 1) { // Check if value's are in a valid range // Bucketed is always calculated to 5 min, we still check if our data is evenly spaced with an allowance of 30 seconds if (isValid(data[i].value) && isValid(data[i - 1].value) && isValid(data[i + 1].value) @@ -60,6 +59,7 @@ class AvgSmoothingPlugin @Inject constructor( // data[0].smoothed = data[0].value return data } + private fun isValid(n: Double): Boolean { // For Dexcom: Below 39 is LOW, above 401 Dexcom just says HI return n > 39 && n < 401 diff --git a/plugins/smoothing/src/main/java/info/nightscout/smoothing/ExponentialSmoothingPlugin.kt b/plugins/smoothing/src/main/java/info/nightscout/smoothing/ExponentialSmoothingPlugin.kt index 19e42d4a9f..22f76d60b0 100644 --- a/plugins/smoothing/src/main/java/info/nightscout/smoothing/ExponentialSmoothingPlugin.kt +++ b/plugins/smoothing/src/main/java/info/nightscout/smoothing/ExponentialSmoothingPlugin.kt @@ -1,7 +1,7 @@ package info.nightscout.smoothing import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting import info.nightscout.database.entities.GlucoseValue import info.nightscout.interfaces.iob.InMemoryGlucoseValue import info.nightscout.interfaces.plugin.PluginBase @@ -123,11 +123,6 @@ class ExponentialSmoothingPlugin @Inject constructor( // here 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 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 diff --git a/plugins/smoothing/src/main/java/info/nightscout/smoothing/NoSmoothingPlugin.kt b/plugins/smoothing/src/main/java/info/nightscout/smoothing/NoSmoothingPlugin.kt index 04efe0f078..3ce54bd6c7 100644 --- a/plugins/smoothing/src/main/java/info/nightscout/smoothing/NoSmoothingPlugin.kt +++ b/plugins/smoothing/src/main/java/info/nightscout/smoothing/NoSmoothingPlugin.kt @@ -1,7 +1,7 @@ package info.nightscout.smoothing 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.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription diff --git a/plugins/source/src/main/java/info/nightscout/source/GlimpPlugin.kt b/plugins/source/src/main/java/info/nightscout/source/GlimpPlugin.kt index 1630431807..2e54005571 100644 --- a/plugins/source/src/main/java/info/nightscout/source/GlimpPlugin.kt +++ b/plugins/source/src/main/java/info/nightscout/source/GlimpPlugin.kt @@ -4,7 +4,7 @@ import android.content.Context import androidx.work.WorkerParameters import androidx.work.workDataOf 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.database.entities.GlucoseValue import info.nightscout.database.impl.AppRepository diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/NsIncomingDataProcessor.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/NsIncomingDataProcessor.kt index d00eed01b0..57c441316f 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/NsIncomingDataProcessor.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/NsIncomingDataProcessor.kt @@ -1,6 +1,6 @@ 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.GlucoseValue import info.nightscout.database.transactions.TransactionGlucoseValue diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/ReceiverDelegate.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/ReceiverDelegate.kt index 6866d36408..b1c15595e3 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/ReceiverDelegate.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/ReceiverDelegate.kt @@ -1,6 +1,6 @@ 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.interfaces.receivers.ReceiverStatusStore import info.nightscout.plugins.sync.R diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/NSDeviceStatusHandler.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/NSDeviceStatusHandler.kt index 4a483991da..adf88bf940 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/NSDeviceStatusHandler.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/NSDeviceStatusHandler.kt @@ -1,6 +1,6 @@ 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.configBuilder.RunningConfiguration import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/NSSettingsStatusImpl.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/NSSettingsStatusImpl.kt index caf2c3979b..ffdf576816 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/NSSettingsStatusImpl.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/NSSettingsStatusImpl.kt @@ -3,7 +3,7 @@ package info.nightscout.plugins.sync.nsclient.data 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.database.entities.UserEntry import info.nightscout.database.entities.UserEntry.Action diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/DataSyncSelectorV3.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/DataSyncSelectorV3.kt index f1acdd1677..cfb9bc3e10 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/DataSyncSelectorV3.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/DataSyncSelectorV3.kt @@ -1,6 +1,6 @@ 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.interfaces.Config import info.nightscout.interfaces.nsclient.StoreDataForDb diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt index 74b773b427..8fb9a410da 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt @@ -14,7 +14,7 @@ import androidx.work.WorkManager import com.google.gson.Gson import com.google.gson.GsonBuilder 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.database.ValueWrapper import info.nightscout.database.entities.interfaces.TraceableDBEntry diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/DataSyncWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/DataSyncWorker.kt index 0ef6e9da02..f19054c336 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/DataSyncWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/DataSyncWorker.kt @@ -2,7 +2,7 @@ package info.nightscout.plugins.sync.nsclientV3.workers import android.content.Context 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.interfaces.plugin.ActivePlugin import info.nightscout.plugins.sync.nsclientV3.DataSyncSelectorV3 diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/workers/XdripDataSyncWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/workers/XdripDataSyncWorker.kt index 68d2dbf7db..f55c5236e0 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/workers/XdripDataSyncWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/xdrip/workers/XdripDataSyncWorker.kt @@ -2,7 +2,7 @@ package info.nightscout.plugins.sync.xdrip.workers import android.content.Context 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.interfaces.plugin.ActivePlugin import info.nightscout.plugins.sync.xdrip.DataSyncSelectorXdripImpl diff --git a/plugins/sync/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt b/plugins/sync/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt index 9c4cae2277..a482c57fe4 100644 --- a/plugins/sync/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt +++ b/plugins/sync/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps 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.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.Pump diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt index 65c35ae88a..87f6173f70 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt @@ -6,10 +6,10 @@ import android.content.Intent import android.content.ServiceConnection import android.os.IBinder import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.danaRKorean.services.DanaRKoreanExecutionService import info.nightscout.androidaps.danar.AbstractDanaRPlugin import info.nightscout.androidaps.danar.R +import info.nightscout.annotations.OpenForTesting import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints @@ -74,14 +74,14 @@ class DanaRKoreanPlugin @Inject constructor( .toObservable(EventPreferenceChange::class.java) .observeOn(aapsSchedulers.io) .subscribe({ - if (isEnabled()) { - val previousValue = useExtendedBoluses - useExtendedBoluses = sp.getBoolean(info.nightscout.core.utils.R.string.key_danar_useextended, false) - if (useExtendedBoluses != previousValue && pumpSync.expectedPumpState().extendedBolus != null) { - sExecutionService.extendedBolusStop() - } - } - }, fabricPrivacy::logException) + if (isEnabled()) { + val previousValue = useExtendedBoluses + useExtendedBoluses = sp.getBoolean(info.nightscout.core.utils.R.string.key_danar_useextended, false) + if (useExtendedBoluses != previousValue && pumpSync.expectedPumpState().extendedBolus != null) { + sExecutionService.extendedBolusStop() + } + } + }, fabricPrivacy::logException) disposable += rxBus .toObservable(EventAppExit::class.java) .observeOn(aapsSchedulers.io) @@ -130,7 +130,7 @@ class DanaRKoreanPlugin @Inject constructor( override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { detailedBolusInfo.insulin = constraintChecker.applyBolusConstraints(Constraint(detailedBolusInfo.insulin)).value() - if (detailedBolusInfo.carbs > 0) throw IllegalArgumentException() + require(detailedBolusInfo.carbs > 0) return if (detailedBolusInfo.insulin > 0) { val t = EventOverviewBolusProgress.Treatment(0.0, 0, detailedBolusInfo.bolusType == DetailedBolusInfo.BolusType.SMB, detailedBolusInfo.id) var connectionOK = false @@ -142,7 +142,14 @@ class DanaRKoreanPlugin @Inject constructor( val result = PumpEnactResult(injector) result.success(connectionOK && abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep) .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) detailedBolusInfo.insulin = t.insulin detailedBolusInfo.timestamp = dateUtil.now() diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java index f35b56f20e..34396a7abe 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java @@ -12,10 +12,10 @@ import javax.inject.Inject; import javax.inject.Singleton; import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.annotations.OpenForTesting; import info.nightscout.androidaps.danaRv2.services.DanaRv2ExecutionService; import info.nightscout.androidaps.danar.AbstractDanaRPlugin; import info.nightscout.androidaps.danar.R; +import info.nightscout.annotations.OpenForTesting; import info.nightscout.core.utils.fabric.FabricPrivacy; import info.nightscout.interfaces.constraints.Constraint; import info.nightscout.interfaces.constraints.Constraints; @@ -232,8 +232,8 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { 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. if (absoluteRate < 0.10d) percentRate = 0; - if (percentRate < 100) percentRate = (int) Round.INSTANCE.ceilTo((double) percentRate, 10d); - else percentRate = (int) Round.INSTANCE.floorTo((double) percentRate, 10d); + if (percentRate < 100) percentRate = (int) Round.INSTANCE.ceilTo(percentRate, 10d); + else percentRate = (int) Round.INSTANCE.floorTo(percentRate, 10d); if (percentRate > 500) // Special high temp 500/15min percentRate = 500; aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Calculated percent rate: " + percentRate); diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java b/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java index 243ad812b2..ab4c9c77e4 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java @@ -12,8 +12,8 @@ import javax.inject.Inject; import javax.inject.Singleton; import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.annotations.OpenForTesting; import info.nightscout.androidaps.danar.services.DanaRExecutionService; +import info.nightscout.annotations.OpenForTesting; import info.nightscout.core.utils.fabric.FabricPrivacy; import info.nightscout.interfaces.constraints.Constraint; import info.nightscout.interfaces.constraints.Constraints; diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.kt index 00716a1860..19cd9f5661 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.kt @@ -1,6 +1,5 @@ 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.hw.rileylink.RileyLinkUtil 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.MedtronicDeviceType import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst +import info.nightscout.annotations.OpenForTesting import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.pump.common.data.PumpStatus import info.nightscout.pump.common.sync.PumpDbEntryTBR diff --git a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/util/RandomByteGenerator.kt b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/util/RandomByteGenerator.kt index 971869f5d2..f894d3360c 100644 --- a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/util/RandomByteGenerator.kt +++ b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/util/RandomByteGenerator.kt @@ -1,10 +1,11 @@ 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 @OpenForTesting class RandomByteGenerator { + private val secureRandom = SecureRandom() fun nextBytes(length: Int): ByteArray = ByteArray(length).also(secureRandom::nextBytes) diff --git a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/util/X25519KeyGenerator.kt b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/util/X25519KeyGenerator.kt index 56a7f1b425..e891a50028 100644 --- a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/util/X25519KeyGenerator.kt +++ b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/util/X25519KeyGenerator.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.util import com.google.crypto.tink.subtle.X25519 -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.annotations.OpenForTesting @OpenForTesting class X25519KeyGenerator { diff --git a/pump/pump-common/src/main/java/info/nightscout/pump/common/sync/PumpSyncStorage.kt b/pump/pump-common/src/main/java/info/nightscout/pump/common/sync/PumpSyncStorage.kt index 548fad8665..fc3c0e0216 100644 --- a/pump/pump-common/src/main/java/info/nightscout/pump/common/sync/PumpSyncStorage.kt +++ b/pump/pump-common/src/main/java/info/nightscout/pump/common/sync/PumpSyncStorage.kt @@ -2,7 +2,7 @@ package info.nightscout.pump.common.sync import com.thoughtworks.xstream.XStream 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.PumpSync import info.nightscout.rx.logging.AAPSLogger @@ -24,6 +24,7 @@ class PumpSyncStorage @Inject constructor( ) { companion object { + const val pumpSyncStorageBolusKey: String = "pump_sync_storage_bolus" const val pumpSyncStorageTBRKey: String = "pump_sync_storage_tbr" } @@ -80,7 +81,7 @@ class PumpSyncStorage @Inject constructor( } fun saveStorageBolus() { - if (!pumpSyncStorageBolus.isEmpty()) { + if (pumpSyncStorageBolus.isNotEmpty()) { sp.putString(pumpSyncStorageBolusKey, xstream.toXML(pumpSyncStorageBolus)) aapsLogger.debug(LTag.PUMP, "Saving Pump Sync Storage: boluses=${pumpSyncStorageBolus.size}") } else { @@ -90,7 +91,7 @@ class PumpSyncStorage @Inject constructor( } fun saveStorageTBR() { - if (!pumpSyncStorageTBR.isEmpty()) { + if (pumpSyncStorageTBR.isNotEmpty()) { sp.putString(pumpSyncStorageTBRKey, xstream.toXML(pumpSyncStorageTBR)) aapsLogger.debug(LTag.PUMP, "Saving Pump Sync Storage: tbr=${pumpSyncStorageTBR.size}") } else { @@ -124,23 +125,27 @@ class PumpSyncStorage @Inject constructor( temporaryId, detailedBolusInfo.bolusType, creator.model(), - creator.serialNumber()) + creator.serialNumber() + ) aapsLogger.debug( LTag.PUMP, "addBolusWithTempId [date=${detailedBolusInfo.timestamp}, temporaryId=$temporaryId, " + - "insulin=${detailedBolusInfo.insulin}, type=${detailedBolusInfo.bolusType}, pumpSerial=${creator.serialNumber()}] - " + - "Result: $result") + "insulin=${detailedBolusInfo.insulin}, type=${detailedBolusInfo.bolusType}, pumpSerial=${creator.serialNumber()}] - " + + "Result: $result" + ) if (detailedBolusInfo.carbs > 0.0) { addCarbs(PumpDbEntryCarbs(detailedBolusInfo, creator)) } if (result && writeToInternalHistory) { - val dbEntry = PumpDbEntryBolus(temporaryId = temporaryId, - date = detailedBolusInfo.timestamp, - pumpType = creator.model(), - serialNumber = creator.serialNumber(), - detailedBolusInfo = detailedBolusInfo) + val dbEntry = PumpDbEntryBolus( + temporaryId = temporaryId, + date = detailedBolusInfo.timestamp, + pumpType = creator.model(), + serialNumber = creator.serialNumber(), + detailedBolusInfo = detailedBolusInfo + ) aapsLogger.debug("PumpDbEntryBolus: $dbEntry") @@ -156,11 +161,13 @@ class PumpSyncStorage @Inject constructor( carbsDto.carbs, null, carbsDto.pumpType, - carbsDto.serialNumber) + carbsDto.serialNumber + ) aapsLogger.debug( 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 { @@ -175,15 +182,18 @@ class PumpSyncStorage @Inject constructor( temporaryId, temporaryBasal.tbrType, creator.model(), - creator.serialNumber()) + creator.serialNumber() + ) if (response && writeToInternalHistory) { - val dbEntry = PumpDbEntryTBR(temporaryId = temporaryId, - date = timeNow, - pumpType = creator.model(), - serialNumber = creator.serialNumber(), - entry = temporaryBasal, - pumpId=null) + val dbEntry = PumpDbEntryTBR( + temporaryId = temporaryId, + date = timeNow, + pumpType = creator.model(), + serialNumber = creator.serialNumber(), + entry = temporaryBasal, + pumpId = null + ) aapsLogger.debug("PumpDbEntryTBR: $dbEntry") diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.kt index 26b85433be..ddb2711bac 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Persistence.kt @@ -1,6 +1,6 @@ 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.LTag import info.nightscout.rx.weardata.EventData @@ -176,7 +176,7 @@ open class Persistence @Inject constructor( } fun setDefaultWatchface() { - readCustomWatchface(true)?.let {store(it)} + readCustomWatchface(true)?.let { store(it) } aapsLogger.debug(LTag.WEAR, "Custom Watchface reset to default") } diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.kt index b703e1e5b2..3744ab2868 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.kt @@ -2,7 +2,7 @@ package info.nightscout.androidaps.interaction.utils import android.content.Context 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.LTag diff --git a/wear/src/test/java/info/nightscout/androidaps/testing/mockers/WearUtilMocker.kt b/wear/src/test/java/info/nightscout/androidaps/testing/mockers/WearUtilMocker.kt index e5d17abaf3..4884c60e19 100644 --- a/wear/src/test/java/info/nightscout/androidaps/testing/mockers/WearUtilMocker.kt +++ b/wear/src/test/java/info/nightscout/androidaps/testing/mockers/WearUtilMocker.kt @@ -1,8 +1,8 @@ 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.WearUtil +import info.nightscout.annotations.OpenForTesting import org.mockito.ArgumentMatchers import org.mockito.Mockito