Determine case charging state more accurately

The previous logic for determining if the case was charging relied on the `batteryCasePercent` being non-null. This commit refines the logic to check if the `batteryCasePercent` falls within the valid range of 0.0 to 1.0, providing a more accurate assessment of the case's charging status.
This commit is contained in:
darken
2025-06-06 06:03:41 +02:00
committed by Matthias Urhahn
parent 3b2dcc1a5c
commit 2ff143b858
@@ -148,8 +148,9 @@ interface DualApplePods : ApplePods, HasChargeDetectionDual, DualPodDevice, HasE
override val isCaseCharging: Boolean
get() {
payload.private?.data?.get(3)?.let { raw ->
val level = (raw and 0x7Fu).toInt() / 100f
val isCharging = (raw and 0x80u).toInt() != 0
if (batteryCasePercent != null) return isCharging
if (0f <= level && level <= 1.0f) return isCharging
}
return pubFlags.isBitSet(2)