Skip to content

fix(battery): aggregate physical UPower devices - #346

Open
kaiyasi wants to merge 2 commits into
wayle-rs:masterfrom
kaiyasi:fix/battery-charge-threshold
Open

fix(battery): aggregate physical UPower devices#346
kaiyasi wants to merge 2 commits into
wayle-rs:masterfrom
kaiyasi:fix/battery-charge-threshold

Conversation

@kaiyasi

@kaiyasi kaiyasi commented Aug 10, 2026

Copy link
Copy Markdown

Summary

  • Aggregate rechargeable physical UPower battery and UPS devices without relying on DisplayDevice.
  • Combine percentage, energy, state, rate, capacity, and warning properties across system power sources.
  • Apply charge-threshold support and enable/disable operations consistently across physical devices.

Validation

  • cargo fmt --all -- --check
  • git diff --check
  • env LANG=C.UTF-8 LANGUAGE=C LC_ALL=C.UTF-8 LC_MESSAGES=C.UTF-8 cargo test -p wayle-shell --lib
  • cargo build -p wayle

Copilot AI lite review requested due to automatic review settings August 10, 2026 12:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR moves the shell to a new shell-specific BatteryService that aggregates physical UPower battery/UPS devices (instead of relying on UPower’s DisplayDevice) and wires it through bootstrap + UI modules.

Changes:

  • Introduces crates/wayle-shell/src/services/battery.rs, aggregating percentage/energy/state/rates/capacity/warnings and charge-threshold capabilities across physical power sources.
  • Updates shell/bootstrap wiring to initialize the new aggregated battery service.
  • Refactors UI modules to import BatteryService from crate::services instead of wayle_battery.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/wayle-shell/src/shell/services.rs Switches shell service container to use the shell’s aggregated BatteryService.
crates/wayle-shell/src/shell/bar/modules/battery/watchers.rs Updates battery module watchers to use crate::services::BatteryService.
crates/wayle-shell/src/shell/bar/modules/battery/messages.rs Updates battery module message/init types to use crate::services::BatteryService.
crates/wayle-shell/src/shell/bar/dropdowns/dashboard/messages.rs Wires dashboard dropdown init to use the new battery service type.
crates/wayle-shell/src/shell/bar/dropdowns/dashboard/battery_section/watchers.rs Updates dashboard battery section watchers to use shell battery service while keeping DeviceState from wayle_battery.
crates/wayle-shell/src/shell/bar/dropdowns/dashboard/battery_section/messages.rs Updates dashboard battery section message/init types to use shell battery service.
crates/wayle-shell/src/shell/bar/dropdowns/battery/messages.rs Updates battery dropdown init types to use shell battery service.
crates/wayle-shell/src/shell/bar/dropdowns/battery/battery_section/watchers.rs Updates battery dropdown section watchers to use shell battery service.
crates/wayle-shell/src/shell/bar/dropdowns/battery/battery_section/mod.rs Updates section module imports to use shell battery service and keep DeviceState/WarningLevel from wayle_battery.
crates/wayle-shell/src/shell/bar/dropdowns/battery/battery_section/messages.rs Updates battery dropdown section init types to use shell battery service.
crates/wayle-shell/src/services/mod.rs Adds services::battery module and re-exports BatteryService (crate-visible).
crates/wayle-shell/src/services/battery.rs New aggregated battery service built from physical UPower devices, with aggregation logic + unit tests.
crates/wayle-shell/src/bootstrap/mod.rs Boots battery service via new bootstrap::battery module (and keeps it optional via try_service!).
crates/wayle-shell/src/bootstrap/battery.rs New helper to build the aggregated battery service.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +172 to +190
let mut controlled_devices = 0;

for device in &self.threshold_devices {
if !device.is_present.get() {
continue;
}

if !device.charge_threshold_supported.get() {
return Err(String::from(
"not all physical batteries support charge thresholds",
));
}

device
.enable_charge_threshold(enabled)
.await
.map_err(|error| error.to_string())?;
controlled_devices += 1;
}
Comment on lines +365 to +367
fn update_aggregate(aggregate: &BatteryDevice, sources: &[Arc<PhysicalDevice>]) {
let reading = aggregate_readings(&readings_from_devices(sources));
aggregate.percentage.set(reading.percentage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants