Skip to content
Snippets Groups Projects
Commit af3a7776 authored by Jan David Mol's avatar Jan David Mol
Browse files

Merge branch 'L2SS-437-exceptions-to-status' into 'master'

L2SS-437: Write exceptions to the status field of a Device

Closes L2SS-437

See merge request !152
parents 9a5cd4fb b67e4cc9
Branches
Tags
1 merge request!152L2SS-437: Write exceptions to the status field of a Device
...@@ -51,7 +51,7 @@ def fault_on_error(): ...@@ -51,7 +51,7 @@ def fault_on_error():
return func(self, *args, **kwargs) return func(self, *args, **kwargs)
except Exception as e: except Exception as e:
self.error_stream("Function failed. Trace: %s", traceback.format_exc()) self.error_stream("Function failed. Trace: %s", traceback.format_exc())
self.Fault() self.Fault(f"FAULT in {func.__name__}: {e.__class__.__name__}: {e}")
return None return None
return error_wrapper return error_wrapper
......
...@@ -85,6 +85,7 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas): ...@@ -85,6 +85,7 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas):
Device.init_device(self) Device.init_device(self)
self.set_state(DevState.OFF) self.set_state(DevState.OFF)
self.set_status("Device is in the OFF state.")
@log_exceptions() @log_exceptions()
def delete_device(self): def delete_device(self):
...@@ -115,6 +116,8 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas): ...@@ -115,6 +116,8 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas):
:return:None :return:None
""" """
self.set_state(DevState.INIT) self.set_state(DevState.INIT)
self.set_status("Device is in the INIT state.")
self.setup_value_dict() self.setup_value_dict()
# reload our class & device properties from the Tango database # reload our class & device properties from the Tango database
...@@ -123,6 +126,7 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas): ...@@ -123,6 +126,7 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas):
self.configure_for_initialise() self.configure_for_initialise()
self.set_state(DevState.STANDBY) self.set_state(DevState.STANDBY)
self.set_status("Device is in the STANDBY state.")
@command() @command()
@only_in_states([DevState.STANDBY, DevState.ON]) @only_in_states([DevState.STANDBY, DevState.ON])
...@@ -141,7 +145,9 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas): ...@@ -141,7 +145,9 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas):
return return
self.configure_for_on() self.configure_for_on()
self.set_state(DevState.ON) self.set_state(DevState.ON)
self.set_status("Device is in the ON state.")
@command() @command()
@DebugIt() @DebugIt()
...@@ -158,23 +164,25 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas): ...@@ -158,23 +164,25 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas):
# Turn off # Turn off
self.set_state(DevState.OFF) self.set_state(DevState.OFF)
self.set_status("Device is in the OFF state.")
self.configure_for_off() self.configure_for_off()
# Turn off again, in case of race conditions through reconnecting # Turn off again, in case of race conditions through reconnecting
self.set_state(DevState.OFF) self.set_state(DevState.OFF)
self.set_status("Device is in the OFF state.")
@command() @command()
@only_in_states([DevState.ON, DevState.INIT, DevState.STANDBY, DevState.FAULT]) @only_in_states([DevState.ON, DevState.INIT, DevState.STANDBY, DevState.FAULT])
@DebugIt() @DebugIt()
@log_exceptions() @log_exceptions()
def Fault(self): def Fault(self, new_status="Device is in the FAULT state."):
""" """
FAULT state is used to indicate our connection with the OPC-UA server is down. FAULT state is used to indicate the device broke down, and partially or fully
stopped functioning. Remaining functionality is undefined.
This device will try to reconnect once, and transition to the ON state on success.
If reconnecting fails, the user needs to call Initialise() to retry to restart this device. new_status: The status to set when going to FAULT.
:return:None :return:None
""" """
...@@ -183,8 +191,10 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas): ...@@ -183,8 +191,10 @@ class lofar_device(Device, metaclass=AbstractDeviceMetas):
logger.warning("Requested to go to FAULT state, but am already in FAULT state.") logger.warning("Requested to go to FAULT state, but am already in FAULT state.")
return return
self.configure_for_fault()
self.set_state(DevState.FAULT) self.set_state(DevState.FAULT)
self.set_status(new_status)
self.configure_for_fault()
# functions that can or must be overloaded # functions that can or must be overloaded
def configure_for_fault(self): def configure_for_fault(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment