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:
1 file changed
+6
@@ -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,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user