diff --git a/src/hardware.rs b/src/hardware.rs index 9c45871..e046a47 100644 --- a/src/hardware.rs +++ b/src/hardware.rs @@ -26,7 +26,6 @@ pub enum HardwareVariant { #[derive(PartialEq, Debug, Copy, Clone)] #[repr(u32)] pub enum HardwareCurrentlySupported { - UnsupportedFeature = 0, Unsupported = 1, Supported = 2, } @@ -46,9 +45,6 @@ impl TryFrom for HardwareCurrentlySupported { type Error = &'static str; fn try_from(v: u32) -> Result { match v { - x if x == HardwareCurrentlySupported::UnsupportedFeature as u32 => { - Ok(HardwareCurrentlySupported::UnsupportedFeature) - } x if x == HardwareCurrentlySupported::Unsupported as u32 => { Ok(HardwareCurrentlySupported::Unsupported) } @@ -63,7 +59,6 @@ impl TryFrom for HardwareCurrentlySupported { impl fmt::Display for HardwareCurrentlySupported { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - HardwareCurrentlySupported::UnsupportedFeature => write!(f, "Unsupported feature"), HardwareCurrentlySupported::Unsupported => write!(f, "Unsupported"), HardwareCurrentlySupported::Supported => write!(f, "Supported"), } diff --git a/src/manager.rs b/src/manager.rs index ca02b22..441df10 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -11,7 +11,7 @@ use tokio::fs::File; use tracing::error; use zbus::{interface, zvariant::Fd}; -use crate::hardware::{check_support, variant, HardwareCurrentlySupported, HardwareVariant}; +use crate::hardware::{check_support, variant, HardwareVariant}; use crate::power::{ get_gpu_performance_level, set_gpu_clocks, set_gpu_performance_level, set_tdp_limit, GPUPerformanceLevel, @@ -30,7 +30,6 @@ enum PrepareFactoryReset { #[derive(PartialEq, Debug, Copy, Clone)] #[repr(u32)] enum FanControl { - UnsupportedFeature = 0, BIOS = 1, OS = 2, } @@ -39,7 +38,6 @@ impl TryFrom for FanControl { type Error = &'static str; fn try_from(v: u32) -> Result { match v { - x if x == FanControl::UnsupportedFeature as u32 => Ok(FanControl::UnsupportedFeature), x if x == FanControl::BIOS as u32 => Ok(FanControl::BIOS), x if x == FanControl::OS as u32 => Ok(FanControl::BIOS), _ => Err("No enum match for value {v}"), @@ -50,7 +48,6 @@ impl TryFrom for FanControl { impl fmt::Display for FanControl { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - FanControl::UnsupportedFeature => write!(f, "Unsupported feature"), FanControl::BIOS => write!(f, "BIOS"), FanControl::OS => write!(f, "OS"), } @@ -94,8 +91,8 @@ impl SteamOSManager { } #[zbus(property)] - fn wifi_power_management_state(&self) -> u32 { - WifiPowerManagement::UnsupportedFeature as u32 // TODO + fn wifi_power_management_state(&self) -> zbus::fdo::Result { + Err(zbus::fdo::Error::UnknownProperty(String::from("This property can't currently be read"))) } #[zbus(property)] @@ -107,12 +104,6 @@ impl SteamOSManager { let state = match state { WifiPowerManagement::Disabled => "off", WifiPowerManagement::Enabled => "on", - WifiPowerManagement::UnsupportedFeature => { - return Err(zbus::fdo::Error::InvalidArgs(String::from( - "Can't set state to unsupported", - )) - .into()) - } }; run_script( @@ -125,8 +116,8 @@ impl SteamOSManager { } #[zbus(property)] - fn fan_control_state(&self) -> u32 { - FanControl::UnsupportedFeature as u32 // TODO + fn fan_control_state(&self) -> zbus::fdo::Result { + Err(zbus::fdo::Error::UnknownProperty(String::from("This property can't currently be read"))) } #[zbus(property)] @@ -138,12 +129,6 @@ impl SteamOSManager { let state = match state { FanControl::OS => "stop", FanControl::BIOS => "start", - FanControl::UnsupportedFeature => { - return Err(zbus::fdo::Error::InvalidArgs(String::from( - "Can't set state to unsupported", - )) - .into()) - } }; // Run what steamos-polkit-helpers/jupiter-fan-control does @@ -157,10 +142,10 @@ impl SteamOSManager { } #[zbus(property)] - async fn hardware_currently_supported(&self) -> u32 { + async fn hardware_currently_supported(&self) -> zbus::fdo::Result { match check_support().await { - Ok(res) => res as u32, - Err(_) => HardwareCurrentlySupported::UnsupportedFeature as u32, + Ok(res) => Ok(res as u32), + Err(e) => Err(anyhow_to_zbus_fdo(e)), } } @@ -246,10 +231,10 @@ impl SteamOSManager { } #[zbus(property)] - async fn gpu_performance_level(&self) -> u32 { + async fn gpu_performance_level(&self) -> zbus::fdo::Result { match get_gpu_performance_level().await { - Ok(level) => level as u32, - Err(_) => GPUPerformanceLevel::UnsupportedFeature as u32, + Ok(level) => Ok(level as u32), + Err(e) => Err(anyhow_to_zbus_fdo(e)), } } @@ -288,9 +273,6 @@ impl SteamOSManager { // Return false on error let wanted_mode = match WifiDebugMode::try_from(mode) { - Ok(WifiDebugMode::UnsupportedFeature) => { - return Err(zbus::fdo::Error::InvalidArgs(String::from("Invalid mode"))) - } Ok(mode) => mode, Err(e) => return Err(zbus::fdo::Error::InvalidArgs(e.to_string())), }; diff --git a/src/power.rs b/src/power.rs index cff8a49..ef97e53 100644 --- a/src/power.rs +++ b/src/power.rs @@ -22,7 +22,6 @@ const GPU_CLOCKS_PATH: &str = "/sys/class/drm/card0/device/pp_od_clk_voltage"; #[derive(PartialEq, Debug, Copy, Clone)] #[repr(u32)] pub enum GPUPerformanceLevel { - UnsupportedFeature = 0, Auto = 1, Low = 2, High = 3, @@ -34,9 +33,6 @@ impl TryFrom for GPUPerformanceLevel { type Error = &'static str; fn try_from(v: u32) -> Result { match v { - x if x == GPUPerformanceLevel::UnsupportedFeature as u32 => { - Ok(GPUPerformanceLevel::UnsupportedFeature) - } x if x == GPUPerformanceLevel::Auto as u32 => Ok(GPUPerformanceLevel::Auto), x if x == GPUPerformanceLevel::Low as u32 => Ok(GPUPerformanceLevel::Low), x if x == GPUPerformanceLevel::High as u32 => Ok(GPUPerformanceLevel::High), @@ -63,17 +59,15 @@ impl FromStr for GPUPerformanceLevel { } } -impl TryInto for GPUPerformanceLevel { - type Error = Error; - fn try_into(self) -> Result { - Ok(String::from(match self { +impl ToString for GPUPerformanceLevel { + fn to_string(&self) -> String { + String::from(match self { GPUPerformanceLevel::Auto => "auto", GPUPerformanceLevel::Low => "low", GPUPerformanceLevel::High => "high", GPUPerformanceLevel::Manual => "manual", GPUPerformanceLevel::ProfilePeak => "peak_performance", - GPUPerformanceLevel::UnsupportedFeature => bail!("No valid string representation"), - })) + }) } } @@ -90,7 +84,7 @@ pub async fn set_gpu_performance_level(level: GPUPerformanceLevel) -> Result<()> .await .inspect_err(|message| error!("Error opening sysfs file for writing: {message}"))?; - let level: String = level.try_into()?; + let level: String = level.to_string(); myfile .write_all(level.as_bytes()) diff --git a/src/wifi.rs b/src/wifi.rs index c87df5b..7882fbd 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -29,7 +29,6 @@ const MIN_BUFFER_SIZE: u32 = 100; #[derive(PartialEq, Debug, Copy, Clone)] #[repr(u32)] pub enum WifiDebugMode { - UnsupportedFeature = 0, Off = 1, On = 2, } @@ -37,7 +36,6 @@ pub enum WifiDebugMode { #[derive(PartialEq, Debug, Copy, Clone)] #[repr(u32)] pub enum WifiPowerManagement { - UnsupportedFeature = 0, Disabled = 1, Enabled = 2, } @@ -46,9 +44,6 @@ impl TryFrom for WifiDebugMode { type Error = &'static str; fn try_from(v: u32) -> Result { match v { - x if x == WifiDebugMode::UnsupportedFeature as u32 => { - Ok(WifiDebugMode::UnsupportedFeature) - } x if x == WifiDebugMode::Off as u32 => Ok(WifiDebugMode::Off), x if x == WifiDebugMode::On as u32 => Ok(WifiDebugMode::On), _ => Err("No enum match for value {v}"), @@ -59,7 +54,6 @@ impl TryFrom for WifiDebugMode { impl fmt::Display for WifiDebugMode { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - WifiDebugMode::UnsupportedFeature => write!(f, "Unsupported feature"), WifiDebugMode::Off => write!(f, "Off"), WifiDebugMode::On => write!(f, "On"), } @@ -70,9 +64,6 @@ impl TryFrom for WifiPowerManagement { type Error = &'static str; fn try_from(v: u32) -> Result { match v { - x if x == WifiPowerManagement::UnsupportedFeature as u32 => { - Ok(WifiPowerManagement::UnsupportedFeature) - } x if x == WifiPowerManagement::Disabled as u32 => Ok(WifiPowerManagement::Disabled), x if x == WifiPowerManagement::Enabled as u32 => Ok(WifiPowerManagement::Enabled), _ => Err("No enum match for value {v}"), @@ -83,7 +74,6 @@ impl TryFrom for WifiPowerManagement { impl fmt::Display for WifiPowerManagement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - WifiPowerManagement::UnsupportedFeature => write!(f, "Unsupported feature"), WifiPowerManagement::Disabled => write!(f, "Disabled"), WifiPowerManagement::Enabled => write!(f, "Enabled"), } @@ -188,10 +178,6 @@ pub async fn set_wifi_debug_mode( }; } } - mode => { - // Invalid mode requested, more coming later, but add this catch-all for now - bail!("Invalid wifi debug mode {mode} requested"); - } } Ok(()) }