From 25915fc30ecd6dd1c965e28fb94af9678ee4ab8f Mon Sep 17 00:00:00 2001
From: thijs snijder <snijder@astron.nl>
Date: Fri, 7 May 2021 16:39:53 +0200
Subject: [PATCH] fied write function

---
 devices/clients/SNMP_client.py | 31 ++++++++-----------------------
 1 file changed, 8 insertions(+), 23 deletions(-)

diff --git a/devices/clients/SNMP_client.py b/devices/clients/SNMP_client.py
index 158ce17df..6230386aa 100644
--- a/devices/clients/SNMP_client.py
+++ b/devices/clients/SNMP_client.py
@@ -26,12 +26,6 @@ snmp_types = {
     "OID": numpy.str_,
 }
 
-# numpy_to_snmp_dict = {
-#     numpy.int64,
-#     numpy.int64,
-#     str,
-# }
-
 
 class SNMP_client(CommClient):
     """
@@ -140,34 +134,25 @@ class SNMP_client(CommClient):
         dim_x, dim_y, numpy_type = self.setup_value_conversion(attribute)
         oids = self.get_oids(dim_x, dim_y, oids)
 
-        if dtype is None:
-            dtype = numpy_type
-
         def _read_function():
-
             vars = self.manager.get(self.host, *oids)
+            return [snmp_to_numpy_dict[type(i.value)](str(i.value)) for i in vars]
 
-            value = []
-            for i in vars:
-                val = snmp_to_numpy_dict[type(i.value)](str(i.value))
-                value.append(val)
-            return value
-
-        if dtype is None:
+        if dtype is not None:
             def _write_function(value):
                 if len(oids) == 1 and type(value) != list:
                     value = [value]
-                else:
-                    for i in range(len(oids)):
-                        self.manager.set(self.host, oids[i], value[i])
 
+                for i in range(len(oids)):
+                    self.manager.set(self.host, oids[i], snmp_types[dtype](value[i]))
         else:
             def _write_function(value):
                 if len(oids) == 1 and type(value) != list:
                     value = [value]
-                else:
-                    for i in range(len(oids)):
-                        self.manager.set(self.host, oids[i], snmp_types[dtype](value[i]))
+
+                for i in range(len(oids)):
+                    self.manager.set(self.host, oids[i], value[i])
+
 
         # return the read/write functions
         return _read_function, _write_function
-- 
GitLab