From bfe915db006adbd1fb96a4b7eb34b95958ecb6ee Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Fri, 22 Sep 2023 17:09:58 +0200
Subject: [PATCH] Don't error if transitioning to a state we're already in.
 Explicitly reboot software devices to make sure their state is as expected

---
 .../devices/base_device_classes/power_hierarchy.py   |  3 ---
 .../tangostationcontrol/devices/station_manager.py   | 12 ++++++++++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/tangostationcontrol/tangostationcontrol/devices/base_device_classes/power_hierarchy.py b/tangostationcontrol/tangostationcontrol/devices/base_device_classes/power_hierarchy.py
index bc1810c30..2fb996242 100644
--- a/tangostationcontrol/tangostationcontrol/devices/base_device_classes/power_hierarchy.py
+++ b/tangostationcontrol/tangostationcontrol/devices/base_device_classes/power_hierarchy.py
@@ -41,9 +41,6 @@ class PowerHierarchyDevice(AbstractHierarchyDevice):
 
     def _boot_device(self, device: DeviceProxy):
         """Default sequence of device booting operations"""
-        if device.state() == DevState.ON:
-            logger.info(f"Booting {device}: Succesful: It's already ON?")
-            return
 
         logger.info(f"Booting {device}: off()")
         device.off()
diff --git a/tangostationcontrol/tangostationcontrol/devices/station_manager.py b/tangostationcontrol/tangostationcontrol/devices/station_manager.py
index 987d7ea24..dc5d6c3f2 100644
--- a/tangostationcontrol/tangostationcontrol/devices/station_manager.py
+++ b/tangostationcontrol/tangostationcontrol/devices/station_manager.py
@@ -195,6 +195,9 @@ class StationManager(LOFARDevice):
         Switch the station into OFF state.
         It can only be executed from state HIBERNATE.
         """
+        if self.station_state == StationState.OFF:
+            return
+
         if not self._is_transition_allowed(StationState.OFF):
             raise Exception(f"Station did not transition to {StationState.OFF.name}")
 
@@ -214,6 +217,9 @@ class StationManager(LOFARDevice):
         Switch the station into HIBERNATE state.
         It can only be executed from either state OFF or STANDBY.
         """
+        if self.station_state == StationState.HIBERNATE:
+            return
+
         if not self._is_transition_allowed(StationState.HIBERNATE):
             raise Exception(
                 f"Station did not transition to {StationState.HIBERNATE.name}"
@@ -247,6 +253,9 @@ class StationManager(LOFARDevice):
         Switch the station into STANDBY state.
         It can only be executed from either state HIBERNATE or ON.
         """
+        if self.station_state == StationState.STANDBY:
+            return
+
         if not self._is_transition_allowed(StationState.STANDBY):
             raise Exception(
                 f"Station did not transition to {StationState.STANDBY.name}"
@@ -278,6 +287,9 @@ class StationManager(LOFARDevice):
         Switch the station into ON state.
         It can only be executed from state STANDBY.
         """
+        if self.station_state == StationState.ON:
+            return
+
         if not self._is_transition_allowed(StationState.ON):
             raise Exception(f"Station did not transition to {StationState.ON.name}")
 
-- 
GitLab