From cb6fd4d4820d85c5571050b77574689b9528b6a6 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Fri, 17 Dec 2021 14:19:44 +0100
Subject: [PATCH] L2SS-544: Trigger on DevState.FAULT directly, instead of
 parsing state string.

---
 .../tangostationcontrol/toolkit/archiver.py      | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/tangostationcontrol/tangostationcontrol/toolkit/archiver.py b/tangostationcontrol/tangostationcontrol/toolkit/archiver.py
index 7562e8862..ae5ff08d5 100644
--- a/tangostationcontrol/tangostationcontrol/toolkit/archiver.py
+++ b/tangostationcontrol/tangostationcontrol/toolkit/archiver.py
@@ -2,7 +2,7 @@
 
 import logging
 
-from tango import DeviceProxy, AttributeProxy
+from tango import DeviceProxy, AttributeProxy, DevState
 
 import time
 import json, os
@@ -68,11 +68,10 @@ class Archiver():
         self.cm_name = cm_name
         self.cm = DeviceProxy(cm_name)
         try: 
-            cm_state = self.cm.state() # ping the device server
-            if 'FAULT' in str(cm_state):
-                raise Exception("Configuration Manager is in FAULT state")
+            if self.cm.state() == DevState.FAULT:
+                raise Exception(f"Configuration Manager {cm_name} is in FAULT state")
         except Exception as e:
-            raise Exception("Connection failed with Configuration Manager device") from e
+            raise Exception(f"Connection failed with Configuration Manager {cm_name}") from e
         self.es_list = [es_name for es_name in self.get_subscribers(from_db=False)] or []
         self.cm.write_attribute('Context',context)    # Set default Context Archiving for all the subscribers
         self.selector = Selector() if selector_filename is None else Selector(selector_filename)  # Create selector for customized strategies
@@ -186,13 +185,12 @@ class Archiver():
             es_name = last_es_name[:-2]+'0'+str(last_es_idx+1)   
         try: 
             es = DeviceProxy(es_name)
-            es_state = es.state() # ping the device server
-            if 'FAULT' in str(es_state):
-                raise Exception(f"{es_name} is in FAULT state")
+            if es.state() == DevState.FAULT:
+                raise Exception(f"Event Subscriber {es_name} is in FAULT state")
             self.cm.ArchiverAdd(device_name_url(es_name))
         except Exception as e:
             if 'already_present' in str(e):
-                logger.warning(f"Subscriber {es_name} already present in Configuration Manager")
+                logger.warning(f"Event Subscriber {es_name} already present in Configuration Manager")
             else:
                 raise Exception from e
 
-- 
GitLab