From 24ab0b736403718542b51dc914d9e57d8d804c90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Corn=C3=A9=20Lukken?= <lukken@astron.nl>
Date: Tue, 7 Nov 2023 19:23:41 +0000
Subject: [PATCH] L2SS-1574: PyTango 9.5.0 compatability

---
 README.md                                     |  1 +
 .../code/tango-prometheus-client.py           | 29 +++++++------------
 tangostationcontrol/VERSION                   |  2 +-
 3 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/README.md b/README.md
index 8762b1d5e..ff2cba2c6 100644
--- a/README.md
+++ b/README.md
@@ -139,6 +139,7 @@ Next change the version in the following places:
 
 # Release Notes
 
+* 0.24.2 Ensure code base is PyTango 9.5 compatible
 * 0.24.1 Let all devices emit basic prometheus metrics
 * 0.24.0 Allow multiple antenna fields to be used in single observation,
   This renames the `Observation` device to `ObservationField`.
diff --git a/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py b/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py
index fdb80e699..a2553cad2 100644
--- a/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py
+++ b/docker-compose/tango-prometheus-exporter/code/tango-prometheus-client.py
@@ -14,9 +14,10 @@ from tango import (
     Database,
     DeviceProxy,
     CmdArgType as ArgType,
+    utils,
     AttrDataFormat,
     DevState,
-    DevFailed,
+    DevFailed, AttributeInfo,
 )
 
 logger = logging.getLogger()
@@ -110,28 +111,18 @@ class CustomCollector(object):
         self.policy = ArchiverPolicy(config)
         self.proxy_timeout = proxy_timeout
 
-    def _to_metric(self, dev, attr_info, x, y, idx, value):
+    def _to_metric(self, dev, attr_info: AttributeInfo, x, y, idx, value):
         """Convert the given values to a (labels, value) pair, used to construct a Metric."""
 
-        if attr_info.data_type in [
-            ArgType.DevShort,
-            ArgType.DevLong,
-            ArgType.DevUShort,
-            ArgType.DevULong,
-            ArgType.DevLong64,
-            ArgType.DevULong64,
-            ArgType.DevInt,
-            ArgType.DevFloat,
-            ArgType.DevDouble,
-        ]:
+        if utils.is_numerical_type(attr_info.data_type):
             data_type = "float"
             str_value = ""
             float_value = float(value)
-        elif attr_info.data_type == ArgType.DevBoolean:
+        elif utils.is_bool_type(attr_info.data_type):
             data_type = "bool"
             str_value = ""
             float_value = int(value)
-        elif attr_info.data_type == ArgType.DevString:
+        elif utils.is_str_type(attr_info.data_type):
             data_type = "string"
             str_value = str(value)
             float_value = len(str_value)
@@ -162,13 +153,13 @@ class CustomCollector(object):
             float_value,
         )
 
-    def metrics_scalar(self, dev, attr_info, attr_value):
+    def metrics_scalar(self, dev, attr_info: AttributeInfo, attr_value):
         """Return all metrics for a given SCALAR attribute."""
 
         new_metric = self._to_metric(dev, attr_info, 0, 0, 0, attr_value.value)
         return [new_metric] if new_metric else []
 
-    def metrics_spectrum(self, dev, attr_info, attr_value):
+    def metrics_spectrum(self, dev, attr_info: AttributeInfo, attr_value):
         """Return all metrics for a given SPECTRUM attribute."""
 
         metrics = []
@@ -178,7 +169,7 @@ class CustomCollector(object):
 
         return metrics
 
-    def metrics_image(self, dev, attr_info, attr_value):
+    def metrics_image(self, dev, attr_info: AttributeInfo, attr_value):
         """Return all metrics for a given IMAGE attribute."""
 
         metrics = []
@@ -199,7 +190,7 @@ class CustomCollector(object):
 
         return metrics
 
-    def metrics(self, dev, attr_info, attr_value):
+    def metrics(self, dev, attr_info: AttributeInfo, attr_value):
         """Return all metrics for a given attribute."""
 
         if attr_info.data_format == AttrDataFormat.SCALAR:
diff --git a/tangostationcontrol/VERSION b/tangostationcontrol/VERSION
index 48b91fd89..8b95abd94 100644
--- a/tangostationcontrol/VERSION
+++ b/tangostationcontrol/VERSION
@@ -1 +1 @@
-0.24.1
+0.24.2
-- 
GitLab