From 95deb35e8259340e9819906c1a11d410825c744d Mon Sep 17 00:00:00 2001
From: lukken <lukken@astron.nl>
Date: Thu, 11 Aug 2022 07:49:58 +0000
Subject: [PATCH] L2SS-868: Prevent undefined variable from disabling tango in
 sst_writer

---
 .../default/statistics/test_writer_sst.py              | 10 +++++-----
 .../tangostationcontrol/statistics/writer.py           |  8 +++++---
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py b/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py
index b6c9f41f7..883821753 100644
--- a/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py
+++ b/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py
@@ -71,11 +71,11 @@ class TestStatisticsWriterSST(BaseIntegrationTestCase):
                 stat = stat_parser.get_statistic('2021-09-20T12:17:40.000+00:00') # same as stat_parser.statistics[0] 
                 self.assertIsNotNone(stat)
                 self.assertEqual(121, stat.data_id_signal_input_index)
-                # RECV attributes are not present since the stats-writer is not connecting to any host              
-                self.assertEqual(stat.rcu_attenuator_dB.tolist(), None)
-                self.assertEqual(stat.rcu_band_select.tolist(), None)
-                self.assertEqual(stat.rcu_dth_on.tolist(), None) 
-        
+                # Test RECV attributes
+                self.assertListEqual(stat.rcu_attenuator_dB.tolist(), [0] * 96)
+                self.assertListEqual(stat.rcu_band_select.tolist(), [0] * 96)
+                self.assertListEqual(stat.rcu_dth_on.tolist(), [False] * 96)
+
     def test_no_tango_SST_statistics(self):
 
         with TemporaryDirectory() as tmpdir:
diff --git a/tangostationcontrol/tangostationcontrol/statistics/writer.py b/tangostationcontrol/tangostationcontrol/statistics/writer.py
index 2ebd32476..d82415196 100644
--- a/tangostationcontrol/tangostationcontrol/statistics/writer.py
+++ b/tangostationcontrol/tangostationcontrol/statistics/writer.py
@@ -153,11 +153,13 @@ def main():
         logger.debug("Setting loglevel to DEBUG")
     
     # sets the Tango connection in order to retrieve attribute values 
-    if tango_disabled or not host:
+    if tango_disabled:
         logger.warning("Tango connection is DISABLED")
-        device = None 
+        device = None
+    elif host:
+        device = DeviceProxy(f"tango://{host}:10000/{args.device}".lower()) if mode == 'SST' else None
     else:     
-        device = DeviceProxy(f"tango://{host}:10000/{args.device}".lower()) if mode=='SST' else None
+        device = DeviceProxy(args.device) if mode == 'SST' else None
 
     # creates the TCP receiver that is given to the writer
     receiver = _create_receiver(filename, host, port)
-- 
GitLab