Update unit tests, cleanup

This commit is contained in:
jbr7rr 2023-05-28 19:50:00 +02:00
parent d8427c6d56
commit 37a6a4f271
21 changed files with 171 additions and 50 deletions

View file

@ -1,7 +1,6 @@
package info.nightscout.pump.medtrum
import android.util.Base64
import info.nightscout.interfaces.profile.Instantiator
import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.pump.PumpSync
import info.nightscout.interfaces.pump.TemporaryBasalStorage
@ -123,7 +122,7 @@ class MedtrumPump @Inject constructor(
set(value) {
_actualBasalProfile = value
val encodedString = Base64.encodeToString(value, Base64.DEFAULT)
sp.putString(R.string.key_actual_basal_profile, encodedString)
sp.putString(R.string.key_actual_basal_profile, encodedString?: "")
}
private var _lastBasalType: MutableStateFlow<BasalType> = MutableStateFlow(BasalType.NONE)
@ -311,7 +310,7 @@ class MedtrumPump @Inject constructor(
LTag.PUMP,
"handleBasalStatusUpdate: basalType: $basalType basalValue: $basalRate basalSequence: $basalSequence basalPatchId: $basalPatchId basalStartTime: $basalStartTime " + "receivedTime: $receivedTime"
)
val expectedTemporaryBasal = pumpSync.expectedPumpState().temporaryBasal
val expectedTemporaryBasal = pumpSync.expectedPumpState()?.temporaryBasal
if (basalType.isTempBasal() && expectedTemporaryBasal?.pumpId != basalStartTime) {
// Note: temporaryBasalInfo will be removed from temporaryBasalStorage after this call
val temporaryBasalInfo = temporaryBasalStorage.findTemporaryBasal(basalStartTime, basalRate)
@ -330,7 +329,7 @@ class MedtrumPump @Inject constructor(
)
aapsLogger.debug(
LTag.PUMPCOMM,
"handleBasalStatusUpdate: ${if (newRecord) "**NEW** " else ""}EVENT TEMP_START ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) " + "Rate: $basalRate Duration: ${duration}"
"handleBasalStatusUpdate: ${if (newRecord) "**NEW** " else ""}EVENT TEMP_START ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) " + "Rate: $basalRate Duration: ${duration} temporaryBasalInfo: $temporaryBasalInfo, expectedTemporaryBasal: $expectedTemporaryBasal"
)
} else if (basalType.isSuspendedByPump() && expectedTemporaryBasal?.pumpId != basalStartTime) {
val newRecord = pumpSync.syncTemporaryBasalWithPumpId(
@ -345,7 +344,7 @@ class MedtrumPump @Inject constructor(
)
aapsLogger.debug(
LTag.PUMPCOMM,
"handleBasalStatusUpdate: ${if (newRecord) "**NEW** " else ""}EVENT TEMP_END ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime)"
"handleBasalStatusUpdate: ${if (newRecord) "**NEW** " else ""}EVENT TEMP_START ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) expectedTemporaryBasal: $expectedTemporaryBasal"
)
} else if (basalType == BasalType.NONE && expectedTemporaryBasal?.pumpId != basalStartTime) { // Also some sort of suspend or unkown by pump
val newRecord = pumpSync.syncTemporaryBasalWithPumpId(
@ -360,7 +359,7 @@ class MedtrumPump @Inject constructor(
)
aapsLogger.debug(
LTag.PUMPCOMM,
"handleBasalStatusUpdate: ${if (newRecord) "**NEW** " else ""}EVENT TEMP_END ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime)"
"handleBasalStatusUpdate: ${if (newRecord) "**NEW** " else ""}EVENT TEMP_START ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) expectedTemporaryBasal: $expectedTemporaryBasal"
)
}

View file

@ -1,8 +1,5 @@
package info.nightscout.pump.medtrum.comm
import info.nightscout.pump.medtrum.encryption.Crypt
class WriteCommandPackets(data: ByteArray, sequenceNumber: Int) {
private val CRC_8_TABLE: IntArray = intArrayOf(0, 155, 173, 54, 193, 90, 108, 247, 25, 130, 180, 47, 216, 67, 117, 238, 50, 169, 159, 4, 243, 104, 94, 197, 43, 176, 134, 29, 234, 113, 71, 220, 100, 255, 201, 82, 165, 62, 8, 147, 125, 230, 208, 75, 188, 39, 17, 138, 86, 205, 251, 96, 151, 12, 58, 161, 79, 212, 226, 121, 142, 21, 35, 184, 200, 83, 101, 254, 9, 146, 164, 63, 209, 74, 124, 231, 16, 139, 189, 38, 250, 97, 87, 204, 59, 160, 150, 13, 227, 120, 78, 213, 34, 185, 143, 20, 172, 55, 1, 154, 109, 246, 192, 91, 181, 46, 24, 131, 116, 239, 217, 66, 158, 5, 51, 168, 95, 196, 242, 105, 135, 28, 42, 177, 70, 221, 235, 112, 11, 144, 166, 61, 202, 81, 103, 252, 18, 137, 191, 36, 211, 72, 126, 229, 57, 162, 148, 15, 248, 99, 85, 206, 32, 187, 141, 22, 225, 122, 76, 215, 111, 244, 194, 89, 174, 53, 3, 152, 118, 237, 219, 64, 183, 44, 26, 129, 93, 198, 240, 107, 156, 7, 49, 170, 68, 223, 233, 114, 133, 30, 40, 179, 195, 88, 110, 245, 2, 153, 175, 52, 218, 65, 119, 236, 27, 128, 182, 45, 241, 106, 92, 199, 48, 171, 157, 6, 232, 115, 69, 222, 41, 178, 132, 31, 167, 60, 10, 145, 102, 253, 203, 80, 190, 37, 19, 136, 127, 228, 210, 73, 149, 14, 56, 163, 84, 207, 249, 98, 140, 23, 33, 186, 77, 214, 224, 123)

View file

@ -99,7 +99,6 @@ class ActivatePacket(injector: HasAndroidInjector, private val basalProfile: Byt
medtrumPump.syncedSequenceNumber = basalSequence // We are activated, reset the synced seq nr ()
// Update the actual basal profile
medtrumPump.actualBasalProfile = basalProfile
// TODO: Handle history entry
medtrumPump.handleBasalStatusUpdate(basalType, basalValue, basalSequence, basalPatchId, basalStartTime, time)
// Update the pump in the database, technically this is not a new pump only new patch, but still TBR's etc need to be cannceled

View file

@ -2,12 +2,10 @@ package info.nightscout.pump.medtrum.comm.packets
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumPump
import info.nightscout.pump.medtrum.comm.enums.CommandType
import info.nightscout.pump.medtrum.comm.enums.CommandType.AUTH_REQ
import info.nightscout.pump.medtrum.encryption.Crypt
import info.nightscout.pump.medtrum.extension.toByteArray
import info.nightscout.pump.medtrum.extension.toInt
import info.nightscout.rx.logging.LTag
import javax.inject.Inject
class AuthorizePacket(injector: HasAndroidInjector) : MedtrumPacket(injector) {

View file

@ -7,7 +7,6 @@ import info.nightscout.pump.medtrum.comm.enums.BasalType
import info.nightscout.pump.medtrum.extension.toInt
import info.nightscout.pump.medtrum.extension.toLong
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
import info.nightscout.rx.logging.LTag
import javax.inject.Inject
class CancelTempBasalPacket(injector: HasAndroidInjector) : MedtrumPacket(injector) {

View file

@ -14,7 +14,6 @@ import info.nightscout.pump.medtrum.extension.toLong
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.utils.DateUtil
import info.nightscout.shared.utils.T
import javax.inject.Inject
class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int) : MedtrumPacket(injector) {

View file

@ -4,14 +4,12 @@ import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumPump
import info.nightscout.pump.medtrum.comm.enums.BasalType
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
import info.nightscout.pump.medtrum.extension.toByteArray
import info.nightscout.pump.medtrum.extension.toInt
import info.nightscout.pump.medtrum.extension.toLong
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import javax.inject.Inject
import kotlin.experimental.and
class NotificationPacket(val injector: HasAndroidInjector) {
@ -107,7 +105,7 @@ class NotificationPacket(val injector: HasAndroidInjector) {
if (fieldMask and MASK_EXTENDED_BOLUS != 0) {
aapsLogger.error(LTag.PUMPCOMM, "Extended bolus notification received, extended bolus not supported!")
// TODO Handle error and stop pump if this happens
// TODO Handle error and stop pump if this happens?
offset += 3
}
@ -144,7 +142,6 @@ class NotificationPacket(val injector: HasAndroidInjector) {
if (fieldMask and MASK_LIFE_TIME != 0) {
aapsLogger.debug(LTag.PUMPCOMM, "Life time notification received")
// TODO Check if timezone offset needs to be added
medtrumPump.patchAge = data.copyOfRange(offset, offset + 4).toLong()
aapsLogger.debug(LTag.PUMPCOMM, "Patch age: ${medtrumPump.patchAge}")
offset += 4
@ -162,7 +159,6 @@ class NotificationPacket(val injector: HasAndroidInjector) {
if (fieldMask and MASK_STORAGE != 0) {
aapsLogger.debug(LTag.PUMPCOMM, "Storage notification received")
// TODO, trigger check for new sequence?
val sequence = data.copyOfRange(offset, offset + 2).toInt()
if (sequence > medtrumPump.currentSequenceNumber) {
medtrumPump.currentSequenceNumber = sequence

View file

@ -4,6 +4,8 @@ import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.comm.enums.CommandType.READ_BOLUS_STATE
class ReadBolusStatePacket(injector: HasAndroidInjector) : MedtrumPacket(injector) {
// UNUSED
// Bolus sync is currently done by getting the records and syncing then with AAPS pumpSync there
var bolusData: ByteArray = byteArrayOf()
@ -20,7 +22,7 @@ class ReadBolusStatePacket(injector: HasAndroidInjector) : MedtrumPacket(injecto
override fun handleResponse(data: ByteArray): Boolean {
val success = super.handleResponse(data)
if (success) {
// TODO: Handle bolus data here
// UNUSED
bolusData = data.copyOfRange(RESP_BOLUS_DATA_START, data.size)
}

View file

@ -50,8 +50,6 @@ class SetBasalProfilePacket(injector: HasAndroidInjector, private val basalProfi
// Update the actual basal profile
medtrumPump.actualBasalProfile = basalProfile
// TODO: Do we need to let AAPS know? Maybe depends on where we cancel TBR if we need to
// TODO: Handle history entry
medtrumPump.handleBasalStatusUpdate(basalType, basalValue, basalSequence, basalPatchId, basalStartTime)
}
return success

View file

@ -5,12 +5,13 @@ import info.nightscout.pump.medtrum.comm.enums.CommandType.SET_BOLUS_MOTOR
class SetBolusMotorPacket(injector: HasAndroidInjector) : MedtrumPacket(injector) {
// UNUSED in our driver
init {
opCode = SET_BOLUS_MOTOR.code
}
override fun getRequest(): ByteArray {
// TODO CHECK! Seems to be a feature? to set the bolus to vibrate? TEST!
return byteArrayOf(opCode) + 0.toByte()
}
}

View file

@ -60,11 +60,6 @@ class SetTempBasalPacket(injector: HasAndroidInjector, private val absoluteRate:
val basalStartTime = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(RESP_BASAL_START_TIME_START, RESP_BASAL_START_TIME_END).toLong())
aapsLogger.debug(LTag.PUMPCOMM, "Basal status update: type=$basalType, rate=$basalRate, sequence=$basalSequence, patchId=$basalPatchId, startTime=$basalStartTime, rawTime=$rawTime")
// TODO: For debugging remove later
val pumpTime = MedtrumTimeUtil().getCurrentTimePumpSeconds()
val systemTime = System.currentTimeMillis()
aapsLogger.debug(LTag.PUMPCOMM, "Pump time: $pumpTime, System time: $systemTime")
medtrumPump.handleBasalStatusUpdate(basalType, basalRate, basalSequence, basalPatchId, basalStartTime)
}
return success

View file

@ -6,7 +6,6 @@ import info.nightscout.pump.medtrum.comm.enums.CommandType.SYNCHRONIZE
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
import info.nightscout.pump.medtrum.extension.toByteArray
import info.nightscout.pump.medtrum.extension.toInt
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import javax.inject.Inject

View file

@ -2,9 +2,14 @@ package info.nightscout.pump.medtrum
import info.nightscout.core.extensions.pureProfileFromJson
import info.nightscout.core.profile.ProfileSealed
import info.nightscout.shared.utils.DateUtil
import org.json.JSONObject
import org.junit.jupiter.api.Test
import org.junit.Assert.*
import org.mockito.Mock
import org.mockito.Mockito.spy
import org.mockito.Mockito.`when`
import org.mockito.kotlin.any
class MedtrumPumpTest : MedtrumTestBase() {
@ -49,4 +54,38 @@ class MedtrumPumpTest : MedtrumTestBase() {
// Expected values
assertNull(result)
}
@Test fun getCurrentHourlyBasalFromMedtrumProfileArrayGivenProfileWhenValuesSetThenReturnCorrectValue() {
// Inputs
// Basal profile with 7 elements:
// 00:00 : 2.1
// 04:00 : 1.9
// 06:00 : 1.7
// 08:00 : 1.5
// 16:00 : 1.6
// 21:00 : 1.7
// 23:00 : 2
val profileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\"," +
"\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"},{\"time\":\"02:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\"," +
"\"basal\":[{\"time\":\"00:00\",\"value\":\"2.1\"},{\"time\":\"04:00\",\"value\":\"1.9\"},{\"time\":\"06:00\",\"value\":\"1.7\"}," +
"{\"time\":\"08:00\",\"value\":\"1.5\"},{\"time\":\"16:00\",\"value\":\"1.6\"},{\"time\":\"21:00\",\"value\":\"1.7\"},{\"time\":\"23:00\",\"value\":\"2\"}]," +
"\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
val profile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(profileJSON), dateUtil)!!)
val profileArray = medtrumPump.buildMedtrumProfileArray(profile)
// For 03:59
`when`(dateUtil.dateAndTimeString((any()))).thenReturn("2023-01-01T03:59:00.000Z")
val result = medtrumPump.getCurrentHourlyBasalFromMedtrumProfileArray(profileArray!!)
assertEquals(2.1, result, 0.01)
// For 23:59
`when`(dateUtil.dateAndTimeString((any()))).thenReturn("2023-01-01T23:59:59.999Z")
val result1 = medtrumPump.getCurrentHourlyBasalFromMedtrumProfileArray(profileArray!!)
assertEquals(2.0, result1, 0.01)
// For 00:00
`when`(dateUtil.dateAndTimeString((any()))).thenReturn("2023-01-01T00:00:00.000Z")
val result2 = medtrumPump.getCurrentHourlyBasalFromMedtrumProfileArray(profileArray!!)
assertEquals(2.1, result2, 0.01)
}
}

View file

@ -4,6 +4,7 @@ import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.comm.enums.AlarmSetting
import info.nightscout.pump.medtrum.comm.enums.BasalType
import org.junit.jupiter.api.Test
import org.junit.Assert.*
@ -56,12 +57,12 @@ class ActivatePacketTest : MedtrumTestBase() {
// Expected values
val expectedPatchId = 41L
val expectedTime = 1675605528L
val exptectedBasalType = 1
val expectedTime = 1675605528000L
val exptectedBasalType = BasalType.STANDARD
val expectedBasalRate = 1.5
val expectedBasalSequence = 1
val expectedBasalPatchId = 41
val expectedBasalStart = 1675605528L
val expectedBasalPatchId = 41L
val expectedBasalStart = 1675605528000L
assertEquals(true, result)
assertEquals(expectedPatchId, medtrumPump.patchId)

View file

@ -3,6 +3,7 @@ package info.nightscout.pump.medtrum.comm.packets
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.comm.enums.BasalType
import org.junit.jupiter.api.Test
import org.junit.Assert.*
@ -41,11 +42,11 @@ class CancelTempBasalPacketTest : MedtrumTestBase() {
val result = packet.handleResponse(repsonse)
// Expected values
val expectedBasalType = 1
val expectedBasalType = BasalType.STANDARD
val expectedBasalRate = 1.1
val expectedBasalSequence = 3
val expectedStartTime = 1679575392L
val expectedPatchId = 146
val expectedStartTime = 1679575392000L
val expectedPatchId = 146L
assertTrue(result)
assertEquals(expectedBasalType, medtrumPump.lastBasalType)

View file

@ -35,12 +35,28 @@ class GetRecordPacketTest : MedtrumTestBase() {
}
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
assertTrue(false)
// TODO: Implement history and test
// Inputs
val data = byteArrayOf(35, 99, 9, 1, 0, 0, -86, 28, 2, -1, -5, -40, -27, -18, 14, 0, -64, 1, -91, -20, -82, 17, -91, -20, -82, 17, 1, 0, 26, 0, 0, 0, -102, 0, -48)
// Call
val packet = GetRecordPacket(packetInjector, 0)
val result = packet.handleResponse(data)
// Expected values
assertEquals(true, result)
assertEquals(false, packet.failed)
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
assertTrue(false)
// TODO: Implement history and test
// Inputs
val data = byteArrayOf(35, 99, 9, 1, 0, 0, -86, 28, 2, -1, -5, -40, -27, -18, 14, 0, -64)
// Call
val packet = GetRecordPacket(packetInjector, 0)
val result = packet.handleResponse(data)
// Expected values
assertEquals(false, result)
assertEquals(true, packet.failed)
}
}

View file

@ -3,8 +3,10 @@ package info.nightscout.pump.medtrum.comm.packets
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.comm.enums.BasalType
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
import info.nightscout.pump.medtrum.extension.toByteArray
import info.nightscout.rx.events.EventOverviewBolusProgress
import org.junit.jupiter.api.Test
import org.junit.Assert.*
@ -32,8 +34,59 @@ class NotificationPacketTest : MedtrumTestBase() {
assertEquals(medtrumPump.pumpState, MedtrumPumpState.fromByte(state))
}
@Test fun handleMaskedMessageGivenMaskAndDataThenDataSaved() {
// TODO: Implement
assertTrue(false)
@Test fun handleNotificationGivenBasalDataThenDataSaved() {
// Inputs
val data = byteArrayOf(32, 40, 64, 6, 25, 0, 14, 0, 84, -93, -83, 17, 17, 64, 0, -104, 14, 0, 16)
// Call
NotificationPacket(packetInjector).handleNotification(data)
// Expected values
assertEquals(BasalType.ABSOLUTE_TEMP, medtrumPump.lastBasalType)
assertEquals(0.85, medtrumPump.lastBasalRate, 0.01)
assertEquals(25, medtrumPump.lastBasalSequence)
assertEquals(14, medtrumPump.lastBasalPatchId)
assertEquals(1685126612000, medtrumPump.lastBasalStartTime)
assertEquals(186.80, medtrumPump.reservoir, 0.01)
}
@Test fun handleNotificationGivenSequenceAndOtherDataThenDataSaved() {
// Inputs
val data = byteArrayOf(32, 0, 17, -89, 0, 14, 0, 0, 0, 0, 0, 0)
// Call
NotificationPacket(packetInjector).handleNotification(data)
// Expected values
assertEquals(167, medtrumPump.currentSequenceNumber)
// TODO: Test error notif on wrong patch id
}
@Test fun handleNotificationGivenBolusInProgressThenDataSaved() {
// Inputs
val data = byteArrayOf(32, 34, 16, 0, 3, 0, -58, 12, 0, 0, 0, 0, 0)
medtrumPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, false, 1)
// Call
NotificationPacket(packetInjector).handleNotification(data)
// Expected values
assertEquals(false, medtrumPump.bolusDone)
assertEquals(0.15, medtrumPump.bolusingTreatment!!.insulin, 0.01)
assertEquals(163.5, medtrumPump.reservoir, 0.01)
}
@Test fun handleNotificationGivenBolusFinnishedThenDataSaved() {
// Inputs
val data = byteArrayOf(32, 34, 17, -128, 33, 0, -89, 12, -80, 0, 14, 0, 0, 0, 0, 0, 0)
medtrumPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, false, 1)
// Call
NotificationPacket(packetInjector).handleNotification(data)
// Expected values
assertEquals(true, medtrumPump.bolusDone)
assertEquals(1.65, medtrumPump.bolusingTreatment!!.insulin, 0.01)
assertEquals(161.95, medtrumPump.reservoir, 0.01)
}
}

View file

@ -3,6 +3,7 @@ package info.nightscout.pump.medtrum.comm.packets
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.comm.enums.BasalType
import org.junit.jupiter.api.Test
import org.junit.Assert.*
@ -43,11 +44,11 @@ class SetBasalProfilePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(repsonse)
// Expected values
val expectedBasalType = 1
val expectedBasalType = BasalType.STANDARD
val expectedBasalRate = 1.1
val expectedBasalSequence = 3
val expectedStartTime = 1679575392L
val expectedPatchId = 146
val expectedStartTime = 1679575392000L
val expectedPatchId = 146L
assertTrue(result)
assertEquals(expectedBasalType, medtrumPump.lastBasalType)

View file

@ -3,6 +3,7 @@ package info.nightscout.pump.medtrum.comm.packets
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.comm.enums.BasalType
import org.junit.jupiter.api.Test
import org.junit.Assert.*
@ -45,11 +46,11 @@ class SetTempBasalPacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
val expectedBasalType = 6
val expectedBasalType = BasalType.ABSOLUTE_TEMP
val expectedBasalRate = 1.25
val expectedBasalSequence = 2
val expectedStartTime = 1679575112L
val expectedPatchId = 146
val expectedStartTime = 1679575112000L
val expectedPatchId = 146L
assertTrue(result)
assertEquals(expectedBasalType, medtrumPump.lastBasalType)

View file

@ -41,7 +41,7 @@ class StopPatchPacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
val expectedPatchId = 146
val expectedPatchId = 146L
val expectedStopSequence = 23
assertEquals(expectedPatchId, medtrumPump.lastStopPatchId)
assertEquals(expectedStopSequence, medtrumPump.lastStopSequence)

View file

@ -2,7 +2,10 @@ package info.nightscout.pump.medtrum.comm.packets
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.interfaces.pump.PumpSync
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.comm.enums.BasalType
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
import info.nightscout.pump.medtrum.extension.toByteArray
import org.junit.jupiter.api.Test
import org.junit.Assert.*
@ -73,4 +76,28 @@ class SynchronizePacketTest : MedtrumTestBase() {
assertEquals(false, result)
assertEquals(true, packet.failed)
}
@Test fun handleResponseContainingSyncDataThenDataSaved() {
// Inputs
val data = byteArrayOf(47, 3, 3, 1, 0, 0, 32, -18, 13, -128, 5, 0, -128, 0, 0, 6, 25, 0, 14, 0, 84, -93, -83, 17, 17, 64, 0, -104, 14, -8, -119, -83, 17, -16, 11, 90, 26, 0, 14, 0, -69, 31, 0, 0, -116, 14, -56)
// Call
val packet = SynchronizePacket(packetInjector)
val result = packet.handleResponse(data)
// Expected values
assertEquals(true, result)
assertEquals(false, packet.failed)
assertEquals(MedtrumPumpState.ACTIVE, packet.medtrumPump.pumpState)
assertEquals(BasalType.ABSOLUTE_TEMP, packet.medtrumPump.lastBasalType)
assertEquals(0.85, packet.medtrumPump.lastBasalRate, 0.01)
assertEquals(25, packet.medtrumPump.lastBasalSequence)
assertEquals(14, packet.medtrumPump.lastBasalPatchId)
assertEquals(1685126612000, packet.medtrumPump.lastBasalStartTime)
assertEquals(186.80, packet.medtrumPump.reservoir, 0.01)
assertEquals(296585720, packet.medtrumPump.patchAge)
assertEquals(5.96875, packet.medtrumPump.batteryVoltage_A, 0.01)
assertEquals(2.8125, packet.medtrumPump.batteryVoltage_B, 0.01)
assertEquals(1388542523000, packet.medtrumPump.patchStartTime)
}
}