feat(src/daemon): add battery limit validation to set_battery_limit

The change ensures that only valid battery percentages (1‑100) are processed, preventing out‑of‑range values from reaching the underlying command.

- New Features
  - Validation of battery limit percentage added.
- Enhancements  - Better error reporting for invalid arguments.
- Bug Fixes
  - Prevents processing of invalid battery limit values.
This commit is contained in:
sankalp committed 2026-05-25 13:36:40 +05:45
1 parent f5f73a4990
commit 75c3a39597
1 file changed
+6
+6
View File
@@ -54,6 +54,12 @@ impl LapctlInterface {
}
pub async fn set_battery_limit(&self, percent: u32) -> zbus::fdo::Result<()> {
if percent == 0 || percent > 100 {
return Err(zbus::fdo::Error::InvalidArgs(format!(
"Invalid battery limit: {}. Must be between 1 and 100.",
percent
)));
}
crate::commands::battery::execute_local(&crate::cli::BatteryCommands::Limit {
percent: percent as u8,
});