From 19b5e8796b626c34acba5045361399ea20459c5b Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Wed, 4 Sep 2024 18:34:50 +0200 Subject: [PATCH] Add `channel_defaults` to the `BaseApiClient` example Signed-off-by: Leandro Lucarella --- src/frequenz/client/base/client.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/frequenz/client/base/client.py b/src/frequenz/client/base/client.py index 3e5176a..99f6596 100644 --- a/src/frequenz/client/base/client.py +++ b/src/frequenz/client/base/client.py @@ -70,14 +70,24 @@ class ExampleResponseWrapper: def __init__(self, response: ExampleResponse): self.transformed_value = f"{response.float_value:.2f}" + # Change defaults as needed + DEFAULT_CHANNEL_OPTIONS = ChannelOptions() + class MyApiClient(BaseApiClient[ExampleAsyncStub]): - def __init__(self, server_url: str, *, connect: bool = True): + def __init__( + self, + server_url: str, + *, + connect: bool = True, + channel_defaults: ChannelOptions = DEFAULT_CHANNEL_OPTIONS, + ) -> None: super().__init__( server_url, # We need to type ignore here because the generated normal and # async stubs are not type-compatible with each other. ExampleStub, # type: ignore[arg-type] - connect=connect + connect=connect, + channel_defaults=channel_defaults, ) self._broadcaster = GrpcStreamBroadcaster( "stream",