Skip to content

Commit 625b21e

Browse files
committed
Fix faulty conversion of non-(mm2,AWG) units
The parsing allows arbitrary units to be used for cable dimensions -- this might be valid units, e.g. square inches, or invalid, e.g. bananas. We only allow conversion between mm2 and AWG, so check that the gauge_unit is either of those before conversion. If not, pass through as is.
1 parent 2b307b0 commit 625b21e

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/wireviz/Harness.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,15 @@ def create_graph(self):
114114

115115
for _, cable in self.cables.items():
116116

117+
awg_fmt = ''
117118
if cable.show_equiv:
119+
# Only convert units we actually know about, i.e. currently
120+
# mm2 and awg --- other units _are_ technically allowed,
121+
# and passed through as-is.
118122
if cable.gauge_unit =='mm\u00B2':
119123
awg_fmt = f' ({awg_equiv(cable.gauge)} AWG)'
120-
else:
124+
elif cable.gauge_unit.upper() == 'AWG':
121125
awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)'
122-
else:
123-
awg_fmt = ''
124126

125127
attributes = [f'{len(cable.colors)}x' if cable.show_wirecount else '',
126128
f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else '',

0 commit comments

Comments
 (0)