From c7a007efbda2a614150c811dc937fc1dadb7c639 Mon Sep 17 00:00:00 2001 From: Maciej Pijanowski Date: Sun, 1 Dec 2024 16:34:54 +0100 Subject: [PATCH] osfv_cli/rte: normalize on/off PSU states strings Sonoff returns capital ON/OFF, while relay returned on/off. We define relay strings here, so can be changed here to unify the reponses, no matter which power control method was used at the time. The more proper solution would be to implement: https://github.com/Dasharo/osfv-scripts/issues/77 Signed-off-by: Maciej Pijanowski --- osfv_cli/src/osfv/cli/cli.py | 2 +- osfv_cli/src/osfv/libs/rte.py | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/osfv_cli/src/osfv/cli/cli.py b/osfv_cli/src/osfv/cli/cli.py index 0168b96..d882835 100755 --- a/osfv_cli/src/osfv/cli/cli.py +++ b/osfv_cli/src/osfv/cli/cli.py @@ -250,7 +250,7 @@ def relay_get(rte, args): def power_on(rte, args): state = rte.psu_get() - if state != "on" or state != "ON": + if state != rte.PSU_STATE_ON: print(f"Power supply state: {state} !") print( 'If you wanted to power on the DUT, you need to enable power supply first ("pwr psu on"), pushing the power button is not enough!' diff --git a/osfv_cli/src/osfv/libs/rte.py b/osfv_cli/src/osfv/libs/rte.py index 410df1f..e54fbbb 100644 --- a/osfv_cli/src/osfv/libs/rte.py +++ b/osfv_cli/src/osfv/libs/rte.py @@ -20,6 +20,9 @@ class RTE(rtectrl): GPIO_CMOS = 12 + PSU_STATE_ON = "ON" + PSU_STATE_OFF = "OFF" + SSH_USER = "root" SSH_PWD = "meta-rte" FW_PATH_WRITE = "/data/write.rom" @@ -147,9 +150,9 @@ def relay_get(self): gpio_state = self.gpio_get(self.GPIO_RELAY) relay_state = None if gpio_state == "high": - relay_state = "on" + relay_state = self.PSU_STATE_ON if gpio_state == "low": - relay_state = "off" + relay_state = self.PSU_STATE_OFF return relay_state def relay_set(self, relay_state): @@ -161,9 +164,9 @@ def relay_set(self, relay_state): or "off" (sets GPIO pin to "low"). """ gpio_state = None - if relay_state == "on": + if relay_state == self.PSU_STATE_ON: gpio_state = "high" - if relay_state == "off": + if relay_state == self.PSU_STATE_OFF: gpio_state = "low" self.gpio_set(self.GPIO_RELAY, gpio_state) @@ -226,12 +229,12 @@ def psu_off(self): if self.dut_data["pwr_ctrl"]["sonoff"] is True: self.sonoff.turn_off() state = self.sonoff.get_state() - if state != "OFF": + if state != self.PSU_STATE_OFF: raise Exception("Failed to power control OFF") elif self.dut_data["pwr_ctrl"]["relay"] is True: - self.relay_set("off") + self.relay_set(self.PSU_STATE_OFF) state = self.relay_get() - if state != "off": + if state != self.PSU_STATE_OFF: raise Exception("Failed to power control OFF") time.sleep(2)