Skip to content

feat: Add ability to read battery and charging status#106

Merged
mithun50 merged 2 commits intomithun50:mainfrom
craigmayhew:feat/battery-power-data
Apr 3, 2026
Merged

feat: Add ability to read battery and charging status#106
mithun50 merged 2 commits intomithun50:mainfrom
craigmayhew:feat/battery-power-data

Conversation

@craigmayhew
Copy link
Copy Markdown
Contributor

@craigmayhew craigmayhew commented Apr 2, 2026

This PR adds the ability for openclaw to read the battery and charging state from the device.

Thanks for a great project, and if this PR is desirable, please let me know how to improve it.

root@localhost:~# openclaw nodes invoke --node "OpenClawX Node" --command battery.status --params '{}'

🦞 OpenClaw 2026.4.1 (da64a97)
  I don't just autocomplete—I auto-commit (emotionally), then ask you to review (logically).

{
  "ok": true,
  "nodeId": "cabae60f17ab7f168c1606022fa0636524be6fcd87fa9c0482f4db84bd5f35e9",
  "command": "battery.status",
  "payload": {
    "temperatureC": 25,
    "level": 100,
    "percentage": 100,
    "scale": 100,
    "isCharging": false,
    "plugged": "UNPLUGGED",
    "status": "NOT CHARGING",
    "voltageMv": 5000
  },
  "payloadJSON": "{\"temperatureC\":25.0,\"level\":100,\"percentage\":100,\"scale\":100,\"isCharging\":false,\"plugged\":\"UNPLUGGED\",\"status\":\"NOT_CHARGING\",\"voltageMv\":5000}"
}

Summary by cubic

Adds a new battery capability so nodes can report device battery level, charging state, temperature, and voltage via the battery.status command. This enables monitoring power status from the app and gateway.

  • New Features
    • Android: Implemented getBatteryStatus in MainActivity using ACTION_BATTERY_CHANGED to return level, percentage, charging status, plug type, temperatureC, and voltageMv.
    • Flutter: Added BatteryCapability exposing battery.status, with NativeBridge.getBatteryStatus() to call the native method.
    • Wiring: Registered the capability in NodeProvider and allowed battery.status in GatewayService.

Written for commit 82fb9b2. Summary will update on new commits.

Summary by CodeRabbit

Release Notes

  • New Features
    • Battery status monitoring functionality has been added to the application. Users can now access and monitor comprehensive, real-time battery information including current charge percentage, active charging method (AC, USB, wireless, or unplugged), battery temperature readings, voltage measurements, and charging state indicators. This enhancement provides improved device power management and enhanced system monitoring capabilities.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 204d2416-7ba1-4a4d-8736-6c7565ed2b90

📥 Commits

Reviewing files that changed from the base of the PR and between 4d382e5 and 82fb9b2.

📒 Files selected for processing (5)
  • flutter_app/android/app/src/main/kotlin/com/nxg/openclawproot/MainActivity.kt
  • flutter_app/lib/providers/node_provider.dart
  • flutter_app/lib/services/capabilities/battery_capability.dart
  • flutter_app/lib/services/gateway_service.dart
  • flutter_app/lib/services/native_bridge.dart

📝 Walkthrough

Walkthrough

Adds battery status capability to the application. Native Android code retrieves battery information via a broadcast receiver. A Flutter bridge method invokes this native code via MethodChannel. A new BatteryCapability class handles battery.status commands, returning battery data through a NodeFrame response structure with proper error handling. The capability is registered with NodeProvider and whitelisted in the gateway service.

Changes

Cohort / File(s) Summary
Native Android Battery Reader
MainActivity.kt
Registers broadcast receiver for ACTION_BATTERY_CHANGED, extracts battery attributes (level, temperature, voltage, status, plugged state), computes percentage and derives status/plugged strings, returns HashMap with all fields or error on failure.
Flutter Bridge & Capability Handler
native_bridge.dart, battery_capability.dart
Added NativeBridge.getBatteryStatus() to invoke native MethodChannel. Created BatteryCapability class that handles battery.status command, invokes the bridge method, constructs NodeFrame responses with battery data or error payloads.
Service Registration
node_provider.dart, gateway_service.dart
Instantiated BatteryCapability and registered it in _registerCapabilities(). Added 'battery.status' to the gateway command allowlist in openclaw.json.

Sequence Diagram

sequenceDiagram
    participant Client as External Client
    participant Capability as BatteryCapability
    participant Bridge as NativeBridge
    participant MethodChannel as MethodChannel
    participant Native as Android Native

    Client->>Capability: battery.status command
    Capability->>Capability: _status()
    Capability->>Bridge: getBatteryStatus()
    Bridge->>MethodChannel: invokeMethod("getBatteryStatus")
    MethodChannel->>Native: getBatteryStatus handler
    Native->>Native: Register battery broadcast receiver
    Native->>Native: Extract battery extras (level, temp, voltage, status, plugged)
    Native->>Native: Compute percentage & derive status string
    Native-->>MethodChannel: Return HashMap with battery data
    MethodChannel-->>Bridge: Cast to Map<String, dynamic>
    Bridge-->>Capability: Return battery map
    Capability->>Capability: Construct NodeFrame.response
    Capability-->>Client: Return NodeFrame with battery data or error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A hop through circuits, a quest begun,
Battery whispers when charging is done,
From Kotlin to Flutter, the voltage does flow,
Status and temperature—now we shall know!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title directly and accurately summarizes the main objective: adding battery and charging status reading capability across native and Dart layers.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

@mithun50 mithun50 merged commit a32e7ec into mithun50:main Apr 3, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants