Skip to content

Commit 894fcf2

Browse files
shsmsdaniel-zullo-frequenz
authored andcommitted
Set zero power for PV inverters not neccessary to reach target power
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. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent bea9449 commit 894fcf2

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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
@@ -148,7 +148,8 @@ async def distribute_power(self, request: Request) -> None:
148148
if remaining_power > Power.zero() or is_close_to_zero(
149149
remaining_power.as_watts()
150150
):
151-
break
151+
allocations[inv_id] = Power.zero()
152+
continue
152153
distribution = remaining_power / float(num_components - idx)
153154
inv_data = self._component_data_caches[inv_id]
154155
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)