Expand description
Battery monitoring via UPower D-Bus interface.
§Quick Start
use wayle_battery::BatteryService;
let service = BatteryService::new().await?;
// Access battery state
let percentage = service.device.percentage.get();
let state = service.device.state.get();
println!("Battery: {percentage}% ({state})");§Reactive Properties
All device properties are wrapped in Property<T>:
- Snapshot:
.get()returns the current value - Stream:
.watch()yields on every change
// React to state changes
let mut state_stream = service.device.state.watch();
while let Some(new_state) = state_stream.next().await {
println!("State changed: {new_state}");
}§DisplayDevice vs Specific Devices
By default, BatteryService::new monitors UPower’s DisplayDevice - a composite
that aggregates all batteries. For specific device monitoring:
use zbus::zvariant::OwnedObjectPath;
let path = OwnedObjectPath::try_from("/org/freedesktop/UPower/devices/battery_BAT0")?;
let service = BatteryService::builder()
.device_path(path)
.build()
.await?;§Control Methods
The Device type exposes UPower operations:
refresh- Force data refresh from hardwareget_history- Historical charge/rate dataget_statistics- Charge/discharge statisticsenable_charge_threshold- Battery charge limiting
Modules§
- core
- Core battery device functionality.
- types
- Type definitions for battery service domain models and enums.
Structs§
- Battery
Service - Battery service for monitoring power devices via UPower.
- Battery
Service Builder - Builder for configuring a BatteryService.
Enums§
- Error
- Battery service errors.