From 406988fbdf968f19ac40ce781f40d57052cef11b Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 29 Mar 2024 18:04:06 -0700 Subject: [PATCH] manager: Implement fan_control_state --- src/manager.rs | 15 +++++++++++---- src/systemd.rs | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/manager.rs b/src/manager.rs index 4202588..a51240a 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -128,10 +128,17 @@ impl SteamOSManager { } #[zbus(property)] - fn fan_control_state(&self) -> zbus::fdo::Result { - Err(zbus::fdo::Error::UnknownProperty(String::from( - "This property can't currently be read", - ))) + async fn fan_control_state(&self) -> zbus::fdo::Result { + let jupiter_fan_control = + SystemdUnit::new(self.connection.clone(), "jupiter_2dfan_2dcontrol_2eservice") + .await + .map_err(anyhow_to_zbus_fdo)?; + let active = jupiter_fan_control.active().await + .map_err(anyhow_to_zbus_fdo)?; + Ok(match active { + true => FanControl::OS as u32, + false => FanControl::BIOS as u32, + }) } #[zbus(property)] diff --git a/src/systemd.rs b/src/systemd.rs index e8d4395..6c111f5 100644 --- a/src/systemd.rs +++ b/src/systemd.rs @@ -69,4 +69,8 @@ impl<'dbus> SystemdUnit<'dbus> { self.proxy.stop("fail").await?; Ok(()) } + + pub async fn active(&self) -> Result { + Ok(self.proxy.active_state().await? == "active") + } }