diff --git a/BAC0/core/io/Write.py b/BAC0/core/io/Write.py index 49b79f84..83786d15 100644 --- a/BAC0/core/io/Write.py +++ b/BAC0/core/io/Write.py @@ -295,9 +295,9 @@ def build_wpm_request(self, args, vendor_id=0, addr=None): ) ) + was = [] for each in args: property_values = [] - was = [] if isinstance(each, str): obj_type, obj_inst, prop_id, value, priority, indx = self._parse_wp_args( each @@ -312,21 +312,31 @@ def build_wpm_request(self, args, vendor_id=0, addr=None): obj_type, prop_id, indx, vendor_id, value ) - property_values.append( - PropertyValue( - propertyIdentifier=prop_id, - propertyArrayIndex=indx, - value=value, - priority=priority, + existingObject = next((obj for obj in was if obj.objectIdentifier == (obj_type, obj_inst)), None) + + if existingObject == None: + property_values.append( + PropertyValue( + propertyIdentifier=prop_id, + propertyArrayIndex=indx, + value=value, + priority=priority, + ) ) - ) - was.append( - WriteAccessSpecification( - objectIdentifier=(obj_type, obj_inst), - listOfProperties=property_values, + was.append( + WriteAccessSpecification( + objectIdentifier=(obj_type, obj_inst), + listOfProperties=property_values, + ) ) - ) + else: + existingObject.listOfProperties.append(PropertyValue( + propertyIdentifier=prop_id, + propertyArrayIndex=indx, + value=value, + priority=priority, + )) datatype = get_datatype(obj_type, prop_id, vendor_id=vendor_id)