From 4011cecf05b88d2276a7ed3a6b340e2573e4c3b1 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Wed, 2 Dec 2020 23:22:05 +0100 Subject: [PATCH] [plugins/battery] Determine empty battery based on percentage instead of remaning time timeToEmpty in UPower is unreliable, e.g. it's always 0 on the PinePhone. Instead warn when the percentage drops below 15%. That's how it is for Android anyway. --- plugins/battery/batteryplugin.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/battery/batteryplugin.cpp b/plugins/battery/batteryplugin.cpp index 15c6b28cc..22ebe29ac 100644 --- a/plugins/battery/batteryplugin.cpp +++ b/plugins/battery/batteryplugin.cpp @@ -102,14 +102,12 @@ void BatteryPlugin::slotChargeChanged() // Prepare an outgoing network packet NetworkPacket status(PACKET_TYPE_BATTERY, {{}}); status.set(QStringLiteral("isCharging"), isAnyBatteryCharging); - status.set(QStringLiteral("currentCharge"), cumulativeCharge / batteryQuantity); + const int charge = cumulativeCharge / batteryQuantity; + status.set(QStringLiteral("currentCharge"), charge); // FIXME: In future, we should consider sending an array of battery objects status.set(QStringLiteral("batteryQuantity"), batteryQuantity); - // We consider the primary battery to be low if it won't last another 10 minutes. - // This doesn't necessarily work if (for example) Solid finds multiple batteries. - // FIXME: In future, we should check system settings instead of hardcoding an - // amount of time. - if (chosen->timeToEmpty() < 600 && chosen->chargeState() == Solid::Battery::ChargeState::Discharging) { + // We consider the primary battery to be low if it's below 15% + if (charge <= 15 && chosen->chargeState() == Solid::Battery::ChargeState::Discharging) { status.set(QStringLiteral("thresholdEvent"), (int)ThresholdBatteryLow); } else { status.set(QStringLiteral("thresholdEvent"), (int)ThresholdNone);