From 2cd5686556432411ff57751263daa6017d06bcee Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 26 Aug 2023 23:39:36 +0200 Subject: [PATCH] kotlin lints --- .../comm/history/MedtronicHistoryDecoder.kt | 14 +- .../comm/history/cgms/CGMSHistoryEntryType.kt | 23 +- .../comm/history/pump/PumpHistoryEntryType.kt | 63 +--- .../comm/ui/MedtronicUIPostprocessor.kt | 44 +-- .../medtronic/data/MedtronicHistoryData.kt | 274 +++++++++++------- .../medtronic/driver/MedtronicPumpStatus.kt | 15 +- .../service/RileyLinkMedtronicService.kt | 8 +- .../pump/medtronic/util/MedtronicUtil.kt | 10 +- 8 files changed, 241 insertions(+), 210 deletions(-) diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/MedtronicHistoryDecoder.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/MedtronicHistoryDecoder.kt index 55912956ee..642f8c97f9 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/MedtronicHistoryDecoder.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/MedtronicHistoryDecoder.kt @@ -20,9 +20,9 @@ abstract class MedtronicHistoryDecoder(var aapsLogge ) : MedtronicHistoryDecoderInterface { // STATISTICS (remove at later time or not) - protected var statisticsEnabled = true + private var statisticsEnabled = true protected var unknownOpCodes: MutableMap = mutableMapOf() - protected var mapStatistics: MutableMap> = mutableMapOf() + private var mapStatistics: MutableMap> = mutableMapOf() abstract fun postProcess() protected abstract fun runPostDecodeTasks() @@ -63,7 +63,7 @@ abstract class MedtronicHistoryDecoder(var aapsLogge } } - protected fun addToStatistics(pumpHistoryEntry: MedtronicHistoryEntryInterface, status: RecordDecodeStatus, opCode: Int?) { + protected fun addToStatistics(pumpHistoryEntry: MedtronicHistoryEntryInterface, status: RecordDecodeStatus, @Suppress("SameParameterValue") opCode: Int?) { if (!statisticsEnabled) return if (opCode != null) { if (!unknownOpCodes.containsKey(opCode)) { @@ -71,8 +71,8 @@ abstract class MedtronicHistoryDecoder(var aapsLogge } return } - if (!mapStatistics[status]!!.containsKey(pumpHistoryEntry.entryTypeName)) { - mapStatistics[status]!!.put(pumpHistoryEntry.entryTypeName, "") + if (mapStatistics[status]?.containsKey(pumpHistoryEntry.entryTypeName) == false) { + mapStatistics[status]?.put(pumpHistoryEntry.entryTypeName, "") } } @@ -82,13 +82,13 @@ abstract class MedtronicHistoryDecoder(var aapsLogge StringUtil.appendToStringBuilder(sb, "" + key, ", ") } aapsLogger.info(LTag.PUMPCOMM, "STATISTICS OF PUMP DECODE") - if (unknownOpCodes.size > 0) { + if (unknownOpCodes.isNotEmpty()) { aapsLogger.warn(LTag.PUMPCOMM, "Unknown Op Codes: $sb") } for ((key, value) in mapStatistics) { sb = StringBuilder() if (key !== RecordDecodeStatus.OK) { - if (value.size == 0) continue + if (value.isEmpty()) continue for ((key1) in value) { StringUtil.appendToStringBuilder(sb, key1, ", ") } diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/cgms/CGMSHistoryEntryType.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/cgms/CGMSHistoryEntryType.kt index 4e993c1249..4027407ca5 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/cgms/CGMSHistoryEntryType.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/cgms/CGMSHistoryEntryType.kt @@ -12,7 +12,11 @@ enum class CGMSHistoryEntryType(val code: Int, val description: String, val head DataEnd(0x01, "DataEnd", 1, 0, 0, DateType.PreviousTimeStamp), // SensorWeakSignal(0x02, "SensorWeakSignal", 1, 0, 0, DateType.PreviousTimeStamp), // SensorCal(0x03, "SensorCal", 1, 0, 1, DateType.PreviousTimeStamp), // - SensorPacket(0x04, "SensorPacket", 1, 0, 1, DateType.PreviousTimeStamp), SensorError(0x05, "SensorError", 1, 0, 1, DateType.PreviousTimeStamp), SensorDataLow(0x06, "SensorDataLow", 1, 0, 1, DateType.PreviousTimeStamp), SensorDataHigh(0x07, "SensorDataHigh", 1, 0, 1, DateType.PreviousTimeStamp), SensorTimestamp(0x08, "SensorTimestamp", 1, 4, 0, DateType.MinuteSpecific), // + SensorPacket(0x04, "SensorPacket", 1, 0, 1, DateType.PreviousTimeStamp), + SensorError(0x05, "SensorError", 1, 0, 1, DateType.PreviousTimeStamp), + SensorDataLow(0x06, "SensorDataLow", 1, 0, 1, DateType.PreviousTimeStamp), + SensorDataHigh(0x07, "SensorDataHigh", 1, 0, 1, DateType.PreviousTimeStamp), + SensorTimestamp(0x08, "SensorTimestamp", 1, 4, 0, DateType.MinuteSpecific), // BatteryChange(0x0a, "BatteryChange", 1, 4, 0, DateType.MinuteSpecific), // SensorStatus(0x0b, "SensorStatus", 1, 4, 0, DateType.MinuteSpecific), // DateTimeChange(0x0c, "DateTimeChange", 1, 4, 0, DateType.SecondSpecific), // @@ -20,19 +24,16 @@ enum class CGMSHistoryEntryType(val code: Int, val description: String, val head CalBGForGH(0x0e, "CalBGForGH',packet_size=5", 1, 4, 1, DateType.MinuteSpecific), // SensorCalFactor(0x0f, "SensorCalFactor", 1, 4, 2, DateType.MinuteSpecific), // Something10(0x10, "10-Something", 1, 4, 0, DateType.MinuteSpecific), // - Something19(0x13, "19-Something", 1, 0, 0, DateType.PreviousTimeStamp), GlucoseSensorData(0xFF, "GlucoseSensorData", 1, 0, 0, DateType.PreviousTimeStamp), + Something19(0x13, "19-Something", 1, 0, 0, DateType.PreviousTimeStamp), + GlucoseSensorData(0xFF, "GlucoseSensorData", 1, 0, 0, DateType.PreviousTimeStamp), UnknownOpCode(0xFF, "Unknown", 0, 0, 0, DateType.None); companion object { private val opCodeMap: MutableMap = mutableMapOf() - fun getByCode(opCode: Int): CGMSHistoryEntryType { - return if (opCodeMap.containsKey(opCode)) - opCodeMap[opCode]!! - else - UnknownOpCode - } + fun getByCode(opCode: Int): CGMSHistoryEntryType = + opCodeMap[opCode] ?: UnknownOpCode init { for (type in values()) { @@ -41,8 +42,8 @@ enum class CGMSHistoryEntryType(val code: Int, val description: String, val head } } - var schemaSet: Boolean - val totalLength: Int + var schemaSet: Boolean = true + val totalLength: Int = headLength + dateLength + bodyLength val dateType: DateType fun hasDate(): Boolean { @@ -57,8 +58,6 @@ enum class CGMSHistoryEntryType(val code: Int, val description: String, val head } init { - totalLength = headLength + dateLength + bodyLength - schemaSet = true this.dateType = dateType } } \ No newline at end of file diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryType.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryType.kt index dfa5305d4f..27c2580dc4 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryType.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntryType.kt @@ -10,13 +10,14 @@ import info.nightscout.pump.common.defs.PumpHistoryEntryGroup * * Author: Andy {andy.rozman@gmail.com} */ -enum class PumpHistoryEntryType // implements CodeEnum -constructor(var code: Byte, - var description: String, - var group: PumpHistoryEntryGroup, - var headLength: Int = 2, - var dateLength: Int = 5, - var bodyLength: Int = 0) { +enum class PumpHistoryEntryType( + var code: Byte, + var description: String, + var group: PumpHistoryEntryGroup, + private var headLength: Int = 2, + var dateLength: Int = 5, + private var bodyLength: Int = 0 +) { // all commented out are probably not the real items None(0, "None", PumpHistoryEntryGroup.Unknown, 1, 0, 0), @@ -25,7 +26,9 @@ constructor(var code: Byte, // /**/EventUnknown_MM522_0x05((byte) 0x05, "Unknown Event 0x05", PumpHistoryEntryGroup.Unknown, 2, 5, 28), // NoDeliveryAlarm(0x06, "No Delivery", PumpHistoryEntryGroup.Alarm, 4, 5, 0), // - EndResultTotals(0x07, "End Result Totals", PumpHistoryEntryGroup.Statistic, 5, 2, 0), ChangeBasalProfile_OldProfile(0x08, "Change Basal Profile (Old)", PumpHistoryEntryGroup.Basal, 2, 5, 145), ChangeBasalProfile_NewProfile(0x09, "Change Basal Profile (New)", PumpHistoryEntryGroup.Basal, 2, 5, 145), // + EndResultTotals(0x07, "End Result Totals", PumpHistoryEntryGroup.Statistic, 5, 2, 0), + ChangeBasalProfile_OldProfile(0x08, "Change Basal Profile (Old)", PumpHistoryEntryGroup.Basal, 2, 5, 145), + ChangeBasalProfile_NewProfile(0x09, "Change Basal Profile (New)", PumpHistoryEntryGroup.Basal, 2, 5, 145), // // /**/EventUnknown_MM512_0x10(0x10, "Unknown Event 0x10", PumpHistoryEntryGroup.Unknown), // 29, 5, 0 CalBGForPH(0x0a, "BG Capture", PumpHistoryEntryGroup.Glucose), // @@ -144,7 +147,7 @@ constructor(var code: Byte, companion object { private val opCodeMap: MutableMap = HashMap() - fun setSpecialRulesForEntryTypes() { + private fun setSpecialRulesForEntryTypes() { EndResultTotals.addSpecialRuleBody(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 3)) Bolus.addSpecialRuleHead(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 8)) BolusWizardSetup.addSpecialRuleBody(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 137)) @@ -153,41 +156,8 @@ constructor(var code: Byte, ChangeSensorSetup2.addSpecialRuleBody(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 34)) } - fun getByCode(opCode: Byte): PumpHistoryEntryType { - return if (opCodeMap.containsKey(opCode)) { - opCodeMap[opCode]!! - } else { - UnknownBasePacket - } - } - - fun isAAPSRelevantEntry(entryType: PumpHistoryEntryType): Boolean { - return entryType == Bolus || // Treatments - entryType == TempBasalRate || // - entryType == TempBasalDuration || // - entryType == Prime || // Pump Status Change - entryType == SuspendPump || // - entryType == ResumePump || // - entryType == Rewind || // - entryType == NoDeliveryAlarm || // no delivery - entryType == BasalProfileStart || // - entryType == ChangeTime || // Time Change - entryType == NewTimeSet || // - entryType == ChangeBasalPattern || // Configuration - entryType == ClearSettings || // - entryType == SaveSettings || // - entryType == ChangeMaxBolus || // - entryType == ChangeMaxBasal || // - entryType == ChangeTempBasalType || // - entryType == ChangeBasalProfile_NewProfile || // Basal profile - entryType == DailyTotals515 || // Daily Totals - entryType == DailyTotals522 || // - entryType == DailyTotals523 || // - entryType == EndResultTotals - } - - val isRelevantEntry: Boolean - get() = true + fun getByCode(opCode: Byte): PumpHistoryEntryType = + opCodeMap[opCode] ?: UnknownBasePacket init { for (type in values()) { @@ -197,7 +167,7 @@ constructor(var code: Byte, } } - private val totalLength: Int + private val totalLength: Int = headLength + dateLength + bodyLength // special rules need to be put in list from highest to lowest (e.g.: // 523andHigher=12, 515andHigher=10 and default (set in cnstr) would be 8) @@ -259,7 +229,4 @@ constructor(var code: Byte, class SpecialRule internal constructor(var deviceType: MedtronicDeviceType, var size: Int) - init { - totalLength = headLength + dateLength + bodyLength - } } \ No newline at end of file diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.kt index d5a155638c..ffaeb7d22d 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.kt @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui -import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BatteryStatusDTO @@ -12,9 +11,9 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicNotificat import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicUIResponseType import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil -import info.nightscout.rx.bus.RxBus import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag +import info.nightscout.shared.interfaces.ResourceHelper import org.joda.time.DateTimeZone import org.joda.time.Duration import java.util.Date @@ -28,11 +27,11 @@ import javax.inject.Singleton @Singleton class MedtronicUIPostprocessor @Inject constructor( private val aapsLogger: AAPSLogger, - private val rxBus: RxBus, private val rh: ResourceHelper, private val medtronicUtil: MedtronicUtil, private val medtronicPumpStatus: MedtronicPumpStatus, - private val medtronicPumpPlugin: MedtronicPumpPlugin) { + private val medtronicPumpPlugin: MedtronicPumpPlugin +) { // this is mostly intended for command that return certain statuses (Remaining Insulin, ...), and // where responses won't be directly used @@ -66,7 +65,7 @@ class MedtronicUIPostprocessor @Inject constructor( } } } catch (ex: Exception) { - aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Basal Profile was returned, but was invalid. [%s]", basalProfile!!.basalProfileToStringError())) + aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Basal Profile was returned, but was invalid. [%s]", basalProfile?.basalProfileToStringError())) uiTask.responseType = MedtronicUIResponseType.Error uiTask.errorDescription = "No profile found." } @@ -95,7 +94,7 @@ class MedtronicUIPostprocessor @Inject constructor( val response = uiTask.result as Boolean aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "New time was %s set.", if (response) "" else "NOT")) if (response) { - medtronicUtil.pumpTime!!.timeDifference = 0 + medtronicUtil.pumpTime?.timeDifference = 0 } } @@ -132,13 +131,16 @@ class MedtronicUIPostprocessor @Inject constructor( private fun processTime(uiTask: MedtronicUITask) { val clockDTO = uiTask.result as ClockDTO? if (clockDTO != null) { - val dur = Duration(clockDTO.pumpTime.toDateTime(DateTimeZone.UTC), - clockDTO.localDeviceTime.toDateTime(DateTimeZone.UTC)) + val dur = Duration( + clockDTO.pumpTime.toDateTime(DateTimeZone.UTC), + clockDTO.localDeviceTime.toDateTime(DateTimeZone.UTC) + ) clockDTO.timeDifference = dur.standardSeconds.toInt() medtronicUtil.pumpTime = clockDTO aapsLogger.debug( LTag.PUMP, "Pump Time: " + clockDTO.localDeviceTime + ", DeviceTime=" + clockDTO.pumpTime + // - ", diff: " + dur.standardSeconds + " s") + ", diff: " + dur.standardSeconds + " s" + ) } else { aapsLogger.debug(LTag.PUMP, "Problem with returned data: " + medtronicUtil.gsonInstance.toJson(uiTask.result)) } @@ -148,18 +150,18 @@ class MedtronicUIPostprocessor @Inject constructor( @Suppress("UNCHECKED_CAST") val settings = uiTask.result as? Map ?: return medtronicUtil.settings = settings - var checkValue: PumpSettingDTO + var checkValue: PumpSettingDTO? medtronicPumpPlugin.rileyLinkService?.verifyConfiguration() // check profile if (settings.containsKey("PCFG_BASAL_PROFILES_ENABLED") && settings.containsKey("PCFG_ACTIVE_BASAL_PROFILE")) { - checkValue = settings["PCFG_BASAL_PROFILES_ENABLED"]!! - if ("Yes" != checkValue.value) { + checkValue = settings["PCFG_BASAL_PROFILES_ENABLED"] + if ("Yes" != checkValue?.value) { aapsLogger.error(LTag.PUMP, "Basal profiles are not enabled on pump.") medtronicUtil.sendNotification(MedtronicNotificationType.PumpBasalProfilesNotEnabled, rh) } else { - checkValue = settings["PCFG_ACTIVE_BASAL_PROFILE"]!! - if ("STD" != checkValue.value) { + checkValue = settings["PCFG_ACTIVE_BASAL_PROFILE"] + if ("STD" != checkValue?.value) { aapsLogger.error("Basal profile set on pump is incorrect (must be STD).") medtronicUtil.sendNotification(MedtronicNotificationType.PumpIncorrectBasalProfileSelected, rh) } @@ -168,7 +170,7 @@ class MedtronicUIPostprocessor @Inject constructor( // TBR if (settings.containsKey("PCFG_TEMP_BASAL_TYPE")) { - if ("Units" != settings["PCFG_TEMP_BASAL_TYPE"]!!.value) { + if ("Units" != settings["PCFG_TEMP_BASAL_TYPE"]?.value) { aapsLogger.error("Wrong TBR type set on pump (must be Absolute).") medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongTBRTypeSet, rh) } @@ -176,17 +178,17 @@ class MedtronicUIPostprocessor @Inject constructor( // MAXes if (settings.containsKey("PCFG_MAX_BOLUS")) { - checkValue = settings["PCFG_MAX_BOLUS"]!! - if (!MedtronicUtil.isSame(checkValue.value.toDouble(), medtronicPumpStatus.maxBolus!!)) { - aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Wrong Max Bolus set on Pump (current=%s, required=%.2f).", checkValue.value, medtronicPumpStatus.maxBolus)) + checkValue = settings["PCFG_MAX_BOLUS"] + if (!MedtronicUtil.isSame(checkValue?.value?.toDouble(), medtronicPumpStatus.maxBolus)) { + aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Wrong Max Bolus set on Pump (current=%s, required=%.2f).", checkValue?.value, medtronicPumpStatus.maxBolus)) medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBolusSet, rh, medtronicPumpStatus.maxBolus) } } if (settings.containsKey("PCFG_MAX_BASAL")) { - checkValue = settings["PCFG_MAX_BASAL"]!! - if (!MedtronicUtil.isSame(checkValue.value.toDouble(), medtronicPumpStatus.maxBasal!!)) { - aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Wrong Max Basal set on Pump (current=%s, required=%.2f).", checkValue.value, medtronicPumpStatus.maxBasal)) + checkValue = settings["PCFG_MAX_BASAL"] + if (!MedtronicUtil.isSame(checkValue?.value?.toDouble(), medtronicPumpStatus.maxBasal)) { + aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Wrong Max Basal set on Pump (current=%s, required=%.2f).", checkValue?.value, medtronicPumpStatus.maxBasal)) medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBasalSet, rh, medtronicPumpStatus.maxBasal) } } diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt index 515ff23b94..d2bf1a3705 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt @@ -226,8 +226,11 @@ class MedtronicHistoryData @Inject constructor( allHistory.removeAll(removeList.toSet()) this.sort(allHistory) aapsLogger.debug( - LTag.PUMP, String.format(Locale.ENGLISH, "All History records [afterFilterCount=%d, removedItemsCount=%d, newItemsCount=%d]", - allHistory.size, removeList.size, newHistory.size)) + LTag.PUMP, String.format( + Locale.ENGLISH, "All History records [afterFilterCount=%d, removedItemsCount=%d, newItemsCount=%d]", + allHistory.size, removeList.size, newHistory.size + ) + ) } else { aapsLogger.error("Since we couldn't determine date, we don't clean full history. This is just workaround.") } @@ -236,12 +239,15 @@ class MedtronicHistoryData @Inject constructor( fun hasRelevantConfigurationChanged(): Boolean { return getStateFromFilteredList( // - setOf(PumpHistoryEntryType.ChangeBasalPattern, // + setOf( + PumpHistoryEntryType.ChangeBasalPattern, // PumpHistoryEntryType.ClearSettings, // PumpHistoryEntryType.SaveSettings, // PumpHistoryEntryType.ChangeMaxBolus, // PumpHistoryEntryType.ChangeMaxBasal, // - PumpHistoryEntryType.ChangeTempBasalType)) + PumpHistoryEntryType.ChangeTempBasalType + ) + ) } private fun isCollectionEmpty(col: List<*>?): Boolean { @@ -282,8 +288,10 @@ class MedtronicHistoryData @Inject constructor( } if (newAndAll.isEmpty()) return newAndAll this.sort(newAndAll) - var newAndAll2: MutableList = getFilteredItems(newAndAll, // - setOf(PumpHistoryEntryType.Bolus, // + var newAndAll2: MutableList = getFilteredItems( + newAndAll, // + setOf( + PumpHistoryEntryType.Bolus, // PumpHistoryEntryType.TempBasalCombined, // PumpHistoryEntryType.Prime, // PumpHistoryEntryType.SuspendPump, // @@ -291,7 +299,9 @@ class MedtronicHistoryData @Inject constructor( PumpHistoryEntryType.Rewind, // PumpHistoryEntryType.NoDeliveryAlarm, // PumpHistoryEntryType.BatteryChange, // - PumpHistoryEntryType.BasalProfileStart)) + PumpHistoryEntryType.BasalProfileStart + ) + ) newAndAll2 = filterPumpSuspend(newAndAll2, 10) return newAndAll2 } @@ -382,8 +392,11 @@ class MedtronicHistoryData @Inject constructor( throw ex } aapsLogger.debug( - LTag.PUMP, String.format(Locale.ENGLISH, "ProcessHistoryData: 'Delivery Suspend' Processed [count=%d, items=%s]", suspends.size, - gson.toJson(suspends))) + LTag.PUMP, String.format( + Locale.ENGLISH, "ProcessHistoryData: 'Delivery Suspend' Processed [count=%d, items=%s]", suspends.size, + gson.toJson(suspends) + ) + ) if (suspends.isNotEmpty()) { try { processSuspends(suspends) // TODO not tested yet @@ -414,7 +427,8 @@ class MedtronicHistoryData @Inject constructor( } } if (lastPrimeRecord != null) { - uploadCareportalEventIfFoundInHistory(lastPrimeRecord, + uploadCareportalEventIfFoundInHistory( + lastPrimeRecord, MedtronicConst.Statistics.LastPrime, DetailedBolusInfo.EventType.CANNULA_CHANGE ) @@ -434,9 +448,11 @@ class MedtronicHistoryData @Inject constructor( } } if (lastRewindRecord != null) { - uploadCareportalEventIfFoundInHistory(lastRewindRecord, + uploadCareportalEventIfFoundInHistory( + lastRewindRecord, MedtronicConst.Statistics.LastRewind, - DetailedBolusInfo.EventType.INSULIN_CHANGE) + DetailedBolusInfo.EventType.INSULIN_CHANGE + ) } } @@ -448,12 +464,16 @@ class MedtronicHistoryData @Inject constructor( eventType, null, historyRecord.pumpId, medtronicPumpStatus.pumpType, - medtronicPumpStatus.serialNumber) + medtronicPumpStatus.serialNumber + ) aapsLogger.debug( - LTag.PUMP, String.format(Locale.ROOT, "insertTherapyEventIfNewWithTimestamp [date=%d, eventType=%s, pumpId=%d, pumpSerial=%s] - Result: %b", - historyRecord.atechDateTime, eventType, historyRecord.pumpId, - medtronicPumpStatus.serialNumber, result)) + LTag.PUMP, String.format( + Locale.ROOT, "insertTherapyEventIfNewWithTimestamp [date=%d, eventType=%s, pumpId=%d, pumpSerial=%s] - Result: %b", + historyRecord.atechDateTime, eventType, historyRecord.pumpId, + medtronicPumpStatus.serialNumber, result + ) + ) sp.putLong(eventSP, historyRecord.atechDateTime) } @@ -463,8 +483,11 @@ class MedtronicHistoryData @Inject constructor( val tdds = filterTDDs(tddsIn) aapsLogger.debug( - LTag.PUMP, String.format(Locale.ENGLISH, logPrefix + "TDDs found: %d.\n%s", - tdds.size, gson.toJson(tdds))) + LTag.PUMP, String.format( + Locale.ENGLISH, logPrefix + "TDDs found: %d.\n%s", + tdds.size, gson.toJson(tdds) + ) + ) for (tdd in tdds) { val totalsDTO = tdd.decodedData["Object"] as DailyTotalsDTO @@ -483,6 +506,7 @@ class MedtronicHistoryData @Inject constructor( @Suppress("unused") private enum class ProcessHistoryRecord(val description: String) { + Bolus("Bolus"), TBR("TBR"), Suspend("Suspend"); @@ -535,12 +559,16 @@ class MedtronicHistoryData @Inject constructor( type = null, pumpId = bolus.pumpId, pumpType = medtronicPumpStatus.pumpType, - pumpSerial = medtronicPumpStatus.serialNumber) + pumpSerial = medtronicPumpStatus.serialNumber + ) aapsLogger.debug( - LTag.PUMP, String.format(Locale.ENGLISH, "syncBolusWithTempId [date=%d, temporaryId=%d, pumpId=%d, insulin=%.2f, pumpSerial=%s] - Result: %b", - bolus.atechDateTime, temporaryId, bolus.pumpId, deliveredAmount, - medtronicPumpStatus.serialNumber, result)) + LTag.PUMP, String.format( + Locale.ENGLISH, "syncBolusWithTempId [date=%d, temporaryId=%d, pumpId=%d, insulin=%.2f, pumpSerial=%s] - Result: %b", + bolus.atechDateTime, temporaryId, bolus.pumpId, deliveredAmount, + medtronicPumpStatus.serialNumber, result + ) + ) } else { val result = pumpSync.syncBolusWithPumpId( timestamp = tryToGetByLocalTime(bolus.atechDateTime), @@ -548,12 +576,16 @@ class MedtronicHistoryData @Inject constructor( type = null, pumpId = bolus.pumpId, pumpType = medtronicPumpStatus.pumpType, - pumpSerial = medtronicPumpStatus.serialNumber) + pumpSerial = medtronicPumpStatus.serialNumber + ) aapsLogger.debug( - LTag.PUMP, String.format(Locale.ENGLISH, "syncBolusWithPumpId [date=%d, pumpId=%d, insulin=%.2f, pumpSerial=%s] - Result: %b", - bolus.atechDateTime, bolus.pumpId, deliveredAmount, - medtronicPumpStatus.serialNumber, result)) + LTag.PUMP, String.format( + Locale.ENGLISH, "syncBolusWithPumpId [date=%d, pumpId=%d, insulin=%.2f, pumpSerial=%s] - Result: %b", + bolus.atechDateTime, bolus.pumpId, deliveredAmount, + medtronicPumpStatus.serialNumber, result + ) + ) } addCarbs(bolus) @@ -570,12 +602,16 @@ class MedtronicHistoryData @Inject constructor( false, bolus.pumpId, medtronicPumpStatus.pumpType, - medtronicPumpStatus.serialNumber) + medtronicPumpStatus.serialNumber + ) aapsLogger.debug( - LTag.PUMP, String.format(Locale.ENGLISH, "syncExtendedBolusWithPumpId [date=%d, amount=%.2f, duration=%d, pumpId=%d, pumpSerial=%s, multiwave=%b] - Result: %b", - bolus.atechDateTime, bolusDTO.deliveredAmount, bolusDTO.duration, bolus.pumpId, - medtronicPumpStatus.serialNumber, isMultiwave, result)) + LTag.PUMP, String.format( + Locale.ENGLISH, "syncExtendedBolusWithPumpId [date=%d, amount=%.2f, duration=%d, pumpId=%d, pumpSerial=%s, multiwave=%b] - Result: %b", + bolus.atechDateTime, bolusDTO.deliveredAmount, bolusDTO.duration, bolus.pumpId, + medtronicPumpStatus.serialNumber, isMultiwave, result + ) + ) } private fun addCarbs(bolus: PumpHistoryEntry) { @@ -584,12 +620,12 @@ class MedtronicHistoryData @Inject constructor( pumpSyncStorage.addCarbs( PumpDbEntryCarbs( - tryToGetByLocalTime(bolus.atechDateTime), - bolusWizard.carbs.toDouble(), - medtronicPumpStatus.pumpType, - medtronicPumpStatus.serialNumber, - bolus.pumpId - ) + tryToGetByLocalTime(bolus.atechDateTime), + bolusWizard.carbs.toDouble(), + medtronicPumpStatus.pumpType, + medtronicPumpStatus.serialNumber, + bolus.pumpId + ) ) } } @@ -628,7 +664,7 @@ class MedtronicHistoryData @Inject constructor( //aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemTwo: " + (if (tempBasalProcessDTO.itemTwo == null) "null" else gson.toJson(tempBasalProcessDTO.itemTwo!!))) @Suppress("Unchecked_Cast") - val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords as MutableList) as PumpDbEntryTBR? + val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords as MutableList) as PumpDbEntryTBR? aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId: " + (entryWithTempId?.toString() ?: "null")) @@ -641,17 +677,19 @@ class MedtronicHistoryData @Inject constructor( if (tbrEntry != null) { aapsLogger.debug( LTag.PUMP, "DD: tempIdEntry=${entryWithTempId}, tbrEntry=${tbrEntry}, " + - "tempBasalProcessDTO=${tempBasalProcessDTO}, " + - "pumpType=${medtronicPumpStatus.pumpType}, serial=${medtronicPumpStatus.serialNumber}") + "tempBasalProcessDTO=${tempBasalProcessDTO}, " + + "pumpType=${medtronicPumpStatus.pumpType}, serial=${medtronicPumpStatus.serialNumber}" + ) aapsLogger.debug( LTag.PUMP, "syncTemporaryBasalWithTempId " + - "[date=${tempBasalProcessDTO.atechDateTime}, dateProcess=${tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)}, " + - "tbrEntry.insulinRate=${tbrEntry.insulinRate}, " + - "duration=${tempBasalProcessDTO.durationAsSeconds} s, " + - "isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " + - "pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " + - "pumpSerial=${medtronicPumpStatus.serialNumber}]") + "[date=${tempBasalProcessDTO.atechDateTime}, dateProcess=${tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)}, " + + "tbrEntry.insulinRate=${tbrEntry.insulinRate}, " + + "duration=${tempBasalProcessDTO.durationAsSeconds} s, " + + "isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " + + "pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " + + "pumpSerial=${medtronicPumpStatus.serialNumber}]" + ) if (tempBasalProcessDTO.durationAsSeconds <= 0) { uiInteraction.addNotification(Notification.MDT_INVALID_HISTORY_DATA, rh.gs(R.string.invalid_history_data), Notification.URGENT) @@ -691,8 +729,9 @@ class MedtronicHistoryData @Inject constructor( aapsLogger.debug( LTag.PUMP, "syncTemporaryBasalWithPumpId [date=${tempBasalProcessDTO.atechDateTime}, " + - "pumpId=${tempBasalProcessDTO.pumpId}, rate=${tbrEntry.insulinRate} U, " + - "duration=${tempBasalProcessDTO.durationAsSeconds} s, pumpSerial=${medtronicPumpStatus.serialNumber}]") + "pumpId=${tempBasalProcessDTO.pumpId}, rate=${tbrEntry.insulinRate} U, " + + "duration=${tempBasalProcessDTO.durationAsSeconds} s, pumpSerial=${medtronicPumpStatus.serialNumber}]" + ) if (tempBasalProcessDTO.durationAsSeconds <= 0) { uiInteraction.addNotification(Notification.MDT_INVALID_HISTORY_DATA, rh.gs(R.string.invalid_history_data), Notification.URGENT) @@ -718,8 +757,11 @@ class MedtronicHistoryData @Inject constructor( } } - if (isTBRActive(startTimestamp = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), - durationSeconds = tempBasalProcessDTO.durationAsSeconds)) { + if (isTBRActive( + startTimestamp = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), + durationSeconds = tempBasalProcessDTO.durationAsSeconds + ) + ) { if (medtronicPumpStatus.runningTBR == null) { medtronicPumpStatus.runningTBR = PumpDbEntryTBR( temporaryId = 0L, @@ -730,7 +772,8 @@ class MedtronicHistoryData @Inject constructor( isAbsolute = !tbrEntry.isPercent, durationInSeconds = tempBasalProcessDTO.durationAsSeconds, tbrType = PumpSync.TemporaryBasalType.NORMAL, - pumpId = tempBasalProcessDTO.pumpId) + pumpId = tempBasalProcessDTO.pumpId + ) } } } else { @@ -741,8 +784,7 @@ class MedtronicHistoryData @Inject constructor( } // collection } - - fun createTBRProcessList(entryList: MutableList) : MutableList { + fun createTBRProcessList(entryList: MutableList): MutableList { aapsLogger.debug(LTag.PUMP, "${ProcessHistoryRecord.TBR.description} List (before filter): ${gson.toJson(entryList)}") @@ -772,11 +814,11 @@ class MedtronicHistoryData @Inject constructor( } var previousItem: TempBasalProcessDTO? = null - val removalList : MutableList = arrayListOf() + val removalList: MutableList = arrayListOf() // fix for Zero TBRs for (tempBasalProcessDTO in processList) { - if (previousItem!=null) { + if (previousItem != null) { val pheEnd = PumpHistoryEntry() pheEnd.atechDateTime = DateTimeUtil.getATDWithAddedSeconds(tempBasalProcessDTO.itemOne.atechDateTime, -2) @@ -786,7 +828,7 @@ class MedtronicHistoryData @Inject constructor( previousItem.itemTwo = pheEnd - if (previousItem.durationAsSeconds <=0) { + if (previousItem.durationAsSeconds <= 0) { // if we have duration of 0 or less, then we have invalid entry which needs to be removed removalList.add(previousItem) } else if (previousItem.durationAsSeconds > initialDuration) { @@ -796,7 +838,7 @@ class MedtronicHistoryData @Inject constructor( previousItem = null } - if (tempBasalProcessDTO.itemOneTbr!!.isZeroTBR && tempBasalProcessDTO.itemTwo == null ) { + if (tempBasalProcessDTO.itemOneTbr!!.isZeroTBR && tempBasalProcessDTO.itemTwo == null) { previousItem = tempBasalProcessDTO } } @@ -852,33 +894,14 @@ class MedtronicHistoryData @Inject constructor( return processList } - fun findNearestEntry(startTime: Long, endTime: Long, list: MutableList) : PumpHistoryEntry? { - val outList: MutableList = mutableListOf() - - for (pumpHistoryEntry in list) { - if ((pumpHistoryEntry.atechDateTime > startTime) && - (pumpHistoryEntry.atechDateTime < endTime)) { - outList.add(pumpHistoryEntry) - } - } - - if (outList.size == 0) { - return null - } else if (outList.size==1) { - return outList[0] - } else { - // TODO - return null - } - } - fun isTBRActive(dbEntry: PumpDbEntryTBR): Boolean { return isTBRActive( startTimestamp = dbEntry.date, - durationSeconds = dbEntry.durationInSeconds) + durationSeconds = dbEntry.durationInSeconds + ) } - fun isTBRActive(startTimestamp: Long, durationSeconds: Int): Boolean { + private fun isTBRActive(startTimestamp: Long, durationSeconds: Int): Boolean { val endDate = startTimestamp + (durationSeconds * 1000) return (endDate > System.currentTimeMillis()) @@ -936,15 +959,32 @@ class MedtronicHistoryData @Inject constructor( } } if (outList.size == 1) { - if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}. Type=EntrySelected, AtTimeMin={}, AtTimeSec={}", treatment, outList[0], min, sec)) + if (doubleBolusDebug) aapsLogger.debug( + LTag.PUMP, + String.format( + Locale.ENGLISH, + "DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}. Type=EntrySelected, AtTimeMin={}, AtTimeSec={}", + treatment, + outList[0], + min, + sec + ) + ) return outList[0] } if (min == 0 && sec == 10 && outList.size > 1) { - aapsLogger.error(String.format(Locale.ENGLISH, "Too many entries (with too small diff): (timeDiff=[min=%d,sec=%d],count=%d,list=%s)", - min, sec, outList.size, gson.toJson(outList))) + aapsLogger.error( + String.format( + Locale.ENGLISH, "Too many entries (with too small diff): (timeDiff=[min=%d,sec=%d],count=%d,list=%s)", + min, sec, outList.size, gson.toJson(outList) + ) + ) if (doubleBolusDebug) aapsLogger.debug( - LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: findDbEntry Error - Too many entries (with too small diff): (timeDiff=[min=%d,sec=%d],count=%d,list=%s)", - min, sec, outList.size, gson.toJson(outList))) + LTag.PUMP, String.format( + Locale.ENGLISH, "DoubleBolusDebug: findDbEntry Error - Too many entries (with too small diff): (timeDiff=[min=%d,sec=%d],count=%d,list=%s)", + min, sec, outList.size, gson.toJson(outList) + ) + ) } sec += 10 } @@ -958,9 +998,10 @@ class MedtronicHistoryData @Inject constructor( aapsLogger.debug( LTag.PUMP, "processSuspends::syncTemporaryBasalWithPumpId [date=${tempBasalProcess.itemOne.atechDateTime}, " + - "rate=0.0, duration=${tempBasalProcess.durationAsSeconds} s, type=${PumpSync.TemporaryBasalType.PUMP_SUSPEND}, " + - "pumpId=${tempBasalProcess.itemOne.pumpId}, " + - "pumpSerial=${medtronicPumpStatus.serialNumber}]") + "rate=0.0, duration=${tempBasalProcess.durationAsSeconds} s, type=${PumpSync.TemporaryBasalType.PUMP_SUSPEND}, " + + "pumpId=${tempBasalProcess.itemOne.pumpId}, " + + "pumpSerial=${medtronicPumpStatus.serialNumber}]" + ) if (tempBasalProcess.durationAsSeconds <= 0) { uiInteraction.addNotification(Notification.MDT_INVALID_HISTORY_DATA, rh.gs(R.string.invalid_history_data), Notification.URGENT) @@ -995,8 +1036,10 @@ class MedtronicHistoryData @Inject constructor( } private fun getSuspendResumeRecordsList(): List { - val filteredItems = getFilteredItems(newHistory, // - setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump)) + val filteredItems = getFilteredItems( + newHistory, // + setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump) + ) aapsLogger.debug(LTag.PUMP, "SuspendResume Records: $filteredItems") @@ -1040,7 +1083,8 @@ class MedtronicHistoryData @Inject constructor( val tbrProcess = TempBasalProcessDTO( itemOne = filtered2Items[i], aapsLogger = aapsLogger, - objectType = TempBasalProcessDTO.ObjectType.Suspend) + objectType = TempBasalProcessDTO.ObjectType.Suspend + ) tbrProcess.itemTwo = filtered2Items[i + 1] @@ -1055,19 +1099,24 @@ class MedtronicHistoryData @Inject constructor( } private fun getNoDeliveryRewindPrimeRecordsList(): List { - val primeItems: MutableList = getFilteredItems(newHistory, // - setOf(PumpHistoryEntryType.Prime)) + val primeItems: MutableList = getFilteredItems( + newHistory, // + setOf(PumpHistoryEntryType.Prime) + ) aapsLogger.debug(LTag.PUMP, "Prime Records: $primeItems") val outList: MutableList = ArrayList() if (primeItems.size == 0) return outList - val filteredItems: MutableList = getFilteredItems(newHistory, // - setOf(PumpHistoryEntryType.Prime, + val filteredItems: MutableList = getFilteredItems( + newHistory, // + setOf( + PumpHistoryEntryType.Prime, PumpHistoryEntryType.Rewind, PumpHistoryEntryType.NoDeliveryAlarm, PumpHistoryEntryType.Bolus, - PumpHistoryEntryType.TempBasalCombined) + PumpHistoryEntryType.TempBasalCombined + ) ) aapsLogger.debug(LTag.PUMP, "Filtered Records: $filteredItems") @@ -1081,7 +1130,8 @@ class MedtronicHistoryData @Inject constructor( } if (startedItems) { if (filteredItem.entryType === PumpHistoryEntryType.Bolus || - filteredItem.entryType === PumpHistoryEntryType.TempBasalCombined) { + filteredItem.entryType === PumpHistoryEntryType.TempBasalCombined + ) { finishedItems = true break } @@ -1089,15 +1139,19 @@ class MedtronicHistoryData @Inject constructor( } } if (!finishedItems) { - val filteredItemsOld: MutableList = getFilteredItems(allHistory, // - setOf(PumpHistoryEntryType.Rewind, + val filteredItemsOld: MutableList = getFilteredItems( + allHistory, // + setOf( + PumpHistoryEntryType.Rewind, PumpHistoryEntryType.NoDeliveryAlarm, PumpHistoryEntryType.Bolus, - PumpHistoryEntryType.TempBasalCombined) + PumpHistoryEntryType.TempBasalCombined + ) ) for (filteredItem in filteredItemsOld) { if (filteredItem.entryType === PumpHistoryEntryType.Bolus || - filteredItem.entryType === PumpHistoryEntryType.TempBasalCombined) { + filteredItem.entryType === PumpHistoryEntryType.TempBasalCombined + ) { finishedItems = true break } @@ -1117,7 +1171,8 @@ class MedtronicHistoryData @Inject constructor( val tbrProcess = TempBasalProcessDTO( itemOne = items[items.size - 1], aapsLogger = aapsLogger, - objectType = TempBasalProcessDTO.ObjectType.Suspend) + objectType = TempBasalProcessDTO.ObjectType.Suspend + ) tbrProcess.itemTwo = itemTwo @@ -1132,7 +1187,8 @@ class MedtronicHistoryData @Inject constructor( val tbrProcess = TempBasalProcessDTO( itemOne = items[0], aapsLogger = aapsLogger, - objectType = TempBasalProcessDTO.ObjectType.Suspend) + objectType = TempBasalProcessDTO.ObjectType.Suspend + ) tbrProcess.itemTwo = itemTwo @@ -1170,8 +1226,10 @@ class MedtronicHistoryData @Inject constructor( } else when (medtronicUtil.medtronicPumpModel) { MedtronicDeviceType.Medtronic_515, MedtronicDeviceType.Medtronic_715 -> PumpHistoryEntryType.DailyTotals515 + MedtronicDeviceType.Medtronic_522, MedtronicDeviceType.Medtronic_722 -> PumpHistoryEntryType.DailyTotals522 + MedtronicDeviceType.Medtronic_523_Revel, MedtronicDeviceType.Medtronic_723_Revel, MedtronicDeviceType.Medtronic_554_Veo, @@ -1212,8 +1270,12 @@ class MedtronicHistoryData @Inject constructor( } fun hasPumpTimeChanged(): Boolean { - return getStateFromFilteredList(setOf(PumpHistoryEntryType.NewTimeSet, // - PumpHistoryEntryType.ChangeTime)) + return getStateFromFilteredList( + setOf( + PumpHistoryEntryType.NewTimeSet, // + PumpHistoryEntryType.ChangeTime + ) + ) } fun setIsInInit(init: Boolean) { @@ -1228,10 +1290,10 @@ class MedtronicHistoryData @Inject constructor( list.sortWith(PumpHistoryEntry.Comparator()) } - private fun preProcessTBRs(TBRs_Input: MutableList): MutableList { + private fun preProcessTBRs(tbrsInput: MutableList): MutableList { val tbrs: MutableList = mutableListOf() val map: MutableMap = HashMap() - for (pumpHistoryEntry in TBRs_Input) { + for (pumpHistoryEntry in tbrsInput) { if (map.containsKey(pumpHistoryEntry.DT)) { medtronicPumpHistoryDecoder.decodeTempBasal(map[pumpHistoryEntry.DT]!!, pumpHistoryEntry) pumpHistoryEntry.setEntryType(medtronicUtil.medtronicPumpModel, PumpHistoryEntryType.TempBasalCombined) @@ -1248,7 +1310,7 @@ class MedtronicHistoryData @Inject constructor( return getFilteredItems(newHistory, entryTypes) } - fun getFilteredItems(entryType: PumpHistoryEntryType): MutableList { + private fun getFilteredItems(entryType: PumpHistoryEntryType): MutableList { return getFilteredItems(newHistory, setOf(entryType)) } 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 17d0487958..00716a1860 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 @@ -26,10 +26,11 @@ import javax.inject.Singleton */ @Singleton @OpenForTesting -class MedtronicPumpStatus @Inject constructor(private val rh: ResourceHelper, - private val sp: SP, - private val rxBus: RxBus, - private val rileyLinkUtil: RileyLinkUtil +class MedtronicPumpStatus @Inject constructor( + private val rh: ResourceHelper, + private val sp: SP, + private val rxBus: RxBus, + private val rileyLinkUtil: RileyLinkUtil ) : PumpStatus(PumpType.MEDTRONIC_522_722) { var errorDescription: String? = null @@ -108,15 +109,13 @@ class MedtronicPumpStatus @Inject constructor(private val rh: ResourceHelper, // Battery type private var batteryTypeByDescMap: MutableMap = HashMap() - fun getBatteryTypeByDescription(batteryTypeStr: String?): BatteryType? { + fun getBatteryTypeByDescription(batteryTypeStr: String?): BatteryType { if (batteryTypeByDescMap.isEmpty()) { for (value in BatteryType.values()) { batteryTypeByDescMap[rh.gs(value.description)] = value } } - return if (batteryTypeByDescMap.containsKey(batteryTypeStr)) { - batteryTypeByDescMap[batteryTypeStr] - } else BatteryType.None + return batteryTypeByDescMap[batteryTypeStr] ?: BatteryType.None } override val errorInfo: String diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.kt index 121585fbff..e07baf9030 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.kt @@ -158,8 +158,8 @@ class RileyLinkMedtronicService : RileyLinkService() { medtronicPumpStatus.errorDescription = rh.gs(R.string.medtronic_error_pump_type_invalid) return false } else { - val pumpType = medtronicPumpStatus.medtronicPumpMap[pumpTypePart]!! - medtronicPumpStatus.medtronicDeviceType = medtronicPumpStatus.medtronicDeviceTypeMap[pumpTypePart]!! + val pumpType = medtronicPumpStatus.medtronicPumpMap[pumpTypePart] ?: return false + medtronicPumpStatus.medtronicDeviceType = medtronicPumpStatus.medtronicDeviceTypeMap[pumpTypePart] ?: return false medtronicPumpStatus.pumpType = pumpType medtronicPumpPlugin.pumpType = pumpType if (pumpTypePart.startsWith("7")) medtronicPumpStatus.reservoirFullUnits = 300 else medtronicPumpStatus.reservoirFullUnits = 176 @@ -223,8 +223,8 @@ class RileyLinkMedtronicService : RileyLinkService() { val batteryTypeStr = sp.getStringOrNull(MedtronicConst.Prefs.BatteryType, null) ?: return false val batteryType = medtronicPumpStatus.getBatteryTypeByDescription(batteryTypeStr) - if (medtronicPumpStatus.batteryType !== batteryType) { - medtronicPumpStatus.batteryType = batteryType!! + if (medtronicPumpStatus.batteryType != batteryType) { + medtronicPumpStatus.batteryType = batteryType } //String bolusDebugEnabled = sp.getStringOrNull(MedtronicConst.Prefs.BolusDebugEnabled, null); diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.kt index 2e53e74990..f4b3b6ef4b 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.kt @@ -240,9 +240,9 @@ class MedtronicUtil @Inject constructor( var pageNumber = 0 var frameNumber: Int? = null - fun setCurrentCommand(currentCommand: MedtronicCommandType, pageNumber_: Int, frameNumber_: Int?) { - pageNumber = pageNumber_ - frameNumber = frameNumber_ + fun setCurrentCommand(currentCommand: MedtronicCommandType, pageNumber: Int, frameNumber: Int?) { + this.pageNumber = pageNumber + this.frameNumber = frameNumber if (this.currentCommand !== currentCommand) { setCurrentCommand(currentCommand) } @@ -306,7 +306,9 @@ class MedtronicUtil @Inject constructor( return strokes } - fun isSame(d1: Double, d2: Double): Boolean { + fun isSame(d1: Double?, d2: Double?): Boolean { + d1 ?: return false + d2 ?: return false val diff = d1 - d2 return abs(diff) <= 0.000001 }