handle attributes on <Data> and <SupplierData>
This commit is contained in:
		
							parent
							
								
									26ca1cd012
								
							
						
					
					
						commit
						701400d442
					
				@ -22,8 +22,8 @@ class Device:
 | 
			
		||||
 | 
			
		||||
    bin_pass: dict[int | str, bool] = field(default_factory=dict)  # Is this bin passing?
 | 
			
		||||
    map: list[list[int]] | list[list[str]] = field(default_factory=list)   # The actual map
 | 
			
		||||
    # Map attribs: MapName, MapVersion
 | 
			
		||||
    # SupplierData attribs: ProductCode, RecipeName
 | 
			
		||||
    data_misc: dict[str, str] = field(default_factory=dict)    # <Data attribs>
 | 
			
		||||
    supplier_data: dict[str, str] = field(default_factory=dict)    # <SupplierData attribs>
 | 
			
		||||
 | 
			
		||||
    misc: dict[str, str] = field(default_factory=dict)  # Any unexpected fields go here
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -114,6 +114,12 @@ def read_devices(el_map: ElementTree.Element) -> list[Device]:
 | 
			
		||||
                else:
 | 
			
		||||
                    data = data_strs
 | 
			
		||||
                device.map = data
 | 
			
		||||
                for key, value in attrib.items():
 | 
			
		||||
                    device.data_misc[key] = value
 | 
			
		||||
            elif tag == 'SupplierData':
 | 
			
		||||
                for key, value in attrib.items():
 | 
			
		||||
                    device.supplier_data[key] = value
 | 
			
		||||
 | 
			
		||||
        devices.append(device)
 | 
			
		||||
    return devices
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -113,6 +113,14 @@ def write_devices(devices: Sequence[Device], el_map: ElementTree.Element) -> Non
 | 
			
		||||
                continue
 | 
			
		||||
            el_device.set(key, value)
 | 
			
		||||
 | 
			
		||||
        for key, value in device.data_misc.items():
 | 
			
		||||
            el_data.set(key, value)
 | 
			
		||||
 | 
			
		||||
        if device.supplier_data:
 | 
			
		||||
            el_suppdata = ElementTree.SubElement(el_device, 'SupplierData')
 | 
			
		||||
            for key, value in device.data_misc.items():
 | 
			
		||||
                el_suppdata.set(key, value)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def prepare_data(data: list[list[str]] | list[list[int]], decimal: bool) -> tuple[list[str], int]:
 | 
			
		||||
    is_char = isinstance(data[0][0], str)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user