feat(battery): support charging limits with system76-power

This commit is contained in:
Piotr 2024-09-06 17:56:11 +02:00 committed by GitHub
parent 58a61b7eee
commit cf06e14545
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 62 additions and 4 deletions

View file

@ -207,3 +207,43 @@ pub enum PowerProfileUpdate {
Update { profile: Power },
Error(String),
}
// check if battery charging thresholds is set
pub async fn get_charging_limit() -> bool {
if let Ok(conn) = Connection::system().await {
if let Ok(backend) = get_power_backend(&conn, &BackendType::S76PowerDaemon).await {
match backend {
Backend::S76PowerDaemon(proxy) => {
if let Ok((start, end)) = proxy.get_charge_thresholds().await {
return start > 0 || end > 0;
}
}
Backend::PowerProfilesDaemon(_) => {
tracing::info!("Power Profiles Daemon is not supported.");
return false;
}
};
}
}
false
}
// set battery charging thresholds via s76 power_daemon
pub async fn set_charging_limit() -> Result<()> {
if let Ok(conn) = Connection::system().await {
if let Ok(backend) = get_power_backend(&conn, &BackendType::S76PowerDaemon).await {
match backend {
Backend::S76PowerDaemon(proxy) => {
let _ = proxy.set_charge_thresholds(&(70, 80)).await;
}
Backend::PowerProfilesDaemon(_) => {
tracing::info!(
"Setting charging limit via Power Profiles Daemon is not supported."
);
}
};
}
}
Ok(())
}