From 1afe060e0913626cc448350242d09072d2f95489 Mon Sep 17 00:00:00 2001 From: Michael Kroes Date: Mon, 24 Oct 2022 16:22:07 +0200 Subject: [PATCH] Improved AAPSClient display of reservoir level and pump status when using OmniPod DASH --- .../general/nsclient/data/DeviceStatusData.kt | 1 + .../general/nsclient/data/NSDeviceStatus.kt | 11 ++++++++--- .../general/overview/StatusLightHandler.kt | 16 +++++++++------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/DeviceStatusData.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/DeviceStatusData.kt index 9368d5a110..a4b1b7ff7e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/DeviceStatusData.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/DeviceStatusData.kt @@ -16,6 +16,7 @@ class DeviceStatusData @Inject constructor() { var voltage = 0.0 var status = "N/A" var reservoir = 0.0 + var reservoirDisplayOverride = "" var extended: Spanned? = null var activeProfileName: String? = null } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.kt index 7a42d9efdd..37248349da 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.kt @@ -168,16 +168,20 @@ class NSDeviceStatus @Inject constructor( pumpData.clock + nsSettingsStatus.extendedPumpSettings("urgentClock") * 60 * 1000L < dateUtil.now() -> Levels.URGENT pumpData.reservoir < nsSettingsStatus.extendedPumpSettings("urgentRes") -> Levels.URGENT pumpData.isPercent && pumpData.percent < nsSettingsStatus.extendedPumpSettings("urgentBattP") -> Levels.URGENT - !pumpData.isPercent && pumpData.voltage < nsSettingsStatus.extendedPumpSettings("urgentBattV") -> Levels.URGENT + !pumpData.isPercent && pumpData.voltage > 0 && pumpData.voltage < nsSettingsStatus.extendedPumpSettings("urgentBattV") -> Levels.URGENT pumpData.clock + nsSettingsStatus.extendedPumpSettings("warnClock") * 60 * 1000L < dateUtil.now() -> Levels.WARN pumpData.reservoir < nsSettingsStatus.extendedPumpSettings("warnRes") -> Levels.WARN pumpData.isPercent && pumpData.percent < nsSettingsStatus.extendedPumpSettings("warnBattP") -> Levels.WARN - !pumpData.isPercent && pumpData.voltage < nsSettingsStatus.extendedPumpSettings("warnBattV") -> Levels.WARN + !pumpData.isPercent && pumpData.voltage > 0 && pumpData.voltage < nsSettingsStatus.extendedPumpSettings("warnBattV") -> Levels.WARN else -> Levels.INFO } string.append("") + val insulinUnit = rh.gs(R.string.insulin_unit_shortname) val fields = nsSettingsStatus.pumpExtendedSettingsFields() - if (fields.contains("reservoir")) string.append(pumpData.reservoir.toInt()).append("U ") + if (pumpData.reservoirDisplayOverride != "") { + string.append(pumpData.reservoirDisplayOverride).append("$insulinUnit ") + } + else if (fields.contains("reservoir")) string.append(pumpData.reservoir.toInt()).append("$insulinUnit ") if (fields.contains("battery") && pumpData.isPercent) string.append(pumpData.percent).append("% ") if (fields.contains("battery") && !pumpData.isPercent) string.append(Round.roundTo(pumpData.voltage, 0.001)).append(" ") if (fields.contains("clock")) string.append(dateUtil.minAgo(rh, pumpData.clock)).append(" ") @@ -200,6 +204,7 @@ class NSDeviceStatus @Inject constructor( deviceStatusPumpData.clock = clock if (pump.has("status") && pump.getJSONObject("status").has("status")) deviceStatusPumpData.status = pump.getJSONObject("status").getString("status") if (pump.has("reservoir")) deviceStatusPumpData.reservoir = pump.getDouble("reservoir") + if (pump.has("reservoir_display_override")) deviceStatusPumpData.reservoirDisplayOverride = pump.getString("reservoir_display_override") if (pump.has("battery") && pump.getJSONObject("battery").has("percent")) { deviceStatusPumpData.isPercent = true deviceStatusPumpData.percent = pump.getJSONObject("battery").getInt("percent") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/StatusLightHandler.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/StatusLightHandler.kt index 18c902f6a4..85ebc8a98a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/StatusLightHandler.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/StatusLightHandler.kt @@ -43,13 +43,15 @@ class StatusLightHandler @Inject constructor( if (pump.pumpDescription.isBatteryReplaceable || pump.isBatteryChangeLoggingEnabled()) { handleAge(careportal_pb_age, TherapyEvent.Type.PUMP_BATTERY_CHANGE, R.string.key_statuslights_bage_warning, 216.0, R.string.key_statuslights_bage_critical, 240.0) } + + val insulinUnit = rh.gs(R.string.insulin_unit_shortname) + if (pump.model() == PumpType.OMNIPOD_EROS || pump.model() == PumpType.OMNIPOD_DASH) { + handleOmnipodReservoirLevel(careportal_reservoir_level, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit) + } else { + handleLevel(careportal_reservoir_level, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit) + } + if (!config.NSCLIENT) { - val insulinUnit = rh.gs(R.string.insulin_unit_shortname) - if (pump.model() == PumpType.OMNIPOD_EROS || pump.model() == PumpType.OMNIPOD_DASH) { - handleOmnipodReservoirLevel(careportal_reservoir_level, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit) - } else { - handleLevel(careportal_reservoir_level, R.string.key_statuslights_res_critical, 10.0, R.string.key_statuslights_res_warning, 80.0, pump.reservoirLevel, insulinUnit) - } if (bgSource.sensorBatteryLevel != -1) handleLevel(careportal_sensor_battery_level, R.string.key_statuslights_sbat_critical, 5.0, R.string.key_statuslights_sbat_warning, 20.0, bgSource.sensorBatteryLevel.toDouble(), "%") else @@ -94,7 +96,7 @@ class StatusLightHandler @Inject constructor( // Omnipod only reports reservoir level when it's 50 units or less, so we display "50+U" for any value > 50 @Suppress("SameParameterValue") private fun handleOmnipodReservoirLevel(view: TextView?, criticalSetting: Int, criticalDefaultValue: Double, warnSetting: Int, warnDefaultValue: Double, level: Double, units: String) { - if (level > OmnipodConstants.MAX_RESERVOIR_READING) { + if (level >= OmnipodConstants.MAX_RESERVOIR_READING) { @Suppress("SetTextI18n") view?.text = " 50+$units" view?.setTextColor(rh.gac(view.context, R.attr.defaultTextColor))