|
5 | 5 |
|
6 | 6 | import asyncio |
7 | 7 | import logging |
8 | | -import math |
9 | 8 | from abc import ABC, abstractmethod |
10 | 9 | from typing import ( |
11 | 10 | Any, |
|
20 | 19 | ) |
21 | 20 |
|
22 | 21 | import grpc |
23 | | -from frequenz.api.microgrid import common_pb2 as common_pb |
24 | 22 | from frequenz.api.common import components_pb2 as components_pb |
| 23 | +from frequenz.api.common import metrics_pb2 as metrics_pb |
25 | 24 | from frequenz.api.microgrid import microgrid_pb2 as microgrid_pb |
26 | 25 | from frequenz.api.microgrid.microgrid_pb2_grpc import MicrogridStub |
27 | 26 | from frequenz.channels import Broadcast, Receiver, Sender |
28 | | -from google.protobuf.empty_pb2 import Empty # pylint: disable=no-name-in-module |
29 | 27 |
|
30 | 28 | from ..._internal._constants import RECEIVER_MAX_SIZE |
31 | 29 | from ..component import ( |
@@ -341,7 +339,7 @@ async def _component_data_task( |
341 | 339 | "Making call to `GetComponentData`, for component_id=%d", component_id |
342 | 340 | ) |
343 | 341 | try: |
344 | | - call = self.api.GetComponentData( |
| 342 | + call = self.api.StreamComponentData( |
345 | 343 | microgrid_pb.ComponentIdParam(id=component_id), |
346 | 344 | ) |
347 | 345 | # grpc.aio is missing types and mypy thinks this is not |
@@ -579,25 +577,12 @@ async def set_power(self, component_id: int, power_w: float) -> None: |
579 | 577 | when the api call exceeded timeout |
580 | 578 | """ |
581 | 579 | try: |
582 | | - if power_w >= 0: |
583 | | - # grpc.aio is missing types and mypy thinks this is not |
584 | | - # async iterable, but it is |
585 | | - await self.api.Charge( |
586 | | - microgrid_pb.PowerLevelParam( |
587 | | - component_id=component_id, power_w=math.floor(power_w) |
588 | | - ), |
589 | | - timeout=DEFAULT_GRPC_CALL_TIMEOUT, # type: ignore[arg-type] |
590 | | - ) # type: ignore[misc] |
591 | | - else: |
592 | | - # grpc.aio is missing types and mypy thinks this is not |
593 | | - # async iterable, but it is |
594 | | - power_w *= -1 |
595 | | - await self.api.Discharge( |
596 | | - microgrid_pb.PowerLevelParam( |
597 | | - component_id=component_id, power_w=math.floor(power_w) |
598 | | - ), |
599 | | - timeout=DEFAULT_GRPC_CALL_TIMEOUT, # type: ignore[arg-type] |
600 | | - ) # type: ignore[misc] |
| 580 | + await self.api.SetPowerActive( |
| 581 | + microgrid_pb.SetPowerActiveParam( |
| 582 | + component_id=component_id, power=power_w |
| 583 | + ), |
| 584 | + timeout=DEFAULT_GRPC_CALL_TIMEOUT, # type: ignore[arg-type] |
| 585 | + ) # type: ignore[misc] |
601 | 586 | except grpc.aio.AioRpcError as err: |
602 | 587 | msg = f"Failed to set power. Microgrid API: {self.target}. Err: {err.details()}" |
603 | 588 | raise grpc.aio.AioRpcError( |
@@ -633,20 +618,13 @@ async def set_bounds( |
633 | 618 | if lower > 0: |
634 | 619 | raise ValueError(f"Lower bound {upper} must be less than or equal to 0.") |
635 | 620 |
|
636 | | - # grpc.aio is missing types and mypy thinks request_iterator is |
637 | | - # a required argument, but it is not |
638 | | - set_bounds_call = self.api.SetBounds( |
639 | | - timeout=DEFAULT_GRPC_CALL_TIMEOUT, |
640 | | - ) # type: ignore[call-arg] |
641 | 621 | try: |
642 | | - # grpc.aio is missing types and mypy thinks set_bounds_call can be Empty |
643 | | - assert not isinstance(set_bounds_call, Empty) |
644 | | - await set_bounds_call.write( |
| 622 | + self.api.AddInclusionBounds( |
645 | 623 | microgrid_pb.SetBoundsParam( |
646 | 624 | component_id=component_id, |
647 | 625 | # pylint: disable=no-member,line-too-long |
648 | 626 | target_metric=microgrid_pb.SetBoundsParam.TargetMetric.TARGET_METRIC_POWER_ACTIVE, |
649 | | - bounds=common_pb.Bounds(lower=lower, upper=upper), |
| 627 | + bounds=metrics_pb.Bounds(lower=lower, upper=upper), |
650 | 628 | ), |
651 | 629 | ) |
652 | 630 | except grpc.aio.AioRpcError as err: |
|
0 commit comments