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 f00707a15c..0c3bb72cb3 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 @@ -9,6 +9,7 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.db.CareportalEvent import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.pump.common.defs.PumpType +import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.OmnipodConstants import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.WarnColors @@ -49,8 +50,14 @@ class StatusLightHandler @Inject constructor( else careportal_sensorbatterylevel?.text = "" } - if (!config.NSCLIENT && pump.model() != PumpType.AccuChekCombo) - handleLevel(careportal_batterylevel, R.string.key_statuslights_bat_critical, 26.0, R.string.key_statuslights_bat_warning, 51.0, pump.batteryLevel.toDouble(), "%") + + if (!config.NSCLIENT) { + if (pump.model() == PumpType.Insulet_Omnipod) { + handleOmnipodBatteryLevel(careportal_batterylevel, R.string.key_statuslights_bat_critical, 26.0, R.string.key_statuslights_bat_warning, 51.0, pump.batteryLevel.toDouble(), "%", (pump as OmnipodPumpPlugin).isUseRileyLinkBatteryLevel) + } else if (pump.model() != PumpType.AccuChekCombo) { + handleLevel(careportal_batterylevel, R.string.key_statuslights_bat_critical, 26.0, R.string.key_statuslights_bat_warning, 51.0, pump.batteryLevel.toDouble(), "%") + } + } } private fun handleAge(view: TextView?, eventName: String, @StringRes warnSettings: Int, defaultWarnThreshold: Double, @StringRes urgentSettings: Int, defaultUrgentThreshold: Double) { @@ -75,16 +82,21 @@ 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 private fun handleOmnipodReservoirLevel(view: TextView?, criticalSetting: Int, criticalDefaultValue: Double, warnSetting: Int, warnDefaultValue: Double, level: Double, units: String) { - val resUrgent = sp.getDouble(criticalSetting, criticalDefaultValue) - val resWarn = sp.getDouble(warnSetting, warnDefaultValue) if (level > OmnipodConstants.MAX_RESERVOIR_READING) { @Suppress("SetTextI18n") view?.text = " 50+$units" view?.setTextColor(Color.WHITE) } else { - @Suppress("SetTextI18n") - view?.text = " " + DecimalFormatter.to0Decimal(level) + units - warnColors.setColorInverse(view, level, resWarn, resUrgent) + handleLevel(view, criticalSetting, criticalDefaultValue, warnSetting, warnDefaultValue, level, units) + } + } + + private fun handleOmnipodBatteryLevel(view: TextView?, criticalSetting: Int, criticalDefaultValue: Double, warnSetting: Int, warnDefaultValue: Double, level: Double, units: String, useRileyLinkBatteryLevel: Boolean) { + if (useRileyLinkBatteryLevel) { + handleLevel(view, criticalSetting, criticalDefaultValue, warnSetting, warnDefaultValue, level, units) + } else { + view?.text = resourceHelper.gs(R.string.notavailable) + view?.setTextColor(Color.WHITE) } } } \ No newline at end of file diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java index 36c9a5cae8..fcaea154b0 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java @@ -119,7 +119,6 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, private static final long STATUS_CHECK_INTERVAL_MILLIS = 60 * 1000L; // 1 minute public static final int STARTUP_STATUS_REQUEST_TRIES = 2; public static final double RESERVOIR_OVER_50_UNITS_DEFAULT = 75.0; - private static final int DEFAULT_BATTERY_LEVEL = 75; private final PodStateManager podStateManager; private final RileyLinkServiceData rileyLinkServiceData; @@ -617,7 +616,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, return rileyLinkServiceData.batteryLevel == null ? 0 : rileyLinkServiceData.batteryLevel; } - return DEFAULT_BATTERY_LEVEL; + return 0; } @NonNull @Override @@ -741,7 +740,9 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, status.put("timestamp", DateUtil.toISOString(new Date())); - pump.put("battery", battery); + if (isUseRileyLinkBatteryLevel()) { + pump.put("battery", battery); + } pump.put("status", status); pump.put("extended", extended); @@ -779,34 +780,34 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, return pumpDescription; } - // FIXME i18n, null checks: iob, TDD @NonNull @Override public String shortStatus(boolean veryShort) { if (!podStateManager.isPodActivationCompleted()) { - return "No active pod"; + return resourceHelper.gs(R.string.omnipod_short_status_no_active_pod); } String ret = ""; if (lastConnectionTimeMillis != 0) { long agoMsec = System.currentTimeMillis() - lastConnectionTimeMillis; int agoMin = (int) (agoMsec / 60d / 1000d); - ret += "LastConn: " + agoMin + " min ago\n"; + ret += resourceHelper.gs(R.string.omnipod_short_status_last_connection, agoMin) + "\n"; } if (podStateManager.getLastBolusStartTime() != null) { - ret += "LastBolus: " + DecimalFormatter.to2Decimal(podStateManager.getLastBolusAmount()) + "U @" + // - android.text.format.DateFormat.format("HH:mm", podStateManager.getLastBolusStartTime().toDate()) + "\n"; + ret += resourceHelper.gs(R.string.omnipod_short_status_last_bolus, DecimalFormatter.to2Decimal(podStateManager.getLastBolusAmount()), + android.text.format.DateFormat.format("HH:mm", podStateManager.getLastBolusStartTime().toDate())) + "\n"; } TemporaryBasal activeTemp = activePlugin.getActiveTreatments().getRealTempBasalFromHistory(System.currentTimeMillis()); if (activeTemp != null) { - ret += "Temp: " + activeTemp.toStringFull() + "\n"; + ret += resourceHelper.gs(R.string.omnipod_short_status_temp_basal, activeTemp.toStringFull()) + "\n"; } ExtendedBolus activeExtendedBolus = activePlugin.getActiveTreatments().getExtendedBolusFromHistory( System.currentTimeMillis()); if (activeExtendedBolus != null) { - ret += "Extended: " + activeExtendedBolus.toString() + "\n"; + ret += resourceHelper.gs(R.string.omnipod_short_status_extended_bolus, activeExtendedBolus.toString()) + "\n"; + } + ret += resourceHelper.gs(R.string.omnipod_short_status_reservoir, (getReservoirLevel() > OmnipodConstants.MAX_RESERVOIR_READING ? "50+" : DecimalFormatter.to0Decimal(getReservoirLevel()))) + "\n"; + if (isUseRileyLinkBatteryLevel()) { + ret += resourceHelper.gs(R.string.omnipod_short_status_rl_battery, getBatteryLevel()) + "\n"; } - ret += "Reserv: " + (getReservoirLevel() > OmnipodConstants.MAX_RESERVOIR_READING ? "50+U" : DecimalFormatter.to0Decimal(getReservoirLevel()) + "U") + "\n"; - ret += "Batt: " + getBatteryLevel(); - return ret.trim(); } @@ -1042,6 +1043,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, return getOperationNotSupportedWithCustomText(info.nightscout.androidaps.core.R.string.pump_operation_not_supported_by_pump_driver); } + public boolean isUseRileyLinkBatteryLevel() { + return aapsOmnipodManager.isUseRileyLinkBatteryLevel(); + } + private void initializeAfterRileyLinkConnection() { if (podStateManager.getActivationProgress().isAtLeast(ActivationProgress.PAIRING_COMPLETED)) { boolean success = false; diff --git a/omnipod/src/main/res/values/strings.xml b/omnipod/src/main/res/values/strings.xml index aa39003f05..45481f312e 100644 --- a/omnipod/src/main/res/values/strings.xml +++ b/omnipod/src/main/res/values/strings.xml @@ -44,8 +44,8 @@ Show Suspend Delivery button in Omnipod tab Show Pulse Log button in Pod Management menu Show RileyLink Stats button in Pod Management menu - Use battery level reported by RileyLink (experimental) - Only tested with EmaLink. The reported battery level may be inaccurate with other devices.\nWhen disabled, the battery level show a fixed value of 75. + Use battery level reported by RileyLink + Works with EmaLink and OrangeLink.\nDOES NOT work with the original RileyLink: it will not report the actual battery level. Might also not work with other RileyLink alternatives. DST/Time zone detection enabled Expiration reminder enabled Hours before shutdown @@ -91,6 +91,15 @@ %1$.2f U, CH=%2$.1f g Rate: %1$.2f U, duration: %2$d minutes + + No active Pod + LastConn: %1$d min ago + LastBolus: %1$s @ %2$s + Temp: %1$s + Extended: %1$s + Reserv: %1$sU + RLBatt: %1$d + Warning RileyLink address invalid.