diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index 2612c101ad..ff88459f6a 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -79,7 +79,7 @@ open class AppModule { @Binds fun bindCommandQueueProvider(commandQueue: CommandQueue): CommandQueueProvider @Binds fun bindConfigInterface(config: Config): ConfigInterface @Binds fun bindConfigBuilderInterface(configBuilderPlugin: ConfigBuilderPlugin): ConfigBuilderInterface - @Binds fun bindTreatmentInterface(treatmentsPlugin: TreatmentsPlugin): TreatmentsInterface + @Binds fun bindTreatmentsInterface(treatmentsPlugin: TreatmentsPlugin): TreatmentsInterface @Binds fun bindDatabaseHelperInterface(databaseHelperProvider: DatabaseHelperProvider): DatabaseHelperInterface @Binds fun bindNotificationHolderInterface(notificationHolder: NotificationHolder): NotificationHolderInterface @Binds fun bindImportExportPrefsInterface(importExportPrefs: ImportExportPrefs): ImportExportPrefsInterface diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt index e970cefef0..cecef90241 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt @@ -8,6 +8,7 @@ import info.nightscout.androidaps.TestPumpPlugin import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -17,7 +18,7 @@ import org.mockito.Mock import org.mockito.Mockito.`when` import org.powermock.core.classloader.annotations.PrepareForTest -@PrepareForTest(RxBusWrapper::class, ActionsTestBase.TestLoopPlugin::class) +@PrepareForTest(RxBusWrapper::class, ActionsTestBase.TestLoopPlugin::class, UserEntryLogger::class) open class ActionsTestBase : TestBaseWithProfile() { open class TestLoopPlugin( @@ -29,7 +30,7 @@ open class ActionsTestBase : TestBaseWithProfile() { pluginDescription, aapsLogger, resourceHelper, injector ), LoopInterface { - var suspended = false + private var suspended = false override var lastRun: LoopInterface.LastRun? = LoopInterface.LastRun() override val isSuspended: Boolean = suspended override fun suspendTo(endTime: Long) {} @@ -44,6 +45,7 @@ open class ActionsTestBase : TestBaseWithProfile() { @Mock lateinit var profilePlugin: ProfileInterface @Mock lateinit var smsCommunicatorPlugin: SmsCommunicatorInterface @Mock lateinit var loopPlugin: TestLoopPlugin + @Mock lateinit var uel: UserEntryLogger private val pluginDescription = PluginDescription() lateinit var testPumpPlugin: TestPumpPlugin @@ -55,6 +57,7 @@ open class ActionsTestBase : TestBaseWithProfile() { it.resourceHelper = resourceHelper it.dateUtil = dateUtil it.repository = repository + it.uel = uel } if (it is ActionStartTempTarget) { it.aapsLogger = aapsLogger @@ -62,6 +65,7 @@ open class ActionsTestBase : TestBaseWithProfile() { it.activePlugin = activePlugin it.repository = repository it.profileFunction = profileFunction + it.uel = uel } if (it is ActionSendSMS) { it.aapsLogger = aapsLogger @@ -73,10 +77,12 @@ open class ActionsTestBase : TestBaseWithProfile() { it.resourceHelper = resourceHelper it.activePlugin = activePlugin it.profileFunction = profileFunction + it.uel = uel } if (it is ActionProfileSwitchPercent) { it.resourceHelper = resourceHelper it.activePlugin = activePlugin + it.uel = uel } if (it is ActionNotification) { it.resourceHelper = resourceHelper @@ -86,18 +92,21 @@ open class ActionsTestBase : TestBaseWithProfile() { it.loopPlugin = loopPlugin it.resourceHelper = resourceHelper it.rxBus = rxBus + it.uel = uel } if (it is ActionLoopResume) { it.loopPlugin = loopPlugin it.resourceHelper = resourceHelper it.configBuilderPlugin = configBuilderPlugin it.rxBus = rxBus + it.uel = uel } if (it is ActionLoopEnable) { it.loopPlugin = loopPlugin it.resourceHelper = resourceHelper it.configBuilderPlugin = configBuilderPlugin it.rxBus = rxBus + it.uel = uel } if (it is ActionLoopDisable) { it.loopPlugin = loopPlugin @@ -105,6 +114,7 @@ open class ActionsTestBase : TestBaseWithProfile() { it.configBuilderPlugin = configBuilderPlugin it.commandQueue = commandQueue it.rxBus = rxBus + it.uel = uel } if (it is PumpEnactResult) { it.resourceHelper = resourceHelper diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIobTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIobTest.kt index 8a2961bc17..8b33bb23c2 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIobTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerIobTest.kt @@ -30,7 +30,7 @@ class TriggerIobTest : TriggerTestBase() { } @Test fun shouldRunTest() { - `when`(iobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Profile::class.java))).thenReturn(generateIobRecordData()) + `when`(iobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(ArgumentMatchers.anyLong(), anyObject())).thenReturn(generateIobRecordData()) var t: TriggerIob = TriggerIob(injector).setValue(1.1).comparator(Comparator.Compare.IS_EQUAL) Assert.assertFalse(t.shouldRun()) t = TriggerIob(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL) diff --git a/core/src/main/java/info/nightscout/androidaps/utils/serialisation/SealedClassHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/serialisation/SealedClassHelper.kt index 216754bd86..a3fd471bd2 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/serialisation/SealedClassHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/serialisation/SealedClassHelper.kt @@ -33,6 +33,7 @@ object SealedClassHelper { val x = gson.fromJson(jsonReader, innerClass.javaObjectType) jsonReader.endObject() // if there a static object, actually return that + @Suppress("UNCHECKED_CAST") return innerClass.objectInstance as T? ?: x } diff --git a/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java b/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java index e68b0029a4..2da5d829d5 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java +++ b/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java @@ -19,7 +19,6 @@ import info.nightscout.androidaps.danar.R; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; -import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.CommandQueueProvider; diff --git a/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgInitConnStatusBasic.kt b/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgInitConnStatusBasic.kt index c69078a09b..82ab4f12ea 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgInitConnStatusBasic.kt +++ b/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgInitConnStatusBasic.kt @@ -25,7 +25,7 @@ class MsgInitConnStatusBasic( danaPump.currentBasal = intFromBuff(bytes, 11, 2) / 100.0 val tempBasalPercent = intFromBuff(bytes, 13, 1) val isExtendedInProgress = intFromBuff(bytes, 14, 1) == 1 - val isTempBasalInProgress = intFromBuff(bytes, 15, 1) == 1 + //val isTempBasalInProgress = intFromBuff(bytes, 15, 1) == 1 val statusBasalUDOption = intFromBuff(bytes, 16, 1) danaPump.isDualBolusInProgress = intFromBuff(bytes, 17, 1) == 1 val extendedBolusRate = intFromBuff(bytes, 18, 2) / 100.0 @@ -46,8 +46,8 @@ class MsgInitConnStatusBasic( aapsLogger.debug(LTag.PUMPCOMM, "Reservoir remaining units: " + danaPump.reservoirRemainingUnits) aapsLogger.debug(LTag.PUMPCOMM, "Bolus blocked: " + danaPump.bolusBlocked) aapsLogger.debug(LTag.PUMPCOMM, "Current basal: " + danaPump.currentBasal) - aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal percent: " + tempBasalPercent) - aapsLogger.debug(LTag.PUMPCOMM, "Is extended bolus running: " + isExtendedInProgress) + aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal percent: $tempBasalPercent") + aapsLogger.debug(LTag.PUMPCOMM, "Is extended bolus running: $isExtendedInProgress") aapsLogger.debug(LTag.PUMPCOMM, "statusBasalUDOption: $statusBasalUDOption") aapsLogger.debug(LTag.PUMPCOMM, "Is dual bolus running: " + danaPump.isDualBolusInProgress) aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus rate: $extendedBolusRate") diff --git a/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgStatusTempBasal.kt b/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgStatusTempBasal.kt index 07cb3a461d..69df6d4157 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgStatusTempBasal.kt +++ b/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgStatusTempBasal.kt @@ -16,8 +16,10 @@ class MsgStatusTempBasal( aapsLogger.debug(LTag.PUMPCOMM, "New message") } + var isTempBasalInProgress = false + override fun handleMessage(bytes: ByteArray) { - val isTempBasalInProgress = intFromBuff(bytes, 0, 1) and 0x01 == 0x01 + isTempBasalInProgress = intFromBuff(bytes, 0, 1) and 0x01 == 0x01 val isAPSTempBasalInProgress = intFromBuff(bytes, 0, 1) and 0x02 == 0x02 var tempBasalPercent = intFromBuff(bytes, 1, 1) if (tempBasalPercent > 200) tempBasalPercent = (tempBasalPercent - 200) * 10 @@ -47,7 +49,7 @@ class MsgStatusTempBasal( } private fun getDateFromSecAgo(tempBasalAgoSecs: Int): Long { - return (floor(System.currentTimeMillis() / 1000.0) - tempBasalAgoSecs).toLong() * 1000 + return (floor(dateUtil._now() / 1000.0) - tempBasalAgoSecs).toLong() * 1000 } // because there is no fixed timestamp of start allow update of tbr only if tbr start differs more diff --git a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/DanaRTestBase.kt b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/DanaRTestBase.kt index 3e5c5f3659..b237d26f12 100644 --- a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/DanaRTestBase.kt +++ b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/DanaRTestBase.kt @@ -32,7 +32,6 @@ open class DanaRTestBase : TestBase() { @Mock lateinit var activePluginProvider: ActivePluginProvider @Mock lateinit var dateUtil: DateUtil @Mock lateinit var databaseHelper: DatabaseHelperInterface - @Mock lateinit var treatmentsInterface: TreatmentsInterface @Mock lateinit var danaRPlugin: DanaRPlugin @Mock lateinit var danaRKoreanPlugin: DanaRKoreanPlugin @Mock lateinit var danaRv2Plugin: DanaRv2Plugin @@ -49,7 +48,6 @@ open class DanaRTestBase : TestBase() { fun setup() { danaPump = DanaPump(aapsLogger, sp, dateUtil, injector) testPumpPlugin = TestPumpPlugin(injector) - `when`(activePluginProvider.activeTreatments).thenReturn(treatmentsInterface) `when`(activePluginProvider.activePump).thenReturn(testPumpPlugin) doNothing().`when`(danaRKoreanPlugin).setPluginEnabled(anyObject(), anyBoolean()) doNothing().`when`(danaRPlugin).setPluginEnabled(anyObject(), anyBoolean()) diff --git a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtendedTest.kt b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtendedTest.kt index e96a579585..fb2687ff6a 100644 --- a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtendedTest.kt +++ b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusBolusExtendedTest.kt @@ -5,7 +5,6 @@ import info.nightscout.androidaps.utils.T import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mockito.`when` import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @@ -13,12 +12,12 @@ class MsgStatusBolusExtendedTest : DanaRTestBase() { @Test fun runTest() { - `when`(activePluginProvider.activeTreatments).thenReturn(treatmentsInterface) val packet = MsgStatusBolusExtended(injector) // test message decoding val array = ByteArray(100) + putByteToArray(array, 0, 1) putByteToArray(array, 1, 1) packet.handleMessage(array) - Assert.assertEquals(T.mins(30).msecs() , danaPump.extendedBolusDuration) + Assert.assertEquals(T.mins(30).msecs(), danaPump.extendedBolusDuration) } } \ No newline at end of file diff --git a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusTempBasalTest.kt b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusTempBasalTest.kt index 5bcbe1db9f..f2a63b72ac 100644 --- a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusTempBasalTest.kt +++ b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusTempBasalTest.kt @@ -12,11 +12,10 @@ class MsgStatusTempBasalTest : DanaRTestBase() { @Test fun runTest() { val packet = MsgStatusTempBasal(injector) // test message decoding - // test message decoding packet.handleMessage(createArray(34, 1.toByte())) - Assert.assertEquals(true, danaPump.isTempBasalInProgress) + Assert.assertEquals(true, packet.isTempBasalInProgress) // passing an bigger number packet.handleMessage(createArray(34, 2.toByte())) - Assert.assertEquals(false, danaPump.isTempBasalInProgress) + Assert.assertEquals(false, packet.isTempBasalInProgress) } } \ No newline at end of file diff --git a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt index b92aa6e6c6..e1762ddc6d 100644 --- a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt +++ b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt @@ -48,7 +48,7 @@ class DanaRKoreanPluginTest : TestBaseWithProfile() { `when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s") `when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s") danaPump = DanaPump(aapsLogger, sp, dateUtil, injector) - danaRPlugin = DanaRKoreanPlugin(injector, aapsLogger, aapsSchedulers, rxBus, danaPump, context, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, dateUtil, pumpSync, fabricPrivacy) + danaRPlugin = DanaRKoreanPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, danaPump, dateUtil, fabricPrivacy, pumpSync) } @Test @Throws(Exception::class) diff --git a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt index a6794d7a83..bbdaececa1 100644 --- a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt +++ b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt @@ -25,7 +25,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) +@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class) class DanaRv2PluginTest : TestBaseWithProfile() { @Mock lateinit var context: Context @@ -51,7 +51,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() { `when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s") `when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s") danaPump = DanaPump(aapsLogger, sp, dateUtil, injector) - danaRv2Plugin = DanaRv2Plugin(injector, aapsLogger, aapsSchedulers, rxBus, context, danaPump, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, detailedBolusInfoStorage, temporaryBasalStorage, dateUtil, fabricPrivacy, pumpSync) + danaRv2Plugin = DanaRv2Plugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, danaPump,detailedBolusInfoStorage, temporaryBasalStorage, dateUtil, fabricPrivacy, pumpSync) } @Test diff --git a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEventsRv2Test.kt b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEventsRv2Test.kt index 2ee8a5e551..e76e29fa6e 100644 --- a/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEventsRv2Test.kt +++ b/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgHistoryEventsRv2Test.kt @@ -19,12 +19,12 @@ class MsgHistoryEventsRv2Test : DanaRTestBase() { // test message decoding val array = createArray(100, 2) - putByteToArray(array, 0, 0xFF.toByte()) - packet.handleMessage(array) - Assert.assertEquals(true, danaPump.historyDoneReceived) - // passing an bigger number putByteToArray(array, 0, 0x01.toByte()) packet.handleMessage(array) Assert.assertEquals(false, danaPump.historyDoneReceived) + + putByteToArray(array, 0, 0xFF.toByte()) + packet.handleMessage(array) + Assert.assertEquals(true, danaPump.historyDoneReceived) } } \ No newline at end of file diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt b/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt index 874e13ab25..f8f475f759 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_State.kt @@ -19,14 +19,18 @@ class DanaRS_Packet_Basal_Get_Temporary_Basal_State( aapsLogger.debug(LTag.PUMPCOMM, "Requesting temporary basal status") } + var isTempBasalInProgress: Boolean = false + var tempBasalTotalSec: Int = 0 + var tempBasalPercent: Int = 0 + override fun handleMessage(data: ByteArray) { val error = byteArrayToInt(getBytes(data, DATA_START, 1)) - val isTempBasalInProgress = byteArrayToInt(getBytes(data, DATA_START + 1, 1)) == 0x01 + isTempBasalInProgress = byteArrayToInt(getBytes(data, DATA_START + 1, 1)) == 0x01 val isAPSTempBasalInProgress = byteArrayToInt(getBytes(data, DATA_START + 1, 1)) == 0x02 - var tempBasalPercent = byteArrayToInt(getBytes(data, DATA_START + 2, 1)) + tempBasalPercent = byteArrayToInt(getBytes(data, DATA_START + 2, 1)) if (tempBasalPercent > 200) tempBasalPercent = (tempBasalPercent - 200) * 10 val durationHour = byteArrayToInt(getBytes(data, DATA_START + 3, 1)) - val tempBasalTotalSec: Int = if (durationHour == 150) 15 * 60 else if (durationHour == 160) 30 * 60 else durationHour * 60 * 60 + tempBasalTotalSec = if (durationHour == 150) 15 * 60 else if (durationHour == 160) 30 * 60 else durationHour * 60 * 60 val runningMin = byteArrayToInt(getBytes(data, DATA_START + 4, 2)) if (error != 0) failed = true val tempBasalRemainingMin = (danaPump.tempBasalTotalSec - runningMin * 60) / 60 diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt b/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt index a94216a90a..e3e6cb9e45 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_State.kt @@ -18,13 +18,15 @@ class DanaRS_Packet_Bolus_Get_Extended_Bolus_State( aapsLogger.debug(LTag.PUMPCOMM, "New message") } + var isExtendedInProgress: Boolean = false + override fun handleMessage(data: ByteArray) { var dataIndex = DATA_START var dataSize = 1 val error = byteArrayToInt(getBytes(data, dataIndex, dataSize)) dataIndex += dataSize dataSize = 1 - val isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01 + isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01 dataIndex += dataSize dataSize = 1 val extendedBolusDuration = T.mins(byteArrayToInt(getBytes(data, dataIndex, dataSize)) * 30L).msecs() diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt b/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt index d427520004..9f4a26da6f 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State.kt @@ -17,13 +17,15 @@ class DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State( aapsLogger.debug(LTag.PUMPCOMM, "New message") } + var isExtendedInProgress: Boolean = false + override fun handleMessage(data: ByteArray) { var dataIndex = DATA_START var dataSize = 1 val extendedMenuOption = byteArrayToInt(getBytes(data, dataIndex, dataSize)) dataIndex += dataSize dataSize = 1 - val isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01 + isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01 aapsLogger.debug(LTag.PUMPCOMM, "extendedMenuOption: $extendedMenuOption") } diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSPluginTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSPluginTest.kt index 9276960e96..61f2ea5d53 100644 --- a/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSPluginTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSPluginTest.kt @@ -23,7 +23,7 @@ import org.powermock.modules.junit4.PowerMockRunner @Suppress("SpellCheckingInspection") @RunWith(PowerMockRunner::class) -@PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, DetailedBolusInfoStorage::class) +@PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class) class DanaRSPluginTest : DanaRSTestBase() { @Mock lateinit var context: Context diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSTestBase.kt b/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSTestBase.kt index e641f0139c..05b06d4fca 100644 --- a/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSTestBase.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSTestBase.kt @@ -5,7 +5,6 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.comm.DanaRS_Packet -import info.nightscout.androidaps.db.TemporaryBasal import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Before import org.mockito.ArgumentMatchers @@ -16,16 +15,7 @@ open class DanaRSTestBase : TestBaseWithProfile() { @Mock lateinit var sp: SP - val injector = HasAndroidInjector { - AndroidInjector { - if (it is TemporaryBasal) { - it.aapsLogger = aapsLogger - it.activePlugin = activePluginProvider - it.profileFunction = profileFunction - it.sp = sp - } - } - } + val injector = HasAndroidInjector { AndroidInjector { } } lateinit var danaPump: DanaPump diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsHistoryEventsTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsHistoryEventsTest.kt index c87f4b64dc..9f55683786 100644 --- a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsHistoryEventsTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsHistoryEventsTest.kt @@ -20,7 +20,7 @@ import org.powermock.modules.junit4.PowerMockRunner import java.util.* @RunWith(PowerMockRunner::class) -@PrepareForTest(RxBusWrapper::class, DetailedBolusInfoStorage::class, DanaRSPlugin::class) +@PrepareForTest(RxBusWrapper::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class, DanaRSPlugin::class) class DanaRsPacketApsHistoryEventsTest : DanaRSTestBase() { @Mock lateinit var context: Context diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetTemporaryBasalStateTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetTemporaryBasalStateTest.kt index 86bf509924..e29ed61b41 100644 --- a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetTemporaryBasalStateTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetTemporaryBasalStateTest.kt @@ -34,9 +34,9 @@ class DanaRsPacketBasalGetTemporaryBasalStateTest : DanaRSTestBase() { putIntToArray(array, 4, 1) packet.handleMessage(array) Assert.assertTrue(packet.failed) - Assert.assertTrue(danaPump.isTempBasalInProgress) - Assert.assertEquals(300, danaPump.tempBasalPercent) - Assert.assertEquals(15 * 60, danaPump.tempBasalTotalSec) + Assert.assertTrue(packet.isTempBasalInProgress) + Assert.assertEquals(300, packet.tempBasalPercent) + Assert.assertEquals(15 * 60, packet.tempBasalTotalSec) Assert.assertEquals("BASAL__TEMPORARY_BASAL_STATE", packet.friendlyName) } } \ No newline at end of file diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetDualBolusTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetDualBolusTest.kt index 5f04609ec5..9de5e53cb8 100644 --- a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetDualBolusTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetDualBolusTest.kt @@ -33,7 +33,6 @@ class DanaRsPacketBolusGetDualBolusTest : DanaRSTestBase() { packet.handleMessage(array) Assert.assertTrue(packet.failed) Assert.assertEquals(1.0, danaPump.bolusStep, 0.0) - Assert.assertEquals(0.55, danaPump.extendedBolusAbsoluteRate, 0.0) Assert.assertEquals(40.0, danaPump.maxBolus, 0.0) Assert.assertEquals("BOLUS__GET_DUAL_BOLUS", packet.friendlyName) diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedBolusStateTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedBolusStateTest.kt index c74b203ff5..759b35e527 100644 --- a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedBolusStateTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedBolusStateTest.kt @@ -31,7 +31,7 @@ class DanaRsPacketBolusGetExtendedBolusStateTest : DanaRSTestBase() { testValue = 1.0 packet.handleMessage(createArray(11, testValue.toInt().toByte())) // is extended bolus in progress - Assert.assertEquals(testValue == 1.0, danaPump.isExtendedInProgress) + Assert.assertEquals(testValue == 1.0, packet.isExtendedInProgress) Assert.assertEquals(testValue != 0.0, packet.failed) Assert.assertEquals("BOLUS__GET_EXTENDED_BOLUS_STATE", packet.friendlyName) } diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedMenuOptionStateTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedMenuOptionStateTest.kt index db66481f5a..50921c5ea5 100644 --- a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedMenuOptionStateTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedMenuOptionStateTest.kt @@ -26,10 +26,10 @@ class DanaRsPacketBolusGetExtendedMenuOptionStateTest : DanaRSTestBase() { // test message decoding packet.handleMessage(createArray(34, 0.toByte())) // isExtendedInProgress should be false - Assert.assertEquals(false, danaPump.isExtendedInProgress) + Assert.assertEquals(false, packet.isExtendedInProgress) // assertEquals(false, packet.failed); packet.handleMessage(createArray(34, 1.toByte())) - Assert.assertEquals(true, danaPump.isExtendedInProgress) + Assert.assertEquals(true, packet.isExtendedInProgress) Assert.assertEquals("BOLUS__GET_EXTENDED_MENU_OPTION_STATE", packet.friendlyName) } } \ No newline at end of file diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetStepBolusStartTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetStepBolusStartTest.kt index 9bc907d7c2..224dd6fee2 100644 --- a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetStepBolusStartTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetStepBolusStartTest.kt @@ -21,7 +21,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) +@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class) class DanaRsPacketBolusSetStepBolusStartTest : DanaRSTestBase() { @Mock lateinit var constraintChecker: ConstraintChecker diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetMoreInformationTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetMoreInformationTest.kt index f21ae1b563..957553475f 100644 --- a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetMoreInformationTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetMoreInformationTest.kt @@ -44,8 +44,6 @@ class DanaRsPacketGeneralGetMoreInformationTest : DanaRSTestBase() { Assert.assertFalse(packet.failed) Assert.assertEquals(6.0, danaPump.iob, 0.01) Assert.assertEquals(12.5, danaPump.dailyTotalUnits, 0.01) - Assert.assertTrue(danaPump.isExtendedInProgress) - Assert.assertEquals(150, danaPump.extendedBolusRemainingMinutes) val lastBolus = Calendar.getInstance() lastBolus.timeInMillis = danaPump.lastBolusTime Assert.assertEquals(15, lastBolus.get(Calendar.HOUR_OF_DAY)) diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyDeliveryRateDisplayTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyDeliveryRateDisplayTest.kt index 1e039e0fda..b8318b686f 100644 --- a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyDeliveryRateDisplayTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyDeliveryRateDisplayTest.kt @@ -24,7 +24,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, DetailedBolusInfoStorage::class) +@PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class) class DanaRsPacketNotifyDeliveryRateDisplayTest : DanaRSTestBase() { @Mock lateinit var activePlugin: ActivePluginProvider diff --git a/database/src/main/java/info/nightscout/androidaps/database/serialisation/SealedClassHelper.kt b/database/src/main/java/info/nightscout/androidaps/database/serialisation/SealedClassHelper.kt index bf1fc4ab6c..704819908e 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/serialisation/SealedClassHelper.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/serialisation/SealedClassHelper.kt @@ -33,6 +33,7 @@ object SealedClassHelper { val x = gson.fromJson(jsonReader, innerClass.javaObjectType) jsonReader.endObject() // if there a static object, actually return that + @Suppress("UNCHECKED_CAST") return innerClass.objectInstance as T? ?: x } diff --git a/omnipod-eros/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPluginTest.java b/omnipod-eros/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPluginTest.java index 0bb6fe6d8e..d3a246ffe0 100644 --- a/omnipod-eros/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPluginTest.java +++ b/omnipod-eros/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPluginTest.java @@ -68,9 +68,10 @@ public class OmnipodErosPumpPluginTest { OmnipodErosPumpPlugin plugin = new OmnipodErosPumpPlugin(injector, aapsLogger, new TestAapsSchedulers(), rxBusWrapper, null, resourceHelper, activePluginProvider, null, null, aapsOmnipodErosManager, commandQueueProvider, null, null, null, null, - rileyLinkUtil, null, null, null + rileyLinkUtil, null, null, pumpSync ); - when(pumpSync.expectedPumpState().getTemporaryBasal()).thenReturn(null); + PumpSync.PumpState pumpState = new PumpSync.PumpState(null, null, null, null); + when(pumpSync.expectedPumpState()).thenReturn(pumpState); when(rileyLinkUtil.getRileyLinkHistory()).thenReturn(new ArrayList<>()); when(injector.androidInjector()).thenReturn(instance -> { });