Skip to content

Commit 09313a0

Browse files
Fix hint errors in microgrid client
The tool mypy is not able to infer the types of the gRPC calls, so we need to cast them to the correct type in order to avoid the errors. Signed-off-by: Daniel Zullo <[email protected]>
1 parent b2b83a3 commit 09313a0

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

src/frequenz/sdk/microgrid/client/_client.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,14 @@ async def components(self) -> Iterable[Component]:
239239
try:
240240
# grpc.aio is missing types and mypy thinks this is not awaitable,
241241
# but it is
242-
component_list = await self.api.ListComponents(
243-
microgrid_pb.ComponentFilter(),
244-
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
245-
) # type: ignore[misc]
242+
component_list = await cast(
243+
Awaitable[microgrid_pb.ComponentList],
244+
self.api.ListComponents(
245+
microgrid_pb.ComponentFilter(),
246+
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
247+
),
248+
)
249+
246250
except grpc.aio.AioRpcError as err:
247251
msg = f"Failed to list components. Microgrid API: {self.target}. Err: {err.details()}"
248252
raise grpc.aio.AioRpcError(
@@ -280,10 +284,13 @@ async def metadata(self) -> Metadata:
280284
"""
281285
microgrid_metadata: microgrid_pb.MicrogridMetadata | None = None
282286
try:
283-
microgrid_metadata = await self.api.GetMicrogridMetadata(
284-
Empty(),
285-
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
286-
) # type: ignore[misc]
287+
microgrid_metadata = await cast(
288+
Awaitable[microgrid_pb.MicrogridMetadata],
289+
self.api.GetMicrogridMetadata(
290+
Empty(),
291+
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
292+
),
293+
)
287294
except grpc.aio.AioRpcError:
288295
_logger.exception("The microgrid metadata is not available.")
289296

@@ -616,12 +623,15 @@ async def set_power(self, component_id: int, power_w: float) -> None:
616623
when the api call exceeded timeout
617624
"""
618625
try:
619-
await self.api.SetPowerActive(
620-
microgrid_pb.SetPowerActiveParam(
621-
component_id=component_id, power=power_w
626+
await cast(
627+
Awaitable[microgrid_pb.SetPowerActiveParam],
628+
self.api.SetPowerActive(
629+
microgrid_pb.SetPowerActiveParam(
630+
component_id=component_id, power=power_w
631+
),
632+
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
622633
),
623-
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
624-
) # type: ignore[misc]
634+
)
625635
except grpc.aio.AioRpcError as err:
626636
msg = f"Failed to set power. Microgrid API: {self.target}. Err: {err.details()}"
627637
raise grpc.aio.AioRpcError(

0 commit comments

Comments
 (0)