From bb4924801e0cbfde9a484e2e9fed9fdf85cd3e0d Mon Sep 17 00:00:00 2001
From: Stefano Di Frischia <stefano.difrischia@inaf.it>
Date: Tue, 19 Sep 2023 11:24:16 +0000
Subject: [PATCH] L2SS-1512: fix dth and dab in state transitions

---
 .../test_power_hierarchy.py                   | 26 +++++++++++++++----
 .../devices/antennafield.py                   |  6 +++++
 .../base_device_classes/recv_device.py        |  4 +++
 3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/tangostationcontrol/integration_test/default/devices/base_device_classes/test_power_hierarchy.py b/tangostationcontrol/integration_test/default/devices/base_device_classes/test_power_hierarchy.py
index d311d8da8..b8330acf0 100644
--- a/tangostationcontrol/integration_test/default/devices/base_device_classes/test_power_hierarchy.py
+++ b/tangostationcontrol/integration_test/default/devices/base_device_classes/test_power_hierarchy.py
@@ -9,6 +9,7 @@ from integration_test import base
 from integration_test.device_proxy import TestDeviceProxy
 from tango import DevState, DeviceProxy
 
+from tangostationcontrol.common.constants import N_rcu, N_rcu_inp
 from tangostationcontrol.common.case_insensitive_string import CaseInsensitiveString
 from tangostationcontrol.devices.base_device_classes.hierarchy_device import (
     NotFoundException,
@@ -160,7 +161,8 @@ class TestPowerHierarchyDevice(base.IntegrationTestCase):
         self.assertEqual(self.ccd_proxy.state(), DevState.ON)
 
         logger.info(
-            f"Exceptions suppressed in test_off_to_hibernate: {self.stationmanager_proxy.last_requested_transition_exceptions_R}"
+            "Exceptions suppressed in test_off_to_hibernate: %s",
+            self.stationmanager_proxy.last_requested_transition_exceptions_R,
         )
 
         self.assertListEqual([], self._unacceptable_exceptions())
@@ -204,7 +206,8 @@ class TestPowerHierarchyDevice(base.IntegrationTestCase):
         )
 
         logger.info(
-            f"Exceptions suppressed: {self.stationmanager_proxy.last_requested_transition_exceptions_R}"
+            "Exceptions suppressed: %s",
+            self.stationmanager_proxy.last_requested_transition_exceptions_R,
         )
 
         self.assertListEqual([], self._unacceptable_exceptions())
@@ -227,8 +230,19 @@ class TestPowerHierarchyDevice(base.IntegrationTestCase):
         self.assertEqual(self.sdp_proxy.state(), DevState.ON)
         self.assertEqual(self.antennafield_proxy.state(), DevState.ON)
 
+        # Test if DTH and DAB are disabled
+        self.assertListEqual(
+            self.recvh_proxy.RCU_DTH_on_R.tolist(),
+            [[False] * N_rcu_inp] * N_rcu,
+        )
+        self.assertListEqual(
+            self.antennafield_proxy.RCU_DAB_filter_on_RW.tolist(),
+            [False] * self.antennafield_proxy.nr_antennas_R,
+        )
+
         logger.info(
-            f"Exceptions suppressed: {self.stationmanager_proxy.last_requested_transition_exceptions_R}"
+            "Exceptions suppressed: %s",
+            self.stationmanager_proxy.last_requested_transition_exceptions_R,
         )
 
         self.assertListEqual([], self._unacceptable_exceptions())
@@ -252,7 +266,8 @@ class TestPowerHierarchyDevice(base.IntegrationTestCase):
         self.assertEqual(self.antennafield_proxy.state(), DevState.OFF)
 
         logger.info(
-            f"Exceptions suppressed: {self.stationmanager_proxy.last_requested_transition_exceptions_R}"
+            "Exceptions suppressed: %s",
+            self.stationmanager_proxy.last_requested_transition_exceptions_R,
         )
 
         self.assertListEqual([], self._unacceptable_exceptions())
@@ -281,7 +296,8 @@ class TestPowerHierarchyDevice(base.IntegrationTestCase):
         self.assertEqual(self.sdpfirmware_proxy.state(), DevState.OFF)
 
         logger.info(
-            f"Exceptions suppressed: {self.stationmanager_proxy.last_requested_transition_exceptions_R}"
+            "Exceptions suppressed: %s",
+            self.stationmanager_proxy.last_requested_transition_exceptions_R,
         )
 
         self.assertListEqual([], self._unacceptable_exceptions())
diff --git a/tangostationcontrol/tangostationcontrol/devices/antennafield.py b/tangostationcontrol/tangostationcontrol/devices/antennafield.py
index 4c1cb0780..91be09afc 100644
--- a/tangostationcontrol/tangostationcontrol/devices/antennafield.py
+++ b/tangostationcontrol/tangostationcontrol/devices/antennafield.py
@@ -1075,6 +1075,12 @@ class AntennaField(LOFARDevice):
         # Configure the devices that process our antennas
         self.configure_recv()
         self.configure_sdp()
+        # Disable DAB filters for HBAs
+        if self.Antenna_Type == "HBA":
+            self.proxy.write_attribute(
+                "RCU_DAB_filter_on_RW",
+                [False] * self.read_nr_antennas_R(),
+            )
 
     def _power_hardware_off(self):
         # Save actual mask values
diff --git a/tangostationcontrol/tangostationcontrol/devices/base_device_classes/recv_device.py b/tangostationcontrol/tangostationcontrol/devices/base_device_classes/recv_device.py
index 1b8a8c5cb..b8e6ad462 100644
--- a/tangostationcontrol/tangostationcontrol/devices/base_device_classes/recv_device.py
+++ b/tangostationcontrol/tangostationcontrol/devices/base_device_classes/recv_device.py
@@ -388,6 +388,10 @@ class RECVDevice(OPCUADevice):
 
         self.RCU_on()
         self.wait_attribute("RECVTR_translator_busy_R", False, self.RCU_On_Off_timeout)
+        self.RCU_DTH_off()
+        self.wait_attribute(
+            "RECVTR_translator_busy_R", False, self.RCU_DTH_On_Off_timeout
+        )
 
     def _power_hardware_off(self):
         """Turns off the RCUs."""
-- 
GitLab