From be1299e7d698ebc3c891fd8e28554d679a3fa455 Mon Sep 17 00:00:00 2001 From: lkoester Date: Tue, 7 Feb 2023 14:56:50 +0100 Subject: [PATCH 1/2] added result return to get_switch_state --- satrs-core/src/power.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/satrs-core/src/power.rs b/satrs-core/src/power.rs index 08f737a..fa8ee01 100644 --- a/satrs-core/src/power.rs +++ b/satrs-core/src/power.rs @@ -47,10 +47,13 @@ pub trait PowerSwitcher { } /// Retrieve the switch state - fn get_switch_state(&mut self, switch_id: SwitchId) -> SwitchState; + fn get_switch_state(&mut self, switch_id: SwitchId) -> Result; - fn get_is_switch_on(&mut self, switch_id: SwitchId) -> bool { - self.get_switch_state(switch_id) == SwitchState::On + fn get_is_switch_on(&mut self, switch_id: SwitchId) -> Result { + match self.get_switch_state(switch_id) { + Ok(switch_state) => { Ok(switch_state == SwitchState::On) } + Err(_) => { Err(()) } + } } /// The maximum delay it will take to change a switch. From ae8718ed6ade1b9cb72b9debd77b11b96e5f970f Mon Sep 17 00:00:00 2001 From: lkoester Date: Tue, 7 Feb 2023 16:01:25 +0100 Subject: [PATCH 2/2] simplified get is switch on --- satrs-core/src/power.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/satrs-core/src/power.rs b/satrs-core/src/power.rs index fa8ee01..513b479 100644 --- a/satrs-core/src/power.rs +++ b/satrs-core/src/power.rs @@ -49,11 +49,8 @@ pub trait PowerSwitcher { /// Retrieve the switch state fn get_switch_state(&mut self, switch_id: SwitchId) -> Result; - fn get_is_switch_on(&mut self, switch_id: SwitchId) -> Result { - match self.get_switch_state(switch_id) { - Ok(switch_state) => { Ok(switch_state == SwitchState::On) } - Err(_) => { Err(()) } - } + fn get_is_switch_on(&mut self, switch_id: SwitchId) -> Result { + Ok(self.get_switch_state(switch_id)? == SwitchState::On) } /// The maximum delay it will take to change a switch.