[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.
This commit is contained in:
Nicolas Fella 2020-12-02 23:22:05 +01:00
parent 28e04a3569
commit 4011cecf05

View file

@ -102,14 +102,12 @@ void BatteryPlugin::slotChargeChanged()
// Prepare an outgoing network packet // Prepare an outgoing network packet
NetworkPacket status(PACKET_TYPE_BATTERY, {{}}); NetworkPacket status(PACKET_TYPE_BATTERY, {{}});
status.set(QStringLiteral("isCharging"), isAnyBatteryCharging); 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 // FIXME: In future, we should consider sending an array of battery objects
status.set(QStringLiteral("batteryQuantity"), batteryQuantity); status.set(QStringLiteral("batteryQuantity"), batteryQuantity);
// We consider the primary battery to be low if it won't last another 10 minutes. // We consider the primary battery to be low if it's below 15%
// This doesn't necessarily work if (for example) Solid finds multiple batteries. if (charge <= 15 && chosen->chargeState() == Solid::Battery::ChargeState::Discharging) {
// 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) {
status.set(QStringLiteral("thresholdEvent"), (int)ThresholdBatteryLow); status.set(QStringLiteral("thresholdEvent"), (int)ThresholdBatteryLow);
} else { } else {
status.set(QStringLiteral("thresholdEvent"), (int)ThresholdNone); status.set(QStringLiteral("thresholdEvent"), (int)ThresholdNone);