Detect and assign unit within cable length attribute

This commit is contained in:
Daniel Rojas 2020-11-16 17:51:45 +01:00
parent dec64abaf5
commit 694f3a3f96

View File

@ -214,6 +214,20 @@ class Cable:
else: else:
pass # gauge not specified pass # gauge not specified
if isinstance(self.length, str): # length and unit specified
try:
l, u = self.length.split(' ')
l = float(l)
except Exception:
raise Exception('Length must be a number, or number and unit separated by a space')
self.length = l
self.length_unit = u
elif self.length is not None: # length specified, assume m
if self.gauge_unit is None:
self.length_unit = 'm'
else:
pass # length not specified
self.connections = [] self.connections = []
if self.length_unit is None: #Default wire length units to meters if left undeclared if self.length_unit is None: #Default wire length units to meters if left undeclared