Skip to content

Commit 10bb82d

Browse files
committed
Stop leaking protobuf types outside of MicogridGrpcClient
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent ac367e7 commit 10bb82d

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

src/frequenz/sdk/actor/power_distributing/power_distributing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import grpc
2727
from frequenz.channels import Peekable, Receiver, Sender
28-
from google.protobuf.empty_pb2 import Empty # pylint: disable=no-name-in-module
2928

3029
from ...actor import ChannelRegistry
3130
from ...actor._decorator import actor
@@ -674,8 +673,7 @@ async def _create_channels(self) -> None:
674673

675674
def _parse_result(
676675
self,
677-
# type comment to quiet pylint and mypy `unused-import` error
678-
tasks, # type: Dict[int, asyncio.Task[Empty]]
676+
tasks: Dict[int, asyncio.Task[None]],
679677
distribution: Dict[int, float],
680678
request_timeout_sec: float,
681679
) -> Tuple[float, Set[int]]:

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ async def ev_charger_data(
169169
"""
170170

171171
@abstractmethod
172-
async def set_power(self, component_id: int, power_w: float) -> Empty:
172+
async def set_power(self, component_id: int, power_w: float) -> None:
173173
"""Send request to the Microgrid to set power for component.
174174
175175
If power > 0, then component will be charged with this power.
@@ -180,9 +180,6 @@ async def set_power(self, component_id: int, power_w: float) -> Empty:
180180
Args:
181181
component_id: id of the component to set power.
182182
power_w: power to set for the component.
183-
184-
Returns:
185-
Empty response.
186183
"""
187184

188185
@abstractmethod
@@ -567,7 +564,7 @@ async def ev_charger_data(
567564
EVChargerData.from_proto,
568565
).new_receiver(maxsize=maxsize)
569566

570-
async def set_power(self, component_id: int, power_w: float) -> Empty:
567+
async def set_power(self, component_id: int, power_w: float) -> None:
571568
"""Send request to the Microgrid to set power for component.
572569
573570
If power > 0, then component will be charged with this power.
@@ -579,9 +576,6 @@ async def set_power(self, component_id: int, power_w: float) -> Empty:
579576
component_id: id of the component to set power.
580577
power_w: power to set for the component.
581578
582-
Returns:
583-
Empty response.
584-
585579
Raises:
586580
AioRpcError: if connection to Microgrid API cannot be established or
587581
when the api call exceeded timeout
@@ -590,7 +584,7 @@ async def set_power(self, component_id: int, power_w: float) -> Empty:
590584
if power_w >= 0:
591585
# grpc.aio is missing types and mypy thinks this is not
592586
# async iterable, but it is
593-
result: Empty = await self.api.Charge(
587+
await self.api.Charge(
594588
microgrid_pb.PowerLevelParam(
595589
component_id=component_id, power_w=math.floor(power_w)
596590
),
@@ -600,7 +594,7 @@ async def set_power(self, component_id: int, power_w: float) -> Empty:
600594
# grpc.aio is missing types and mypy thinks this is not
601595
# async iterable, but it is
602596
power_w *= -1
603-
result = await self.api.Discharge(
597+
await self.api.Discharge(
604598
microgrid_pb.PowerLevelParam(
605599
component_id=component_id, power_w=math.floor(power_w)
606600
),
@@ -615,7 +609,6 @@ async def set_power(self, component_id: int, power_w: float) -> Empty:
615609
details=msg,
616610
debug_error_string=err.debug_error_string(),
617611
)
618-
return result
619612

620613
async def set_bounds(
621614
self,

tests/microgrid/test_timeout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def mock_set_power(
110110
power_values = [-100, 100]
111111
for power_w in power_values:
112112
with pytest.raises(grpc.aio.AioRpcError) as err_ctx:
113-
_ = await client.set_power(component_id=1, power_w=power_w)
113+
await client.set_power(component_id=1, power_w=power_w)
114114
assert err_ctx.value.code() == grpc.StatusCode.DEADLINE_EXCEEDED
115115

116116
assert await server.graceful_shutdown()

0 commit comments

Comments
 (0)