Skip to content

Commit abc4751

Browse files
authored
Set zero power for PV inverters not neccessary to reach target power (#946)
If desired power is already reached without the need to use some inverters, their powers need to be set to zero. If not, their original powers would remain and the target powers would be wrong. In case the requested power is zero, this was also leading to crashes because there were no allocations. This change also fixes that issue. Closes #933
2 parents b9bc2c2 + 94d0e23 commit abc4751

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717
## Bug Fixes
1818

19-
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->
19+
- When the PowerDistributor receives a zero power request for PV inverters, it now correctly sets zero power to the inverters, and no longer crashes.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ async def distribute_power(self, request: Request) -> None:
136136
if remaining_power > Power.zero() or is_close_to_zero(
137137
remaining_power.as_watts()
138138
):
139-
break
139+
allocations[inv_id] = Power.zero()
140+
continue
140141
distribution = remaining_power / float(num_components - idx)
141142
inv_data = self._component_data_caches[inv_id]
142143
if not inv_data.has_value():

tests/timeseries/_pv_pool/test_pv_pool_control_methods.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async def _recv_reports_until(
131131
if check(report):
132132
break
133133

134-
async def test_setting_power(
134+
async def test_setting_power( # pylint: disable=too-many-statements
135135
self,
136136
mocks: _Mocks,
137137
mocker: MockerFixture,
@@ -260,3 +260,24 @@ async def test_setting_power(
260260
mocker.call(inv_ids[2], -30000.0),
261261
mocker.call(inv_ids[3], -30000.0),
262262
]
263+
264+
# Setting 0 power should set all inverters to 0
265+
set_power.reset_mock()
266+
await pv_pool.propose_power(Power.zero())
267+
await self._recv_reports_until(
268+
bounds_rx,
269+
lambda x: x.target_power is not None and x.target_power.as_watts() == 0.0,
270+
)
271+
self._assert_report(
272+
await bounds_rx.receive(), power=0.0, lower=-100000.0, upper=0.0
273+
)
274+
await asyncio.sleep(0.0)
275+
276+
assert set_power.call_count == 4
277+
inv_ids = mocks.microgrid.pv_inverter_ids
278+
assert sorted(set_power.call_args_list, key=lambda x: x.args[0]) == [
279+
mocker.call(inv_ids[0], 0.0),
280+
mocker.call(inv_ids[1], 0.0),
281+
mocker.call(inv_ids[2], 0.0),
282+
mocker.call(inv_ids[3], 0.0),
283+
]

0 commit comments

Comments
 (0)