From 91d45029ac2294e1ad82e71b7c18f20bcdf42b2e Mon Sep 17 00:00:00 2001 From: thijs snijder <snijder@astron.nl> Date: Tue, 18 May 2021 17:49:24 +0200 Subject: [PATCH] processed review points. Fixed off bug when no client has been initialised --- devices/APSCTL.py | 10 ++++++---- devices/PCC.py | 9 ++++++--- devices/SDP.py | 9 ++++++--- devices/SNMP.py | 4 ++-- devices/ini_device.py | 5 +++-- devices/util/attribute_wrapper.py | 2 +- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/devices/APSCTL.py b/devices/APSCTL.py index 0cb322251..fe66a52a1 100644 --- a/devices/APSCTL.py +++ b/devices/APSCTL.py @@ -149,9 +149,11 @@ class APSCTL(hardware_device): @log_exceptions() def configure_for_off(self): """ user code here. is called when the state is set to OFF """ - # Stop keep-alive - self.opcua_connection.stop() + try: + self.opcua_connection.stop() + except Exception as e: + self.error_stream("Caught this exception when going to OFF state:".format(e)) @log_exceptions() def configure_for_initialise(self): @@ -165,10 +167,10 @@ class APSCTL(hardware_device): for i in self.attr_list(): try: i.set_comm_client(self.OPCua_client) - except: + except Exception as e: # use the pass function instead of setting read/write fails i.set_pass_func() - self.error_stream("error in getting APSCTL attribute: {} from client".format(i)) + self.warn_stream("error while setting the APSCTL attribute {} read/write function. {}".format(i, e)) self.OPCua_client.start() diff --git a/devices/PCC.py b/devices/PCC.py index da615d180..a8c104a3e 100644 --- a/devices/PCC.py +++ b/devices/PCC.py @@ -120,7 +120,10 @@ class PCC(hardware_device): def configure_for_off(self): """ user code here. is called when the state is set to OFF """ # Stop keep-alive - self.OPCua_client.stop() + try: + self.opcua_connection.stop() + except Exception as e: + self.error_stream("Caught this exception when going to OFF state:".format(e)) @log_exceptions() def configure_for_initialise(self): @@ -144,10 +147,10 @@ class PCC(hardware_device): for i in self.attr_list(): try: i.set_comm_client(self.OPCua_client) - except: + except Exception as e: # use the pass function instead of setting read/write fails i.set_pass_func() - self.error_stream("error in getting PCC attribute: {} from client".format(i)) + self.warn_stream("error while setting the PCC attribute {} read/write function. {}".format(i, e)) self.OPCua_client.start() diff --git a/devices/SDP.py b/devices/SDP.py index ebe680999..f8b16bd46 100644 --- a/devices/SDP.py +++ b/devices/SDP.py @@ -124,7 +124,10 @@ class SDP(hardware_device): """ user code here. is called when the state is set to OFF """ # Stop keep-alive - self.opcua_connection.stop() + try: + self.opcua_connection.stop() + except Exception as e: + self.error_stream("Caught this exception when going to OFF state:".format(e)) @log_exceptions() def configure_for_initialise(self): @@ -138,10 +141,10 @@ class SDP(hardware_device): for i in self.attr_list(): try: i.set_comm_client(self.OPCua_client) - except: + except Exception as e: # use the pass function instead of setting read/write fails i.set_pass_func() - self.debug_stream("error in getting SDP attribute: {} from client".format(i)) + self.warn_stream("error while setting the SDP attribute {} read/write function. {}".format(i, e)) pass self.OPCua_client.start() diff --git a/devices/SNMP.py b/devices/SNMP.py index 078ca6ddf..db748639e 100644 --- a/devices/SNMP.py +++ b/devices/SNMP.py @@ -92,10 +92,10 @@ class SNMP(hardware_device): for i in self.attr_list(): try: i.set_comm_client(self.snmp_manager) - except: + except Exception as e: # use the pass function instead of setting read/write fails i.set_pass_func() - self.error_stream("error in getting SNMP attribute: {} from client".format(i)) + self.warn_stream("error while setting the SNMP attribute {} read/write function. {}".format(i, e)) self.snmp_manager.start() diff --git a/devices/ini_device.py b/devices/ini_device.py index 9b3e83a1e..dbc6e6159 100644 --- a/devices/ini_device.py +++ b/devices/ini_device.py @@ -110,10 +110,11 @@ class ini_device(hardware_device): for i in self.attr_list(): try: i.set_comm_client(self.ini_client) - except: + except Exception as e: # use the pass function instead of setting read/write fails i.set_pass_func() - self.error_stream("error in getting ini attribute: {} from client".format(i)) + + self.warn_stream("error while setting the ini attribute {} read/write function. {}".format(i, e)) self.ini_client.start() diff --git a/devices/util/attribute_wrapper.py b/devices/util/attribute_wrapper.py index 8340af614..d4584f01b 100644 --- a/devices/util/attribute_wrapper.py +++ b/devices/util/attribute_wrapper.py @@ -136,7 +136,7 @@ class attribute_wrapper(attribute): self.read_function, self.write_function = client.setup_attribute(self.comms_annotation, self) except Exception as e: - logger.error("Exception while setting {} attribute with annotation: '{}'".format(client.__class__.__name__, self.comms_annotation)) + logger.error("Exception while setting {} attribute with annotation: '{}' {}".format(client.__class__.__name__, self.comms_annotation, e)) raise Exception("Exception while setting %s attribute with annotation: '%s'", client.__class__.__name__, self.comms_annotation) from e def set_pass_func(self): -- GitLab