[Repo Assist] feat(device): add BatteryStatusRequested event to DeviceCapability#248
Closed
github-actions[bot] wants to merge 1 commit intomasterfrom
Closed
Conversation
DeviceCapability.HandleStatus() always returned battery as null/unknown. Issue #240 identified that real battery data requires WinRT APIs (Windows.Devices.Power.Battery) that are unavailable in the cross-platform Shared project (net10.0 TFM). Follows the same event-delegation pattern used by CameraCapability and ScreenCapability: the capability exposes a Func<Task<DeviceBatteryStatus?>> event; the Tray.WinUI project subscribes a WinRT-backed provider. Changes: - DeviceCapability: add BatteryStatusRequested event + DeviceBatteryStatus class - HandleStatus -> HandleStatusAsync: awaits provider if wired; falls back gracefully to unknown if provider throws or is null - battery response now includes a 'present' field (false when no provider) - NodeService.cs: TODO comment marking where WinRT provider should be wired - CapabilityTests: 4 new tests covering charging, unplugged, not-present, and provider-throws-graceful-fallback scenarios Test Status: - Shared.Tests: 1045 passed (+4), 5 pre-existing McpHttpServer failures, 20 skipped - Tray.Tests: 245 passed, 0 failed Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
17 tasks
Contributor
|
Closing per repo-assist triage: this is superseded by #249 and is not useful enough on its own without the provider-backed battery implementation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated PR from Repo Assist.
Implements the
BatteryStatusRequestedevent API described in issue #240 and tracked in Repo Assist's future-work list. This opens the door for real battery data indevice.statusresponses without adding WinRT dependencies to the cross-platformOpenClaw.Sharedproject.Background
device.statushas always returned a battery stub:{"level": null, "state": "unknown", "lowPowerModeEnabled": false}Issue #240 identified that battery info requires
Windows.Devices.Power.Battery(WinRT), which is only available inOpenClaw.Tray.WinUI(TFMnet10.0-windows10.0.19041.0). The Shared project targetsnet10.0(cross-platform) and cannot use WinRT directly.Solution
Same event-delegation pattern used by
CameraCapabilityandScreenCapability:Changes
src/OpenClaw.Shared/Capabilities/DeviceCapability.csBatteryStatusRequested:Func<Task<DeviceBatteryStatus?>>?eventDeviceBatteryStatusclass:Present,ChargePercent?,IsCharging,EstimatedMinutesRemaining?HandleStatus→HandleStatusAsync: awaits the provider if wired; falls back gracefully if provider is null or throwspresentfield (falsewhen no provider is wired)ExecuteAsyncupdated to awaitHandleStatusAsyncsrc/OpenClaw.Tray.WinUI/Services/NodeService.cs_deviceCapabilityregistration pointing to where the WinRTBatteryStatusProvidershould be wired. Actual WinRT implementation is the follow-up step.tests/OpenClaw.Shared.Tests/CapabilityTests.csFour new tests in
DeviceCapabilityTests:DeviceStatus_BatteryProvider_Charging_ReturnsChargingStatestate=charging,level≈0.72DeviceStatus_BatteryProvider_Unplugged_ReturnsUnpluggedStatestate=unpluggedDeviceStatus_BatteryProvider_NotPresent_ReturnsUnknownstate=unknown, present=falseDeviceStatus_BatteryProvider_Throws_FallsBackToUnknowndevice.statusstill succeeds, falls back to stubTest Status
OpenClaw.Shared.TestsOpenClaw.Tray.Tests./build.ps1Next Step
Wire
_deviceCapability.BatteryStatusRequestedinNodeService.csto a WinRT implementation usingWindows.Devices.Power.Battery.AggregateBattery.GetReport(). This is a Windows-only build step that requires the WinUI project — best done in a follow-up PR on a Windows machine.