From 1dbb33d24ec195086a3e4329e9f988c85ef314ff Mon Sep 17 00:00:00 2001
From: gifrerenom <lluis.gifre@cttc.es>
Date: Sun, 29 Jan 2023 08:37:27 +0000
Subject: [PATCH] Device component:

- implemented support to compose resulting rules considering previous values
---
 src/device/service/Tools.py | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/device/service/Tools.py b/src/device/service/Tools.py
index b4dc66dde..28b5391a7 100644
--- a/src/device/service/Tools.py
+++ b/src/device/service/Tools.py
@@ -19,6 +19,7 @@ from common.method_wrappers.ServiceExceptions import InvalidArgumentException
 from common.proto.context_pb2 import ConfigActionEnum, Device, DeviceConfig
 from common.proto.device_pb2 import MonitoringSettings
 from common.proto.kpi_sample_types_pb2 import KpiSampleType
+from common.tools.grpc.ConfigRules import update_config_rule_custom
 from common.tools.grpc.Tools import grpc_message_to_json
 from .driver_api._Driver import _Driver, RESOURCE_ENDPOINTS
 from .monitoring.MonitoringLoops import MonitoringLoops
@@ -117,11 +118,8 @@ def _raw_config_rules_to_grpc(
             errors.append(error_template.format(device_uuid, str(resource_key), str(resource_value)))
             continue
 
-        config_rule = device_config.config_rules.add()
-        config_rule.action = config_action
-        config_rule.custom.resource_key = resource_key
-        config_rule.custom.resource_value = \
-            resource_value if isinstance(resource_value, str) else json.dumps(resource_value, sort_keys=True)
+        resource_value = json.loads(resource_value) if isinstance(resource_value, str) else resource_value
+        update_config_rule_custom(device_config.config_rules, resource_key, resource_value, new_action=config_action)
 
     return errors
 
-- 
GitLab