Skip to content

Commit 3281f46

Browse files
committed
Allow setting api_power_request_timeout in microgrid.initialize()
This was supposed to be possible from `microgrid.initialize()`, but it was only available from `microgrid._data_pipeline.initialize()` until now. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 091628e commit 3281f46

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/frequenz/sdk/microgrid/__init__.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@
223223
Power actually distributed to the batteries: 1500W
224224
""" # noqa: D205, D400
225225

226+
from datetime import timedelta
227+
226228
from ..actor import ResamplerConfig
227229
from . import _data_pipeline, connection_manager
228230
from ._data_pipeline import (
@@ -238,7 +240,12 @@
238240
)
239241

240242

241-
async def initialize(server_url: str, resampler_config: ResamplerConfig) -> None:
243+
async def initialize(
244+
server_url: str,
245+
resampler_config: ResamplerConfig,
246+
*,
247+
api_power_request_timeout: timedelta = timedelta(seconds=5.0),
248+
) -> None:
242249
"""Initialize the microgrid connection manager and the data pipeline.
243250
244251
Args:
@@ -248,9 +255,16 @@ async def initialize(server_url: str, resampler_config: ResamplerConfig) -> None
248255
`9090`) and ssl should be a boolean (defaulting to false). For example:
249256
`grpc://localhost:1090?ssl=true`.
250257
resampler_config: Configuration for the resampling actor.
258+
api_power_request_timeout: Timeout to use when making power requests to
259+
the microgrid API. When requests to components timeout, they will
260+
be marked as blocked for a short duration, during which time they
261+
will be unavailable from the corresponding component pools.
251262
"""
252263
await connection_manager.initialize(server_url)
253-
await _data_pipeline.initialize(resampler_config)
264+
await _data_pipeline.initialize(
265+
resampler_config,
266+
api_power_request_timeout=api_power_request_timeout,
267+
)
254268

255269

256270
__all__ = [

0 commit comments

Comments
 (0)