2121from frequenz .sdk .actor import ResamplerConfig , power_distributing
2222from frequenz .sdk .microgrid ._data_pipeline import _DataPipeline
2323from frequenz .sdk .timeseries import Power
24- from frequenz .sdk .timeseries .pv_pool import PVPool , PVPoolReport
24+ from frequenz .sdk .timeseries .pv_pool import PVPoolReport
2525
2626from ...microgrid .fixtures import _Mocks
2727from ...utils .component_data_streamer import MockComponentDataStreamer
@@ -117,22 +117,6 @@ def _assert_report( # pylint: disable=too-many-arguments
117117 assert report .distribution_result is not None
118118 assert expected_result_pred (report .distribution_result )
119119
120- async def _get_bounds_receiver (self , pv_pool : PVPool ) -> Receiver [PVPoolReport ]:
121- bounds_rx = pv_pool .power_status .new_receiver ()
122-
123- # Consume initial reports as components are initialized
124- expected_lower_bounds = - 100000.0
125- max_reports = 10
126- ctr = 0
127- while ctr < max_reports :
128- ctr += 1
129- report = await bounds_rx .receive ()
130- assert report .bounds is not None
131- if report .bounds .lower == Power .from_watts (expected_lower_bounds ):
132- break
133-
134- return bounds_rx
135-
136120 async def _recv_reports_until (
137121 self ,
138122 bounds_rx : Receiver [PVPoolReport ],
@@ -160,7 +144,11 @@ async def test_setting_power(
160144 await self ._init_pv_inverters (mocks )
161145 await self ._patch_data_pipeline (mocker )
162146 pv_pool = microgrid .pv_pool ()
163- bounds_rx = await self ._get_bounds_receiver (pv_pool )
147+ bounds_rx = pv_pool .power_status .new_receiver ()
148+ await self ._recv_reports_until (
149+ bounds_rx ,
150+ lambda x : x .bounds is not None and x .bounds .lower .as_watts () == - 100000.0 ,
151+ )
164152 self ._assert_report (
165153 await bounds_rx .receive (), power = None , lower = - 100000.0 , upper = 0.0
166154 )
@@ -187,8 +175,11 @@ async def test_setting_power(
187175
188176 set_power .reset_mock ()
189177 await pv_pool .propose_power (Power .from_watts (- 4000.0 ))
190- # ignore one report because it is not always immediately updated.
191- await bounds_rx .receive ()
178+ await self ._recv_reports_until (
179+ bounds_rx ,
180+ lambda x : x .target_power is not None
181+ and x .target_power .as_watts () == - 4000.0 ,
182+ )
192183 self ._assert_report (
193184 await bounds_rx .receive (), power = - 4000.0 , lower = - 100000.0 , upper = 0.0
194185 )
0 commit comments