Skip to content

Commit b49eb89

Browse files
Fix type hint errors in microgrid client (#778)
The mypy type hint errors in microgrid client were fixed in an attempt to address #774 which might no longer need to be addressed as the suggestion is just moving the type hint error from `no-name-in-module` where `protobuf.*` is imported to `no-member` where it is used. Anyway I kept these commits in case we want to merge them, otherwise we can just close this PR and #774.
2 parents 87b37b1 + 09313a0 commit b49eb89

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

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

Lines changed: 24 additions & 14 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=DEFAULT_GRPC_CALL_TIMEOUT, # type: ignore[arg-type]
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

@@ -329,7 +336,7 @@ async def connections(
329336
Awaitable[microgrid_pb.ConnectionList],
330337
self.api.ListConnections(
331338
connection_filter,
332-
timeout=DEFAULT_GRPC_CALL_TIMEOUT, # type: ignore[arg-type]
339+
timeout=int(DEFAULT_GRPC_CALL_TIMEOUT),
333340
),
334341
),
335342
)
@@ -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=DEFAULT_GRPC_CALL_TIMEOUT, # type: ignore[arg-type]
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)