From def4bd964a06083f155c49dd6096e50a3ea8be83 Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Tue, 3 Oct 2023 15:29:07 +0200 Subject: [PATCH] stateengine plugin: minor code improvement in StateengineValue --- stateengine/StateEngineValue.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/stateengine/StateEngineValue.py b/stateengine/StateEngineValue.py index c2c273a0d..a3c649ab1 100755 --- a/stateengine/StateEngineValue.py +++ b/stateengine/StateEngineValue.py @@ -112,20 +112,9 @@ def set_from_attr(self, item, attribute_name, default_value=None, reset=True, at # update value type correctly based on attr_type value = "{}:{}".format(attr_type, value) # Convert weird string representation of OrderedDict correctly - if isinstance(value, str) and value.startswith("["): - value = re.split('(, (?![^(]*\)))', value.strip('][')) - value = [s for s in value if s != ', '] - result = [] - for s in value: - m = re.match(r'^OrderedDict\((.+)\)$', s) - if m: - result.append(dict(ast.literal_eval(m.group(1)))) - else: - result.append(ast.literal_eval(s)) - value = result try: - value = ast.literal_eval(value) - except Exception as ex: + value = StateEngineTools.convert_str_to_dict(value) + except Exception: pass if value is not None: self._log_develop("Setting value {0}, attribute name {1}, reset {2}, type {3}", @@ -245,8 +234,8 @@ def set(self, value, name="", reset=True, item=None, copyvalue=True): self.__listorder = [i for i in self.__listorder if i != value] source, field_value, value = None, None, None try: - cond1 = source.lstrip('-').replace('.','',1).isdigit() - cond2 = field_value.lstrip('-').replace('.','',1).isdigit() + cond1 = source.lstrip('-').replace('.', '', 1).isdigit() + cond2 = field_value.lstrip('-').replace('.', '', 1).isdigit() except Exception: cond1 = False cond2 = False