Detect and assign unit within cable length attribute (#198)
Co-authored-by: kvid <kvid@users.noreply.github.com>
This commit is contained in:
parent
dec64abaf5
commit
606ddbf977
@ -200,9 +200,11 @@ class Cable:
|
|||||||
try:
|
try:
|
||||||
g, u = self.gauge.split(' ')
|
g, u = self.gauge.split(' ')
|
||||||
except Exception:
|
except Exception:
|
||||||
raise Exception('Gauge must be a number, or number and unit separated by a space')
|
raise Exception(f'Cable {self.name} gauge={self.gauge} - Gauge must be a number, or number and unit separated by a space')
|
||||||
self.gauge = g
|
self.gauge = g
|
||||||
|
|
||||||
|
if self.gauge_unit is not None:
|
||||||
|
print(f'Warning: Cable {self.name} gauge_unit={self.gauge_unit} is ignored because its gauge contains {u}')
|
||||||
if u.upper() == 'AWG':
|
if u.upper() == 'AWG':
|
||||||
self.gauge_unit = u.upper()
|
self.gauge_unit = u.upper()
|
||||||
else:
|
else:
|
||||||
@ -214,11 +216,23 @@ class Cable:
|
|||||||
else:
|
else:
|
||||||
pass # gauge not specified
|
pass # gauge not specified
|
||||||
|
|
||||||
self.connections = []
|
if isinstance(self.length, str): # length and unit specified
|
||||||
|
try:
|
||||||
if self.length_unit is None: #Default wire length units to meters if left undeclared
|
L, u = self.length.split(' ')
|
||||||
|
L = float(L)
|
||||||
|
except Exception:
|
||||||
|
raise Exception(f'Cable {self.name} length={self.length} - Length must be a number, or number and unit separated by a space')
|
||||||
|
self.length = L
|
||||||
|
if self.length_unit is not None:
|
||||||
|
print(f'Warning: Cable {self.name} length_unit={self.length_unit} is ignored because its length contains {u}')
|
||||||
|
self.length_unit = u
|
||||||
|
elif not any(isinstance(self.length, t) for t in [int, float]):
|
||||||
|
raise Exception(f'Cable {self.name} length has a non-numeric value')
|
||||||
|
elif self.gauge_unit is None:
|
||||||
self.length_unit = 'm'
|
self.length_unit = 'm'
|
||||||
|
|
||||||
|
self.connections = []
|
||||||
|
|
||||||
if self.wirecount: # number of wires explicitly defined
|
if self.wirecount: # number of wires explicitly defined
|
||||||
if self.colors: # use custom color palette (partly or looped if needed)
|
if self.colors: # use custom color palette (partly or looped if needed)
|
||||||
pass
|
pass
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user