From e038646a149c52d24012b66a11e3606b4430e899 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Tue, 1 Dec 2020 14:45:19 +0100
Subject: [PATCH] Abstracted pcc_node.get_child to avoid repetition

---
 RCUSCC/RCUSCC/RCUSCC.py | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/RCUSCC/RCUSCC/RCUSCC.py b/RCUSCC/RCUSCC/RCUSCC.py
index 50bd74d45..109d8b7ea 100644
--- a/RCUSCC/RCUSCC/RCUSCC.py
+++ b/RCUSCC/RCUSCC/RCUSCC.py
@@ -159,6 +159,9 @@ class RCUSCC(Device):
     # General methods
     # ---------------
 
+    def get_pcc_node(self, node):
+        return self.pcc_node.get_child(["{}:{}".format(self.name_space_index, node)])
+
 
     def init_device(self):
         """Initialises the attributes and properties of the RCUSCC."""
@@ -228,40 +231,40 @@ class RCUSCC(Device):
             # 2020-11-27, thomas
             # TODO
             # Modify as soon as we have a real multi-dimensional array
-            self.attribute_mapping["Attenuator_R"] = (self.pcc_node.get_child(["{}:RCUs_Attenuator1_R".format(self.name_space_index)]), self.pcc_node.get_child(["{}:RCUs_Attenuator2_R".format(self.name_space_index)]), self.pcc_node.get_child(["{}:RCUs_Attenuator3_R".format(self.name_space_index)]))
+            self.attribute_mapping["Attenuator_R"] = (self.get_pcc_node("RCUs_Attenuator1_R"), self.get_pcc_node("RCUs_Attenuator2_R"), self.get_pcc_node("RCUs_Attenuator3_R"))
 
             # 2020-11-27, thomas
             # TODO
             # Modify as soon as we have a real multi-dimensional array
-            self.attribute_mapping["Attenuator_RW"] = (self.pcc_node.get_child(["{}:RCUs_Attenuator1_RW".format(self.name_space_index)]), self.pcc_node.get_child(["{}:RCUs_Attenuator2_RW".format(self.name_space_index)]), self.pcc_node.get_child(["{}:RCUs_Attenuator3_RW".format(self.name_space_index)]))
+            self.attribute_mapping["Attenuator_RW"] = (self.get_pcc_node("RCUs_Attenuator1_RW"), self.get_pcc_node("RCUs_Attenuator2_RW"), self.get_pcc_node("RCUs_Attenuator3_RW"))
 
             # 2020-11-27, thomas
             # TODO
             # Modify as soon as we have a real multi-dimensional array
-            self.attribute_mapping["Band_R"] = (self.pcc_node.get_child(["{}:RCUs_Band1_R".format(self.name_space_index)]), self.pcc_node.get_child(["{}:RCUs_Band2_R".format(self.name_space_index)]), self.pcc_node.get_child(["{}:RCUs_Band3_R".format(self.name_space_index)]))
+            self.attribute_mapping["Band_R"] = (self.get_pcc_node("RCUs_Band1_R"), self.get_pcc_node("RCUs_Band2_R"), self.get_pcc_node("RCUs_Band3_R"))
 
             # 2020-11-27, thomas
             # TODO
             # Modify as soon as we have a real multi-dimensional array
-            self.attribute_mapping["Band_RW"] = (self.pcc_node.get_child(["{}:RCUs_Band1_RW".format(self.name_space_index)]), self.pcc_node.get_child(["{}:RCUs_Band2_RW".format(self.name_space_index)]), self.pcc_node.get_child(["{}:RCUs_Band3_RW".format(self.name_space_index)]))
+            self.attribute_mapping["Band_RW"] = (self.get_pcc_node("RCUs_Band1_RW"), self.get_pcc_node("RCUs_Band2_RW"), self.get_pcc_node("RCUs_Band3_RW"))
 
-            self.attribute_mapping["CLK_PLL_locked_R"] = self.pcc_node.get_child(["{}:CLK_PLL_locked_R".format(self.name_space_index)])
+            self.attribute_mapping["CLK_PLL_locked_R"] = self.get_pcc_node("CLK_PLL_locked_R")
 
-#            self.attribute_mapping["Dither_Frequency_R"] = self.pcc_node.get_child(["{}:RCUs_Dither_Frequency_R".format(self.name_space_index)])
+#            self.attribute_mapping["Dither_Frequency_R"] = self.get_pcc_node("RCUs_Dither_Frequency_R")
 
-#            self.attribute_mapping["Dither_Frequency_RW"] = self.pcc_node.get_child(["{}:RCUs_Dither_Frequency_RW".format(self.name_space_index)])
+#            self.attribute_mapping["Dither_Frequency_RW"] = self.get_pcc_node("RCUs_Dither_Frequency_RW")
 
-            self.attribute_mapping["LED_R"] = self.pcc_node.get_child(["{}:RCUs_LED0_R".format(self.name_space_index)])
+            self.attribute_mapping["LED_R"] = self.get_pcc_node("RCUs_LED0_R")
 
-            self.attribute_mapping["LED_RW"] = self.pcc_node.get_child(["{}:RCUs_LED0_RW".format(self.name_space_index)])
+            self.attribute_mapping["LED_RW"] = self.get_pcc_node("RCUs_LED0_RW")
 
-            self.attribute_mapping["Pwr_dig_R"] = self.pcc_node.get_child(["{}:RCUs_Pwr_dig_R".format(self.name_space_index)])
+            self.attribute_mapping["Pwr_dig_R"] = self.get_pcc_node("RCUs_Pwr_dig_R")
 
-            self.attribute_mapping["Temperature_R"] = self.pcc_node.get_child(["{}:RCUs_Temperature_R".format(self.name_space_index)])
+            self.attribute_mapping["Temperature_R"] = self.get_pcc_node("RCUs_Temperature_R")
 
-#            self.attribute_mapping["RCU_off"] = self.pcc_node.get_child(["{}:RCUs_RCU_off".format(self.name_space_index)])
+#            self.attribute_mapping["RCU_off"] = self.get_pcc_node("RCUs_RCU_off")
 
-#            self.attribute_mapping["RCU_on"] = self.pcc_node.get_child(["{}:RCUs_RCU_on".format(self.name_space_index)])
+#            self.attribute_mapping["RCU_on"] = self.get_pcc_node("RCUs_RCU_on")
 
 
             self.debug_stream("Mapping OPC-UA MP/CP to attributes done.")
-- 
GitLab