diff --git a/plugins/main/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt b/plugins/main/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt index 5becfcf64f..84aba04ab2 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt @@ -112,7 +112,8 @@ class StatusLightHandler @Inject constructor( private fun handleLevel(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) - view?.text = " " + DecimalFormatter.to0Decimal(level, units) + if (level > 0) view?.text = " " + DecimalFormatter.to0Decimal(level, units) + else view?.text = "" warnColors.setColorInverse(view, level, resWarn, resUrgent) } diff --git a/plugins/main/src/main/res/layout/overview_fragment.xml b/plugins/main/src/main/res/layout/overview_fragment.xml index 28185504f3..7c1d413be6 100644 --- a/plugins/main/src/main/res/layout/overview_fragment.xml +++ b/plugins/main/src/main/res/layout/overview_fragment.xml @@ -135,7 +135,7 @@ android:layout_height="wrap_content" android:paddingStart="4sp" android:paddingEnd="4sp" - android:text="Pump: running" + tools:text="Pump: running" android:textSize="16sp" tools:ignore="HardcodedText" /> @@ -146,7 +146,7 @@ android:layout_weight="1" android:paddingStart="4sp" android:paddingEnd="4sp" - android:text="OpenAPS: 3 min ago" + tools:text="OpenAPS: 3 min ago" android:textSize="16sp" tools:ignore="HardcodedText" /> @@ -157,7 +157,7 @@ android:layout_weight="1" android:paddingStart="4sp" android:paddingEnd="4sp" - android:text="Uploader: 84%" + tools:text="Uploader: 84%" android:textSize="16sp" tools:ignore="HardcodedText" /> diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/ProcessedDeviceStatusDataImpl.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/ProcessedDeviceStatusDataImpl.kt index d65d63dad4..29de582b6c 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/ProcessedDeviceStatusDataImpl.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/data/ProcessedDeviceStatusDataImpl.kt @@ -36,32 +36,33 @@ class ProcessedDeviceStatusDataImpl @Inject constructor( // test warning level // color override fun pumpStatus(nsSettingsStatus: NSSettingsStatus): Spanned { - val pumpData = pumpData ?: return HtmlHelper.fromHtml("") - //String[] ALL_STATUS_FIELDS = {"reservoir", "battery", "clock", "status", "device"}; - val string = StringBuilder() - .append("") - .append(rh.gs(info.nightscout.core.ui.R.string.pump)) - .append(": ") + //String[] ALL_STATUS_FIELDS = {"reservoir", "battery", "clock", "status", "device"}; + val string = StringBuilder() + .append("") + .append(rh.gs(info.nightscout.core.ui.R.string.pump)) + .append(": ") - // test warning level - val level = when { - pumpData.clock + nsSettingsStatus.extendedPumpSettings("urgentClock") * 60 * 1000L < dateUtil.now() -> ProcessedDeviceStatusData.Levels.URGENT - pumpData.reservoir < nsSettingsStatus.extendedPumpSettings("urgentRes") -> ProcessedDeviceStatusData.Levels.URGENT - pumpData.isPercent && pumpData.percent < nsSettingsStatus.extendedPumpSettings("urgentBattP") -> ProcessedDeviceStatusData.Levels.URGENT - !pumpData.isPercent && pumpData.voltage > 0 && pumpData.voltage < nsSettingsStatus.extendedPumpSettings("urgentBattV") -> ProcessedDeviceStatusData.Levels.URGENT - pumpData.clock + nsSettingsStatus.extendedPumpSettings("warnClock") * 60 * 1000L < dateUtil.now() -> ProcessedDeviceStatusData.Levels.WARN - pumpData.reservoir < nsSettingsStatus.extendedPumpSettings("warnRes") -> ProcessedDeviceStatusData.Levels.WARN - pumpData.isPercent && pumpData.percent < nsSettingsStatus.extendedPumpSettings("warnBattP") -> ProcessedDeviceStatusData.Levels.WARN + val pumpData = pumpData ?: return HtmlHelper.fromHtml(string.toString()) + + // test warning level + val level = when { + pumpData.clock + nsSettingsStatus.extendedPumpSettings("urgentClock") * 60 * 1000L < dateUtil.now() -> ProcessedDeviceStatusData.Levels.URGENT + pumpData.reservoir < nsSettingsStatus.extendedPumpSettings("urgentRes") -> ProcessedDeviceStatusData.Levels.URGENT + pumpData.isPercent && pumpData.percent < nsSettingsStatus.extendedPumpSettings("urgentBattP") -> ProcessedDeviceStatusData.Levels.URGENT + !pumpData.isPercent && pumpData.voltage > 0 && pumpData.voltage < nsSettingsStatus.extendedPumpSettings("urgentBattV") -> ProcessedDeviceStatusData.Levels.URGENT + pumpData.clock + nsSettingsStatus.extendedPumpSettings("warnClock") * 60 * 1000L < dateUtil.now() -> ProcessedDeviceStatusData.Levels.WARN + pumpData.reservoir < nsSettingsStatus.extendedPumpSettings("warnRes") -> ProcessedDeviceStatusData.Levels.WARN + pumpData.isPercent && pumpData.percent < nsSettingsStatus.extendedPumpSettings("warnBattP") -> ProcessedDeviceStatusData.Levels.WARN !pumpData.isPercent && pumpData.voltage > 0 && pumpData.voltage < nsSettingsStatus.extendedPumpSettings("warnBattV") -> ProcessedDeviceStatusData.Levels.WARN else -> ProcessedDeviceStatusData.Levels.INFO } string.append("") val insulinUnit = rh.gs(info.nightscout.core.ui.R.string.insulin_unit_shortname) val fields = nsSettingsStatus.pumpExtendedSettingsFields() - if (pumpData.reservoirDisplayOverride != "") - string.append(pumpData.reservoirDisplayOverride).append("$insulinUnit ") - else if (fields.contains("reservoir")) string.append(pumpData.reservoir.toInt()).append("$insulinUnit ") + // Removed here. Same value is in StatusLights + // 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(" ") @@ -139,13 +140,19 @@ class ProcessedDeviceStatusDataImpl @Inject constructor( string.append(": ") val iterator: Iterator<*> = uploaderMap.entries.iterator() var minBattery = 100 + var found = false while (iterator.hasNext()) { val pair = iterator.next() as Map.Entry<*, *> val uploader = pair.value as ProcessedDeviceStatusData.Uploader - if (minBattery > uploader.battery) minBattery = uploader.battery + if (minBattery > uploader.battery) { + minBattery = uploader.battery + found = true + } + } + if (found) { + string.append(minBattery) + string.append("%") } - string.append(minBattery) - string.append("%") return HtmlHelper.fromHtml(string.toString()) } diff --git a/pump/virtual/src/main/java/info/nightscout/pump/virtual/VirtualPumpPlugin.kt b/pump/virtual/src/main/java/info/nightscout/pump/virtual/VirtualPumpPlugin.kt index 9db3437861..74c18b7a41 100644 --- a/pump/virtual/src/main/java/info/nightscout/pump/virtual/VirtualPumpPlugin.kt +++ b/pump/virtual/src/main/java/info/nightscout/pump/virtual/VirtualPumpPlugin.kt @@ -12,6 +12,7 @@ import info.nightscout.core.utils.fabric.InstanceId import info.nightscout.interfaces.Config import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.notifications.Notification +import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.profile.Profile @@ -62,7 +63,8 @@ open class VirtualPumpPlugin @Inject constructor( commandQueue: CommandQueue, private val pumpSync: PumpSync, private val config: Config, - private val dateUtil: DateUtil + private val dateUtil: DateUtil, + private val processedDeviceStatusData: ProcessedDeviceStatusData ) : PumpPluginBase( PluginDescription() .mainType(PluginType.PUMP) @@ -169,7 +171,9 @@ open class VirtualPumpPlugin @Inject constructor( get() = profileFunction.getProfile()?.getBasal() ?: 0.0 override val reservoirLevel: Double - get() = reservoirInUnits.toDouble() + get() = + if (config.NSCLIENT) processedDeviceStatusData.pumpData?.reservoir ?: -1.0 + else reservoirInUnits.toDouble() override val batteryLevel: Int get() = batteryPercent diff --git a/pump/virtual/src/test/java/info/nightscout/pump/virtual/VirtualPumpPluginUTest.kt b/pump/virtual/src/test/java/info/nightscout/pump/virtual/VirtualPumpPluginUTest.kt index 872bb7c8eb..6c8edfbda9 100644 --- a/pump/virtual/src/test/java/info/nightscout/pump/virtual/VirtualPumpPluginUTest.kt +++ b/pump/virtual/src/test/java/info/nightscout/pump/virtual/VirtualPumpPluginUTest.kt @@ -5,6 +5,7 @@ import info.nightscout.androidaps.TestBase import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.interfaces.Config import info.nightscout.interfaces.iob.IobCobCalculator +import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.defs.PumpType @@ -31,12 +32,17 @@ class VirtualPumpPluginUTest : TestBase() { @Mock lateinit var dateUtil: DateUtil @Mock lateinit var pumpSync: PumpSync @Mock lateinit var config: Config + @Mock lateinit var processedDeviceStatusData: ProcessedDeviceStatusData private lateinit var virtualPumpPlugin: VirtualPumpPlugin @BeforeEach fun prepareMocks() { - virtualPumpPlugin = VirtualPumpPlugin({ AndroidInjector { } }, aapsLogger, rxBus, fabricPrivacy, rh, aapsSchedulers, sp, profileFunction, iobCobCalculator, commandQueue, pumpSync, config, dateUtil) + virtualPumpPlugin = VirtualPumpPlugin( + { AndroidInjector { } }, + aapsLogger, rxBus, fabricPrivacy, rh, aapsSchedulers, sp, profileFunction, iobCobCalculator, + commandQueue, pumpSync, config, dateUtil, processedDeviceStatusData + ) } @Test