Show ref no instead of raw pumpType value

This commit is contained in:
jbr7rr 2024-01-21 13:20:10 +01:00 committed by Casper V. Kristensen
parent 3a82e9c10f
commit 194cecce16
8 changed files with 52 additions and 44 deletions

View file

@ -53,6 +53,7 @@ import app.aaps.core.ui.toast.ToastUtils
import app.aaps.core.validators.ValidatingEditTextPreference import app.aaps.core.validators.ValidatingEditTextPreference
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
import info.nightscout.pump.medtrum.comm.enums.ModelType
import info.nightscout.pump.medtrum.services.MedtrumService import info.nightscout.pump.medtrum.services.MedtrumService
import info.nightscout.pump.medtrum.ui.MedtrumOverviewFragment import info.nightscout.pump.medtrum.ui.MedtrumOverviewFragment
import info.nightscout.pump.medtrum.util.MedtrumSnUtil import info.nightscout.pump.medtrum.util.MedtrumSnUtil
@ -153,7 +154,7 @@ import kotlin.math.abs
override fun afterTextChanged(newValue: Editable?) { override fun afterTextChanged(newValue: Editable?) {
val newSN = newValue?.toString()?.toLongOrNull(radix = 16) ?: 0 val newSN = newValue?.toString()?.toLongOrNull(radix = 16) ?: 0
val newDeviceType = MedtrumSnUtil().getDeviceTypeFromSerial(newSN) val newDeviceType = MedtrumSnUtil().getDeviceTypeFromSerial(newSN)
editText.error = if (newDeviceType == MedtrumSnUtil.INVALID) { editText.error = if (newDeviceType == ModelType.INVALID) {
rh.gs(R.string.sn_input_invalid) rh.gs(R.string.sn_input_invalid)
} else { } else {
null null
@ -174,7 +175,7 @@ import kotlin.math.abs
val newDeviceType = MedtrumSnUtil().getDeviceTypeFromSerial(newSN) val newDeviceType = MedtrumSnUtil().getDeviceTypeFromSerial(newSN)
when { when {
newDeviceType == MedtrumSnUtil.INVALID -> { newDeviceType == ModelType.INVALID -> {
preferenceFragment.activity?.let { activity -> preferenceFragment.activity?.let { activity ->
OKDialog.show(activity, rh.gs(R.string.sn_input_title), rh.gs(R.string.sn_input_invalid)) OKDialog.show(activity, rh.gs(R.string.sn_input_title), rh.gs(R.string.sn_input_invalid))
} }
@ -183,7 +184,7 @@ import kotlin.math.abs
medtrumPump.pumpType(newDeviceType) == PumpType.MEDTRUM_UNTESTED -> { medtrumPump.pumpType(newDeviceType) == PumpType.MEDTRUM_UNTESTED -> {
preferenceFragment.activity?.let { activity -> preferenceFragment.activity?.let { activity ->
OKDialog.show(activity, rh.gs(R.string.sn_input_title), rh.gs(R.string.pump_unsupported, newDeviceType)) OKDialog.show(activity, rh.gs(R.string.sn_input_title), rh.gs(R.string.pump_unsupported, newDeviceType.toString()))
} }
false false
} }

View file

@ -18,6 +18,7 @@ import info.nightscout.pump.medtrum.comm.enums.AlarmSetting
import info.nightscout.pump.medtrum.comm.enums.AlarmState import info.nightscout.pump.medtrum.comm.enums.AlarmState
import info.nightscout.pump.medtrum.comm.enums.BasalType import info.nightscout.pump.medtrum.comm.enums.BasalType
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
import info.nightscout.pump.medtrum.comm.enums.ModelType
import info.nightscout.pump.medtrum.extension.toByteArray import info.nightscout.pump.medtrum.extension.toByteArray
import info.nightscout.pump.medtrum.extension.toInt import info.nightscout.pump.medtrum.extension.toInt
import info.nightscout.pump.medtrum.util.MedtrumSnUtil import info.nightscout.pump.medtrum.util.MedtrumSnUtil
@ -291,13 +292,13 @@ class MedtrumPump @Inject constructor(
var desiredPumpWarning = true var desiredPumpWarning = true
var desiredPumpWarningExpiryThresholdHours = 72L var desiredPumpWarningExpiryThresholdHours = 72L
fun pumpType(): PumpType = pumpType(deviceType) fun pumpType(): PumpType = pumpType(ModelType.fromValue(deviceType))
fun pumpType(type: Int): PumpType = fun pumpType(type: ModelType): PumpType =
when (type) { when (type) {
MedtrumSnUtil.MD_0201, MedtrumSnUtil.MD_8201 -> PumpType.MEDTRUM_NANO ModelType.MD0201, ModelType.MD8201 -> PumpType.MEDTRUM_NANO
MedtrumSnUtil.MD_8301 -> PumpType.MEDTRUM_300U ModelType.MD8301 -> PumpType.MEDTRUM_300U
else -> PumpType.MEDTRUM_UNTESTED else -> PumpType.MEDTRUM_UNTESTED
} }
fun loadVarsFromSP() { fun loadVarsFromSP() {

View file

@ -0,0 +1,17 @@
package info.nightscout.pump.medtrum.comm.enums
enum class ModelType(val value: Int) {
INVALID(-1),
MD0201(80),
MD5201(81),
MD0202(82),
MD5202(83),
MD8201(88),
MD8301(98);
companion object {
fun fromValue(value: Int): ModelType {
return values().find { it.value == value } ?: INVALID
}
}
}

View file

@ -132,7 +132,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
if (event.isChanged(rh.gs(R.string.key_sn_input))) { if (event.isChanged(rh.gs(R.string.key_sn_input))) {
aapsLogger.debug(LTag.PUMPCOMM, "Serial number changed, reporting new pump!") aapsLogger.debug(LTag.PUMPCOMM, "Serial number changed, reporting new pump!")
medtrumPump.loadUserSettingsFromSP() medtrumPump.loadUserSettingsFromSP()
medtrumPump.deviceType = MedtrumSnUtil().getDeviceTypeFromSerial(medtrumPump.pumpSN) medtrumPump.deviceType = MedtrumSnUtil().getDeviceTypeFromSerial(medtrumPump.pumpSN).value
medtrumPump.resetPatchParameters() medtrumPump.resetPatchParameters()
pumpSync.connectNewPump() pumpSync.connectNewPump()
medtrumPump.setFakeTBRIfNotSet() medtrumPump.setFakeTBRIfNotSet()

View file

@ -14,6 +14,7 @@ import info.nightscout.pump.medtrum.R
import info.nightscout.pump.medtrum.code.ConnectionState import info.nightscout.pump.medtrum.code.ConnectionState
import info.nightscout.pump.medtrum.code.EventType import info.nightscout.pump.medtrum.code.EventType
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
import info.nightscout.pump.medtrum.comm.enums.ModelType
import info.nightscout.pump.medtrum.ui.MedtrumBaseNavigator import info.nightscout.pump.medtrum.ui.MedtrumBaseNavigator
import info.nightscout.pump.medtrum.ui.event.SingleLiveEvent import info.nightscout.pump.medtrum.ui.event.SingleLiveEvent
import info.nightscout.pump.medtrum.ui.event.UIEvent import info.nightscout.pump.medtrum.ui.event.UIEvent
@ -199,7 +200,7 @@ class MedtrumOverviewViewModel @Inject constructor(
val activeAlarmStrings = medtrumPump.activeAlarms.map { medtrumPump.alarmStateToString(it) } val activeAlarmStrings = medtrumPump.activeAlarms.map { medtrumPump.alarmStateToString(it) }
_activeAlarms.postValue(activeAlarmStrings.joinToString("\n")) _activeAlarms.postValue(activeAlarmStrings.joinToString("\n"))
_pumpType.postValue(medtrumPump.deviceType.toString()) _pumpType.postValue(ModelType.fromValue(medtrumPump.deviceType).toString())
_fwVersion.postValue(medtrumPump.swVersion) _fwVersion.postValue(medtrumPump.swVersion)
_patchNo.postValue(medtrumPump.patchId.toString()) _patchNo.postValue(medtrumPump.patchId.toString())

View file

@ -1,33 +1,20 @@
package info.nightscout.pump.medtrum.util package info.nightscout.pump.medtrum.util
import info.nightscout.pump.medtrum.comm.enums.ModelType
import info.nightscout.pump.medtrum.encryption.Crypt import info.nightscout.pump.medtrum.encryption.Crypt
class MedtrumSnUtil { class MedtrumSnUtil {
companion object { fun getDeviceTypeFromSerial(serial: Long): ModelType {
const val INVALID = -1
const val MD_0201 = 80
const val MD_5201 = 81
const val MD_0202 = 82
const val MD_5202 = 83
const val MD_8201 = 88
const val MD_8301 = 98
}
fun getDeviceTypeFromSerial(serial: Long): Int {
if (serial in 106000000..106999999) {
return INVALID
}
return when (Crypt().simpleDecrypt(serial)) { return when (Crypt().simpleDecrypt(serial)) {
in 126000000..126999999 -> MD_0201 in 126000000..126999999 -> ModelType.MD0201
in 127000000..127999999 -> MD_5201 in 127000000..127999999 -> ModelType.MD5201
in 128000000..128999999 -> MD_8201 in 128000000..128999999 -> ModelType.MD8201
in 130000000..130999999 -> MD_0202 in 130000000..130999999 -> ModelType.MD0202
in 131000000..131999999 -> MD_5202 in 131000000..131999999 -> ModelType.MD5202
in 148000000..148999999 -> MD_8301 in 148000000..148999999 -> ModelType.MD8301
else -> INVALID else -> ModelType.INVALID
} }
} }
} }

View file

@ -141,7 +141,7 @@
<string name="sn_input_title">Serial Number</string> <string name="sn_input_title">Serial Number</string>
<string name="sn_input_summary">Enter the serial number of your pump base.</string> <string name="sn_input_summary">Enter the serial number of your pump base.</string>
<string name="sn_input_invalid">Invalid serial number!</string> <string name="sn_input_invalid">Invalid serial number!</string>
<string name="pump_unsupported">Pump untested: %1$d! Please contact us at discord or github for support</string> <string name="pump_unsupported">Pump untested: %1$s! Please contact us at discord or github for support</string>
<string name="alarm_setting_title">Alarm Settings</string> <string name="alarm_setting_title">Alarm Settings</string>
<string name="alarm_setting_summary">Select your preferred pump alarm settings.</string> <string name="alarm_setting_summary">Select your preferred pump alarm settings.</string>
<string name="pump_warning_notification_title">Notification on pump warning</string> <string name="pump_warning_notification_title">Notification on pump warning</string>

View file

@ -9,6 +9,7 @@ import app.aaps.core.interfaces.rx.events.EventOverviewBolusProgress
import app.aaps.core.interfaces.utils.T import app.aaps.core.interfaces.utils.T
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import info.nightscout.pump.medtrum.comm.enums.BasalType import info.nightscout.pump.medtrum.comm.enums.BasalType
import info.nightscout.pump.medtrum.comm.enums.ModelType
import info.nightscout.pump.medtrum.util.MedtrumSnUtil import info.nightscout.pump.medtrum.util.MedtrumSnUtil
import org.json.JSONObject import org.json.JSONObject
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
@ -139,7 +140,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val receivedTime = 1500L val receivedTime = 1500L
val duration = T.mins(5).msecs() val duration = T.mins(5).msecs()
medtrumPump.deviceType = MedtrumSnUtil.MD_8301 medtrumPump.deviceType = ModelType.MD8301.value
// Mocks // Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java) val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -191,7 +192,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L val basalStartTime = 1000L
val receivedTime = 1500L val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301 medtrumPump.deviceType = ModelType.MD8301.value
// Mocks // Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java) val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -240,7 +241,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L val basalStartTime = 1000L
val receivedTime = 1500L val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301 medtrumPump.deviceType = ModelType.MD8301.value
// Mocks // Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java) val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -293,7 +294,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val duration = T.mins(5).msecs() val duration = T.mins(5).msecs()
medtrumPump.actualBasalProfile = medtrumPump.buildMedtrumProfileArray(validProfile)!! medtrumPump.actualBasalProfile = medtrumPump.buildMedtrumProfileArray(validProfile)!!
medtrumPump.deviceType = MedtrumSnUtil.MD_8301 medtrumPump.deviceType = ModelType.MD8301.value
// Mocks // Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java) val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -346,7 +347,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L val basalStartTime = 1000L
val receivedTime = 1500L val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301 medtrumPump.deviceType = ModelType.MD8301.value
// Mocks // Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java) val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -441,7 +442,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L val basalStartTime = 1000L
val receivedTime = 1500L val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301 medtrumPump.deviceType = ModelType.MD8301.value
// Mocks // Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java) val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -492,7 +493,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L val basalStartTime = 1000L
val receivedTime = 1500L val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301 medtrumPump.deviceType = ModelType.MD8301.value
// Mocks // Mocks
Mockito.`when`(pumpSync.expectedPumpState()).thenReturn( Mockito.`when`(pumpSync.expectedPumpState()).thenReturn(
@ -537,7 +538,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L val basalStartTime = 1000L
val receivedTime = 1500L val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301 medtrumPump.deviceType = ModelType.MD8301.value
// Mocks // Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java) val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -581,7 +582,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L val basalStartTime = 1000L
val receivedTime = 1500L val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301 medtrumPump.deviceType = ModelType.MD8301.value
// Mocks // Mocks
Mockito.`when`(pumpSync.expectedPumpState()).thenReturn( Mockito.`when`(pumpSync.expectedPumpState()).thenReturn(
@ -650,7 +651,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
@Test fun setFakeTBRIfNotSetWhenNoFakeTBRAlreadyRunningExpectPumpSync() { @Test fun setFakeTBRIfNotSetWhenNoFakeTBRAlreadyRunningExpectPumpSync() {
// Inputs // Inputs
medtrumPump.deviceType = MedtrumSnUtil.MD_8301 medtrumPump.deviceType = ModelType.MD8301.value
// Mocks // Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java) val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -684,7 +685,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
@Test fun setFakeTBRIfNotSetWhenFakeTBRAlreadyRunningExpectNoPumpSync() { @Test fun setFakeTBRIfNotSetWhenFakeTBRAlreadyRunningExpectNoPumpSync() {
// Inputs // Inputs
medtrumPump.deviceType = MedtrumSnUtil.MD_8301 medtrumPump.deviceType = ModelType.MD8301.value
// Mocks // Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java) val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)