Skip to content

Commit 3302229

Browse files
committed
Don't guess missing power bounds from adjacent components
While the API allows those values to be unset, in practice this won't ever happen. The backend will mark any components with missing power bounds as broken and will not use them, so it makes no sense for us to guess those bounds as the component won't be accepted by the backend anyway. Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent f41b75e commit 3302229

File tree

2 files changed

+10
-37
lines changed

2 files changed

+10
-37
lines changed

src/frequenz/sdk/actor/power_distributing/power_distributing.py

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -573,55 +573,29 @@ def _get_battery_inverter_data(
573573
)
574574
return None
575575

576-
not_replaceable_metrics = [
576+
crucial_metrics_bat = [
577577
battery_data.soc,
578578
battery_data.soc_lower_bound,
579579
battery_data.soc_upper_bound,
580-
# We could replace capacity with 0, but it won't change distribution.
581-
# This battery will be ignored in distribution anyway.
582580
battery_data.capacity,
581+
battery_data.power_inclusion_lower_bound,
582+
battery_data.power_inclusion_upper_bound,
583583
]
584-
if any(map(isnan, not_replaceable_metrics)):
584+
if any(map(isnan, crucial_metrics_bat)):
585585
_logger.debug("Some metrics for battery %d are NaN", battery_id)
586586
return None
587587

588-
replaceable_metrics = [
589-
battery_data.power_inclusion_lower_bound,
590-
battery_data.power_inclusion_upper_bound,
588+
crucial_metrics_inv = [
591589
inverter_data.active_power_inclusion_lower_bound,
592590
inverter_data.active_power_inclusion_upper_bound,
593591
]
594592

595593
# If all values are ok then return them.
596-
if not any(map(isnan, replaceable_metrics)):
597-
inv_bat_pair = InvBatPair(battery_data, inverter_data)
598-
self._cached_metrics[battery_id] = _CacheEntry.from_ttl(inv_bat_pair)
599-
return inv_bat_pair
600-
601-
# Replace NaN with the corresponding value in the adjacent component.
602-
# If both metrics are None, return None to ignore this battery.
603-
replaceable_pairs = [
604-
("power_inclusion_lower_bound", "active_power_inclusion_lower_bound"),
605-
("power_inclusion_upper_bound", "active_power_inclusion_upper_bound"),
606-
]
594+
if any(map(isnan, crucial_metrics_inv)):
595+
_logger.debug("Some metrics for inverter %d are NaN", inverter_id)
596+
return None
607597

608-
battery_new_metrics = {}
609-
inverter_new_metrics = {}
610-
for bat_attr, inv_attr in replaceable_pairs:
611-
bat_bound = getattr(battery_data, bat_attr)
612-
inv_bound = getattr(inverter_data, inv_attr)
613-
if isnan(bat_bound) and isnan(inv_bound):
614-
_logger.debug("Some metrics for battery %d are NaN", battery_id)
615-
return None
616-
if isnan(bat_bound):
617-
battery_new_metrics[bat_attr] = inv_bound
618-
elif isnan(inv_bound):
619-
inverter_new_metrics[inv_attr] = bat_bound
620-
621-
inv_bat_pair = InvBatPair(
622-
replace(battery_data, **battery_new_metrics),
623-
replace(inverter_data, **inverter_new_metrics),
624-
)
598+
inv_bat_pair = InvBatPair(battery_data, inverter_data)
625599
self._cached_metrics[battery_id] = _CacheEntry.from_ttl(inv_bat_pair)
626600
return inv_bat_pair
627601

tests/actor/power_distributing/test_power_distributing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,10 @@ async def test_battery_power_bounds_nan(self, mocker: MockerFixture) -> None:
366366
await mockgrid.start(mocker)
367367
await self.init_component_data(mockgrid)
368368

369-
# Battery 19 should work even if his inverter sends NaN
370369
await mockgrid.mock_client.send(
371370
inverter_msg(
372371
18,
373-
power=PowerBounds(math.nan, 0, 0, math.nan),
372+
power=PowerBounds(-1000, 0, 0, 1000),
374373
)
375374
)
376375

0 commit comments

Comments
 (0)