Merge pull request #3177 from jbr7rr/medtrum-fixes

Medtrum improvements
This commit is contained in:
Milos Kozak 2024-01-23 11:27:32 +01:00 committed by GitHub
commit 927676d5ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 54 additions and 51 deletions

View file

@ -53,6 +53,7 @@ import app.aaps.core.ui.toast.ToastUtils
import app.aaps.core.validators.ValidatingEditTextPreference
import dagger.android.HasAndroidInjector
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.ui.MedtrumOverviewFragment
import info.nightscout.pump.medtrum.util.MedtrumSnUtil
@ -153,7 +154,7 @@ import kotlin.math.abs
override fun afterTextChanged(newValue: Editable?) {
val newSN = newValue?.toString()?.toLongOrNull(radix = 16) ?: 0
val newDeviceType = MedtrumSnUtil().getDeviceTypeFromSerial(newSN)
editText.error = if (newDeviceType == MedtrumSnUtil.INVALID) {
editText.error = if (newDeviceType == ModelType.INVALID) {
rh.gs(R.string.sn_input_invalid)
} else {
null
@ -174,7 +175,7 @@ import kotlin.math.abs
val newDeviceType = MedtrumSnUtil().getDeviceTypeFromSerial(newSN)
when {
newDeviceType == MedtrumSnUtil.INVALID -> {
newDeviceType == ModelType.INVALID -> {
preferenceFragment.activity?.let { activity ->
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 -> {
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
}

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.BasalType
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.toInt
import info.nightscout.pump.medtrum.util.MedtrumSnUtil
@ -291,13 +292,13 @@ class MedtrumPump @Inject constructor(
var desiredPumpWarning = true
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) {
MedtrumSnUtil.MD_0201, MedtrumSnUtil.MD_8201 -> PumpType.MEDTRUM_NANO
MedtrumSnUtil.MD_8301 -> PumpType.MEDTRUM_300U
else -> PumpType.MEDTRUM_UNTESTED
ModelType.MD0201, ModelType.MD8201 -> PumpType.MEDTRUM_NANO
ModelType.MD8301 -> PumpType.MEDTRUM_300U
else -> PumpType.MEDTRUM_UNTESTED
}
fun loadVarsFromSP() {
@ -569,7 +570,7 @@ class MedtrumPump @Inject constructor(
AlarmState.EXPIRED -> R.string.alarm_expired
AlarmState.RESERVOIR_EMPTY -> R.string.alarm_reservoir_empty
AlarmState.PATCH_FAULT -> R.string.alarm_patch_fault
AlarmState.PATCH_FAULT2 -> R.string.alarm_patch_fault2
AlarmState.PATCH_FAULT2 -> R.string.alarm_patch_fault // To avoid confusion, medtrum app also doesn't show patch fault 2
AlarmState.BASE_FAULT -> R.string.alarm_base_fault
AlarmState.BATTERY_OUT -> R.string.alarm_battery_out
AlarmState.NO_CALIBRATION -> R.string.alarm_no_calibration

View file

@ -15,7 +15,6 @@ enum class PatchStep {
ACTIVATE_COMPLETE,
RETRY_ACTIVATION,
RETRY_ACTIVATION_CONNECT,
ERROR,
CANCEL,
COMPLETE;
}

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))) {
aapsLogger.debug(LTag.PUMPCOMM, "Serial number changed, reporting new pump!")
medtrumPump.loadUserSettingsFromSP()
medtrumPump.deviceType = MedtrumSnUtil().getDeviceTypeFromSerial(medtrumPump.pumpSN)
medtrumPump.deviceType = MedtrumSnUtil().getDeviceTypeFromSerial(medtrumPump.pumpSN).value
medtrumPump.resetPatchParameters()
pumpSync.connectNewPump()
medtrumPump.setFakeTBRIfNotSet()

View file

@ -38,7 +38,6 @@ class MedtrumActivateFragment : MedtrumBaseFragment<FragmentMedtrumActivateBindi
MedtrumViewModel.SetupStep.ACTIVATED -> moveStep(PatchStep.ACTIVATE_COMPLETE)
MedtrumViewModel.SetupStep.ERROR -> {
moveStep(PatchStep.ERROR)
updateSetupStep(MedtrumViewModel.SetupStep.PRIMED) // Reset setup step
binding.textActivatingPump.text = rh.gs(R.string.activating_error)
binding.btnPositive.visibility = View.VISIBLE

View file

@ -43,7 +43,6 @@ class MedtrumActivity : MedtrumBaseActivity<ActivityMedtrumBinding>() {
PatchStep.ATTACH_PATCH -> setupViewFragment(MedtrumAttachPatchFragment.newInstance())
PatchStep.ACTIVATE -> setupViewFragment(MedtrumActivateFragment.newInstance())
PatchStep.ACTIVATE_COMPLETE -> setupViewFragment(MedtrumActivateCompleteFragment.newInstance())
PatchStep.ERROR -> Unit // Do nothing, let activity handle this
PatchStep.RETRY_ACTIVATION -> setupViewFragment(MedtrumRetryActivationFragment.newInstance())
PatchStep.RETRY_ACTIVATION_CONNECT -> setupViewFragment(MedtrumRetryActivationConnectFragment.newInstance())
PatchStep.START_DEACTIVATION -> setupViewFragment(MedtrumStartDeactivationFragment.newInstance())

View file

@ -38,7 +38,6 @@ class MedtrumDeactivatePatchFragment : MedtrumBaseFragment<FragmentMedtrumDeacti
}
MedtrumViewModel.SetupStep.ERROR -> {
moveStep(PatchStep.ERROR)
updateSetupStep(MedtrumViewModel.SetupStep.START_DEACTIVATION) // Reset setup step
binding.textDeactivatingPump.text = rh.gs(R.string.deactivating_error)
binding.btnNegative.visibility = View.VISIBLE

View file

@ -39,7 +39,6 @@ class MedtrumPrimingFragment : MedtrumBaseFragment<FragmentMedtrumPrimingBinding
MedtrumViewModel.SetupStep.PRIMED -> moveStep(PatchStep.PRIME_COMPLETE)
MedtrumViewModel.SetupStep.ERROR -> {
moveStep(PatchStep.ERROR)
updateSetupStep(MedtrumViewModel.SetupStep.FILLED) // Reset setup step
binding.textWaitForPriming.text = rh.gs(R.string.priming_error)
binding.btnNegative.visibility = View.VISIBLE

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.EventType
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.event.SingleLiveEvent
import info.nightscout.pump.medtrum.ui.event.UIEvent
@ -199,7 +200,7 @@ class MedtrumOverviewViewModel @Inject constructor(
val activeAlarmStrings = medtrumPump.activeAlarms.map { medtrumPump.alarmStateToString(it) }
_activeAlarms.postValue(activeAlarmStrings.joinToString("\n"))
_pumpType.postValue(medtrumPump.deviceType.toString())
_pumpType.postValue(ModelType.fromValue(medtrumPump.deviceType).toString())
_fwVersion.postValue(medtrumPump.swVersion)
_patchNo.postValue(medtrumPump.patchId.toString())

View file

@ -137,7 +137,6 @@ class MedtrumViewModel @Inject constructor(
PatchStep.CANCEL,
PatchStep.COMPLETE,
PatchStep.ACTIVATE_COMPLETE,
PatchStep.ERROR,
PatchStep.START_DEACTIVATION,
PatchStep.DEACTIVATE,
PatchStep.FORCE_DEACTIVATION,
@ -307,7 +306,6 @@ class MedtrumViewModel @Inject constructor(
PatchStep.COMPLETE,
PatchStep.FORCE_DEACTIVATION,
PatchStep.ERROR,
PatchStep.CANCEL -> _title.value
}

View file

@ -1,33 +1,23 @@
package info.nightscout.pump.medtrum.util
import info.nightscout.pump.medtrum.comm.enums.ModelType
import info.nightscout.pump.medtrum.encryption.Crypt
class MedtrumSnUtil {
companion object {
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 {
fun getDeviceTypeFromSerial(serial: Long): ModelType {
if (serial in 106000000..106999999) {
return INVALID
return ModelType.INVALID
}
return when (Crypt().simpleDecrypt(serial)) {
in 126000000..126999999 -> MD_0201
in 127000000..127999999 -> MD_5201
in 128000000..128999999 -> MD_8201
in 130000000..130999999 -> MD_0202
in 131000000..131999999 -> MD_5202
in 148000000..148999999 -> MD_8301
else -> INVALID
in 126000000..126999999 -> ModelType.MD0201
in 127000000..127999999 -> ModelType.MD5201
in 128000000..128999999 -> ModelType.MD8201
in 130000000..130999999 -> ModelType.MD0202
in 131000000..131999999 -> ModelType.MD5202
in 148000000..148999999 -> ModelType.MD8301
else -> ModelType.INVALID
}
}
}

View file

@ -77,7 +77,6 @@
<string name="alarm_expired">Expired</string>
<string name="alarm_reservoir_empty">Reservoir empty</string>
<string name="alarm_patch_fault">Patch fault</string>
<string name="alarm_patch_fault2">Patch fault 2</string>
<string name="alarm_base_fault">Base fault</string>
<string name="alarm_battery_out">Battery out</string>
<string name="alarm_no_calibration">No calibration</string>
@ -142,7 +141,7 @@
<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_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_summary">Select your preferred pump alarm settings.</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 com.google.common.truth.Truth.assertThat
import info.nightscout.pump.medtrum.comm.enums.BasalType
import info.nightscout.pump.medtrum.comm.enums.ModelType
import info.nightscout.pump.medtrum.util.MedtrumSnUtil
import org.json.JSONObject
import org.junit.jupiter.api.Test
@ -139,7 +140,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val receivedTime = 1500L
val duration = T.mins(5).msecs()
medtrumPump.deviceType = MedtrumSnUtil.MD_8301
medtrumPump.deviceType = ModelType.MD8301.value
// Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -191,7 +192,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L
val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301
medtrumPump.deviceType = ModelType.MD8301.value
// Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -240,7 +241,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L
val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301
medtrumPump.deviceType = ModelType.MD8301.value
// Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -293,7 +294,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val duration = T.mins(5).msecs()
medtrumPump.actualBasalProfile = medtrumPump.buildMedtrumProfileArray(validProfile)!!
medtrumPump.deviceType = MedtrumSnUtil.MD_8301
medtrumPump.deviceType = ModelType.MD8301.value
// Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -346,7 +347,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L
val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301
medtrumPump.deviceType = ModelType.MD8301.value
// Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -441,7 +442,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L
val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301
medtrumPump.deviceType = ModelType.MD8301.value
// Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -492,7 +493,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L
val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301
medtrumPump.deviceType = ModelType.MD8301.value
// Mocks
Mockito.`when`(pumpSync.expectedPumpState()).thenReturn(
@ -537,7 +538,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L
val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301
medtrumPump.deviceType = ModelType.MD8301.value
// Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -581,7 +582,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val basalStartTime = 1000L
val receivedTime = 1500L
medtrumPump.deviceType = MedtrumSnUtil.MD_8301
medtrumPump.deviceType = ModelType.MD8301.value
// Mocks
Mockito.`when`(pumpSync.expectedPumpState()).thenReturn(
@ -650,7 +651,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
@Test fun setFakeTBRIfNotSetWhenNoFakeTBRAlreadyRunningExpectPumpSync() {
// Inputs
medtrumPump.deviceType = MedtrumSnUtil.MD_8301
medtrumPump.deviceType = ModelType.MD8301.value
// Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)
@ -684,7 +685,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
@Test fun setFakeTBRIfNotSetWhenFakeTBRAlreadyRunningExpectNoPumpSync() {
// Inputs
medtrumPump.deviceType = MedtrumSnUtil.MD_8301
medtrumPump.deviceType = ModelType.MD8301.value
// Mocks
val expectedTemporaryBasal: PumpSync.PumpState.TemporaryBasal = mock(PumpSync.PumpState.TemporaryBasal::class.java)