handle attributes on <Data> and <SupplierData>

This commit is contained in:
jan 2023-07-13 14:02:43 -07:00
parent 26ca1cd012
commit 701400d442
3 changed files with 16 additions and 2 deletions

View File

@ -22,8 +22,8 @@ class Device:
bin_pass: dict[int | str, bool] = field(default_factory=dict) # Is this bin passing? 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: list[list[int]] | list[list[str]] = field(default_factory=list) # The actual map
# Map attribs: MapName, MapVersion data_misc: dict[str, str] = field(default_factory=dict) # <Data attribs>
# SupplierData attribs: ProductCode, RecipeName supplier_data: dict[str, str] = field(default_factory=dict) # <SupplierData attribs>
misc: dict[str, str] = field(default_factory=dict) # Any unexpected fields go here misc: dict[str, str] = field(default_factory=dict) # Any unexpected fields go here

View File

@ -114,6 +114,12 @@ def read_devices(el_map: ElementTree.Element) -> list[Device]:
else: else:
data = data_strs data = data_strs
device.map = data 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) devices.append(device)
return devices return devices

View File

@ -113,6 +113,14 @@ def write_devices(devices: Sequence[Device], el_map: ElementTree.Element) -> Non
continue continue
el_device.set(key, value) 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]: def prepare_data(data: list[list[str]] | list[list[int]], decimal: bool) -> tuple[list[str], int]:
is_char = isinstance(data[0][0], str) is_char = isinstance(data[0][0], str)