From 29004f7ac5279827bf63aae59529398a90f4a86f Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Tue, 6 May 2025 14:37:56 +0200 Subject: [PATCH] client: add SecopClient.execCommandFromString analogous to setParameterFromString to be used in simple clients where values of structured datatypes are just python literals Change-Id: I4936a3c5c0cac45bd7e875c938ce2700b4f4a979 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/36262 Reviewed-by: Markus Zolliker Tested-by: Jenkins Automated Tests --- frappy/client/__init__.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/frappy/client/__init__.py b/frappy/client/__init__.py index 533bf22c..ae04b9e9 100644 --- a/frappy/client/__init__.py +++ b/frappy/client/__init__.py @@ -753,6 +753,28 @@ class SecopClient(ProxyClient): data = datatype.import_value(data) return data, qualifiers + def execCommandFromString(self, module, command, formatted_argument=''): + """call command from string argument + + return data as CacheItem which allows to get + - result.value # the python value + - result.formatted() # a string (incl. units) + - result.timestamp + """ + self.connect() + datatype = self.modules[module]['commands'][command]['datatype'].argument + if datatype: + argument = datatype.from_string(formatted_argument) + else: + if formatted_argument: + raise WrongTypeError('command has no argument') + argument = None + # pylint: disable=unsubscriptable-object + data, qualifiers = self.request(COMMANDREQUEST, self.identifier[module, command], argument)[2] + datatype = self.modules[module]['commands'][command]['datatype'].result + value = datatype.import_value(data) if datatype else None + return CacheItem(value, qualifiers.get('t'), None, datatype) + def updateValue(self, module, param, value, timestamp, readerror): datatype = self.modules[module]['parameters'][param]['datatype'] if readerror: