Skip to content

Commit c440288

Browse files
committed
Expose Bus.LineList/LoadList, minor adjustment for lists of strings
1 parent 3d15e6b commit c440288

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

dss/_cffi_api_util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def clear_buffers(self):
148148
def get_string(self, b):
149149
if b != self.ffi.NULL:
150150
return self.ffi.string(b).decode(self.codec)
151-
return ''
151+
return u''
152152

153153
def get_float64_array(self, func, *args):
154154
ptr = self.ffi.new('double**')
@@ -200,7 +200,7 @@ def get_string_array(self, func, *args):
200200
codec = self.codec
201201
str_ptrs = self.ffi.unpack(actual_ptr, cnt[0])
202202
#res = [(str(self.ffi.string(str_ptr).decode(codec)) if (str_ptr != self.ffi.NULL) else None) for str_ptr in str_ptrs]
203-
res = [(self.ffi.string(str_ptr).decode(codec) if (str_ptr != self.ffi.NULL) else None) for str_ptr in str_ptrs]
203+
res = [(self.ffi.string(str_ptr).decode(codec) if (str_ptr != self.ffi.NULL) else u'') for str_ptr in str_ptrs]
204204

205205
self.lib.DSS_Dispose_PPAnsiChar(ptr, cnt[1])
206206
return res
@@ -219,7 +219,7 @@ def get_string_array2(self, func, *args): # for compatibility with OpenDSSDirect
219219
else:
220220
codec = self.codec
221221
res = [(str(self.ffi.string(actual_ptr[i]).decode(codec)) if (actual_ptr[i] != self.ffi.NULL) else '') for i in range(cnt[0])]
222-
if res == ['']:
222+
if res == [u'']:
223223
# most COM methods return an empty array as an
224224
# array with an empty string
225225
res = []

dss/dss_capi_gr/IBus.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ def y(self):
222222
def y(self, Value):
223223
self.CheckForError(self._lib.Bus_Set_y(Value))
224224

225+
@property
226+
def LoadList(self):
227+
'''List of strings: Full Names of LOAD elements connected to the active bus.'''
228+
return self.CheckForError(self._get_string_array(self._lib.Bus_Get_LoadList))
229+
230+
@property
231+
def LineList(self):
232+
'''List of strings: Full Names of LINE elements connected to the active bus.'''
233+
return self.CheckForError(self._get_string_array(self._lib.Bus_Get_LineList))
234+
225235
def __getitem__(self, index):
226236
if isinstance(index, int):
227237
# bus index is zero based, pass it directly

dss/dss_capi_ir/IBus.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ def y(self):
207207
def y(self, Value):
208208
self.CheckForError(self._lib.Bus_Set_y(Value))
209209

210+
@property
211+
def LoadList(self):
212+
'''List of strings: Full Names of LOAD elements connected to the active bus.'''
213+
return self.CheckForError(self._get_string_array(self._lib.Bus_Get_LoadList))
214+
215+
@property
216+
def LineList(self):
217+
'''List of strings: Full Names of LINE elements connected to the active bus.'''
218+
return self.CheckForError(self._get_string_array(self._lib.Bus_Get_LineList))
219+
210220
def __getitem__(self, index):
211221
if isinstance(index, int):
212222
# bus index is zero based, pass it directly

tests/validate.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ def validate_Buses(self):
277277
self.com.ActiveCircuit.SetActiveBus(name)
278278
if not SAVE_COM_OUTPUT: assert A.Name == B.Name
279279

280+
if self.capi.ActiveCircuit.NumNodes < 1000:
281+
for field in ('LoadList', 'LineList'):
282+
fB = getattr(B, field)
283+
fA = output['ActiveCircuit.ActiveBus[{}].{}'.format(name, field)] if LOAD_COM_OUTPUT else getattr(A, field)
284+
if SAVE_COM_OUTPUT: output['ActiveCircuit.ActiveBus[{}].{}'.format(name, field)] = fA
285+
if not SAVE_COM_OUTPUT: assert list(fA) == list(fB), (fA, fB)
286+
287+
280288
for field in ('Coorddefined', 'Cust_Duration', 'Cust_Interrupts', 'Distance', 'Int_Duration', 'Isc', 'Lambda', 'N_Customers', 'N_interrupts', 'Nodes', 'NumNodes', 'SectionID', 'TotalMiles', 'VLL', 'VMagAngle', 'Voc', 'Voltages', 'YscMatrix', 'Zsc0', 'Zsc1', 'ZscMatrix', 'kVBase', 'puVLL', 'puVmagAngle', 'puVoltages', 'x', 'y', 'SeqVoltages', 'CplxSeqVoltages'):
281289
fB = getattr(B, field)
282290
if COM_VLL_BROKEN and field in ('VLL', 'puVLL') and len(fB) == 1:

0 commit comments

Comments
 (0)