diff --git a/asusd/src/ctrl_platform.rs b/asusd/src/ctrl_platform.rs index 192bd6b2..2e622155 100644 --- a/asusd/src/ctrl_platform.rs +++ b/asusd/src/ctrl_platform.rs @@ -295,16 +295,39 @@ impl CtrlPlatform { #[zbus(property)] fn charge_control_end_threshold(&self) -> Result { - let limit = self.power.get_charge_control_end_threshold()?; + if !self.power.has_charge_control_end_threshold() { + return Err(FdoErr::NotSupported( + "RogPlatform: charge_control_end_threshold not supported".to_owned(), + )); + } + + let limit = self.power.get_charge_control_end_threshold().map_err(|e| { + FdoErr::Failed(format!( + "Could not read charge_control_end_threshold: {e:?}" + )) + })?; + Ok(limit) } #[zbus(property)] async fn set_charge_control_end_threshold(&mut self, limit: u8) -> Result<(), FdoErr> { + if !self.power.has_charge_control_end_threshold() { + return Err(FdoErr::NotSupported( + "RogPlatform: charge_control_end_threshold not supported".to_owned(), + )); + } + if !(20..=100).contains(&limit) { return Err(RogError::ChargeLimit(limit))?; } - self.power.set_charge_control_end_threshold(limit)?; + + self.power + .set_charge_control_end_threshold(limit) + .map_err(|e| { + FdoErr::Failed(format!("Could not set charge_control_end_threshold: {e:?}")) + })?; + self.config.lock().await.charge_control_end_threshold = limit; self.config.lock().await.base_charge_control_end_threshold = limit; self.config.lock().await.write(); @@ -312,12 +335,22 @@ impl CtrlPlatform { } async fn one_shot_full_charge(&self) -> Result<(), FdoErr> { + if !self.power.has_charge_control_end_threshold() { + return Err(FdoErr::NotSupported( + "RogPlatform: charge_control_end_threshold not supported".to_owned(), + )); + } + let base_limit = std::mem::replace( &mut self.config.lock().await.charge_control_end_threshold, 100, ); if base_limit != 100 { - self.power.set_charge_control_end_threshold(100)?; + self.power + .set_charge_control_end_threshold(100) + .map_err(|e| { + FdoErr::Failed(format!("Could not set one_shot_full_charge: {e:?}")) + })?; self.config.lock().await.base_charge_control_end_threshold = base_limit; self.config.lock().await.write(); } diff --git a/rog-platform/src/power.rs b/rog-platform/src/power.rs index adf75e2c..5d2d1c79 100644 --- a/rog-platform/src/power.rs +++ b/rog-platform/src/power.rs @@ -101,8 +101,15 @@ impl AsusPower { }); } - Err(PlatformError::MissingFunction( - "Did not find a battery".to_owned(), - )) + // No battery found. Return an AsusPower with an empty battery path so + // callers can still be constructed and query `has_*` methods which + // will correctly report absence. This avoids hard-failing on systems + // where the asus-nb-wmi driver loads on desktops with no battery. + info!("Did not find a battery, continuing without battery support"); + Ok(Self { + mains, + battery: PathBuf::new(), + usb, + }) } }