Ignore 0% battery readings in low-battery alerting #55

Merged
kamilkrzywda merged 1 commits from fix/battery-zero-ignore into main 2026-10-06 12:53:41 +02:00
Owner

What changed

Low-battery monitoring now ignores a 0% reading. A batteryLevel of 0 (or any non-positive value) is an invalid/no-data value — a node with no battery wired or a misconfigured node — not a genuinely critical battery, so it must not produce a ⚠️ battery low alert. Genuinely-low readings (1–20%) still alert exactly as before.

Code

  • src/battery/battery.service.ts — one-line guard in shouldAlert added right after the existing undefined check:
    if (node.batteryLevel === undefined) return false; // no battery reported — skip
    if (node.batteryLevel <= 0) return false; // 0/invalid reading — no battery wired or misconfigured node, not a real low-battery alert
    
    The threshold <=, cooldown, and single-batched-broadcast behavior are all unchanged.

Tests

Three new specs in the check threshold block of src/battery/battery.service.spec.ts:

  • a 0% node is excluded from the batch (a 5% node in the same batch still alerts);
  • a lone 0% reading sends no broadcast at all;
  • a 1% node (lowest valid value) is still alerted.

Existing check threshold / cooldown / end-to-end specs still pass.

Verification

  • npm run build → exit 0
  • npm test → 15 files / 183 tests passed (up from 180)

Version

v0.21.11 → v0.21.12 (patch); CHANGELOG.md entry added at the top.

## What changed Low-battery monitoring now **ignores a 0% reading**. A `batteryLevel` of 0 (or any non-positive value) is an invalid/no-data value — a node with no battery wired or a misconfigured node — not a genuinely critical battery, so it must not produce a `⚠️ battery low` alert. Genuinely-low readings (1–20%) still alert exactly as before. ### Code - `src/battery/battery.service.ts` — one-line guard in `shouldAlert` added right after the existing `undefined` check: ```ts if (node.batteryLevel === undefined) return false; // no battery reported — skip if (node.batteryLevel <= 0) return false; // 0/invalid reading — no battery wired or misconfigured node, not a real low-battery alert ``` The threshold `<=`, cooldown, and single-batched-broadcast behavior are all unchanged. ### Tests Three new specs in the `check threshold` block of `src/battery/battery.service.spec.ts`: - a **0%** node is excluded from the batch (a 5% node in the same batch still alerts); - a **lone 0%** reading sends no broadcast at all; - a **1%** node (lowest valid value) is still alerted. Existing `check threshold` / cooldown / end-to-end specs still pass. ## Verification - `npm run build` → exit 0 - `npm test` → 15 files / 183 tests passed (up from 180) ## Version v0.21.11 → v0.21.12 (patch); `CHANGELOG.md` entry added at the top.
kamilkrzywda added 1 commit 2026-10-06 10:03:03 +02:00
Ignore 0% battery readings in low-battery alerting
CI / build + unit (pull_request) Successful in 1m18s
7ec97a06d2
A 0% batteryLevel is an invalid/no-data value (no battery wired or
misconfigured node), not a genuinely critical battery, so it must not
produce a "⚠️ battery low" alert. Add a non-positive guard to
shouldAlert after the undefined check: 0 (and any non-positive) now
skips, while 1-20 still alert and >20 still doesn't. Threshold/cooldown/
batching unchanged.

Tests: 3 new specs in the check-threshold block (0% excluded from the
batch, lone 0% sends nothing, 1% still alerts). 180 -> 183.
kamilkrzywda merged commit b54f909fbc into main 2026-10-06 12:53:41 +02:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: OpenCode/MeshBot#55