fix reservoir value in nsclient status

This commit is contained in:
Milos Kozak 2022-12-15 10:29:09 +01:00
parent 4a1fc0f45c
commit 31a6bf4460
5 changed files with 46 additions and 28 deletions

View file

@ -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)
}

View file

@ -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" />

View file

@ -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("<span style=\"color:${rh.gac(info.nightscout.core.ui.R.attr.nsTitleColor)}\">")
.append(rh.gs(info.nightscout.core.ui.R.string.pump))
.append(": </span>")
//String[] ALL_STATUS_FIELDS = {"reservoir", "battery", "clock", "status", "device"};
val string = StringBuilder()
.append("<span style=\"color:${rh.gac(info.nightscout.core.ui.R.attr.nsTitleColor)}\">")
.append(rh.gs(info.nightscout.core.ui.R.string.pump))
.append(": </span>")
// 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("<span style=\"color:${level.toColor()}\">")
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(": </span>")
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())
}

View file

@ -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

View file

@ -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