@@ -263,6 +263,12 @@ def _link_enabled(link_obj: Any) -> bool:
263263 # Reuse the same selection as links_for_sum to ensure endpoint-enabled check
264264 links_iter = links_for_sum
265265
266+ # Precompute which nodes have chassis/hardware; optics are ignored when absent
267+ node_has_hw : Dict [str , bool ] = {}
268+ for nd in network .nodes .values ():
269+ nd_comp , _nd_cnt = resolve_node_hardware (nd .attrs , library )
270+ node_has_hw [nd .name ] = nd_comp is not None
271+
266272 for lk in links_iter :
267273 (src_end , dst_end , per_end ) = resolve_link_end_components (
268274 lk .attrs , library
@@ -278,14 +284,20 @@ def _totals_with_max(c, n) -> tuple[float, float, float, float]:
278284 power_max = float (c .total_power_max () * n )
279285 return capex , power , cap , power_max
280286
281- # Compute endpoints
282- src_capex , src_power , src_cap , src_power_max = _totals_with_max (
283- src_comp , src_cnt
284- )
287+ # Compute endpoints; ignore optics if the endpoint node has no hardware
288+ if src_comp is not None and node_has_hw .get (lk .source , False ):
289+ _ , src_power , src_cap , src_power_max = _totals_with_max (
290+ src_comp , src_cnt
291+ )
292+ else :
293+ src_power , src_cap , src_power_max = 0.0 , 0.0 , 0.0
285294
286- dst_capex , dst_power , dst_cap , dst_power_max = _totals_with_max (
287- dst_comp , dst_cnt
288- )
295+ if dst_comp is not None and node_has_hw .get (lk .target , False ):
296+ _ , dst_power , dst_cap , dst_power_max = _totals_with_max (
297+ dst_comp , dst_cnt
298+ )
299+ else :
300+ dst_power , dst_cap , dst_power_max = 0.0 , 0.0 , 0.0
289301
290302 # Aggregate per-link
291303 power_watts = float (src_power + dst_power )
@@ -305,12 +317,14 @@ def _totals_with_max(c, n) -> tuple[float, float, float, float]:
305317 "source" : {
306318 "component" : src_comp .name
307319 if src_comp is not None
320+ and node_has_hw .get (lk .source , False )
308321 else None ,
309322 "count" : float (src_cnt ),
310323 },
311324 "target" : {
312325 "component" : dst_comp .name
313326 if dst_comp is not None
327+ and node_has_hw .get (lk .target , False )
314328 else None ,
315329 "count" : float (dst_cnt ),
316330 },
0 commit comments