Skip to content

Commit 24674a0

Browse files
authored
Remove unused JUNCTION and LOAD component categories (#467)
These component categories are deprecated, and are no longer used in production, and have been removed from the microgrid API v0.15.1, which we will update to soon. This PR also fixes a protobuf generated type getting leaked outside the MicrogridClient.
2 parents ac367e7 + dee01cb commit 24674a0

File tree

14 files changed

+53
-187
lines changed

14 files changed

+53
-187
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
capacity: float = soc_sample.value.as_watt_hours()
2525
```
2626

27+
- `MicrogridApiClient.set_power` no longer returns a `protobuf.Empty` result, but a `None`. This won't affect you unless you are using the low level APIs of the SDK.
28+
2729
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
2830

2931
## New Features

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/_graph.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,6 @@ def validate(self) -> None:
502502
self._validate_graph_root()
503503
self._validate_grid_endpoint()
504504
self._validate_intermediary_components()
505-
self._validate_junctions()
506505
self._validate_leaf_components()
507506

508507
def is_pv_inverter(self, component: Component) -> bool:
@@ -747,7 +746,6 @@ def _validate_graph_root(self) -> None:
747746
valid_root_types = {
748747
ComponentCategory.NONE,
749748
ComponentCategory.GRID,
750-
ComponentCategory.JUNCTION,
751749
}
752750

753751
valid_roots = list(
@@ -822,24 +820,6 @@ def _validate_intermediary_components(self) -> None:
822820
f"{missing_predecessors}"
823821
)
824822

825-
def _validate_junctions(self) -> None:
826-
"""Check that junctions are configured correctly in the graph.
827-
828-
Raises:
829-
InvalidGraphError: if any junction has no successors (it is allowed
830-
for a single junction to be the root of the component graph, in
831-
which case it will have no predecessors: this is taken care of
832-
by the `_validate_graph_root` check)
833-
"""
834-
junctions = self.components(component_category={ComponentCategory.JUNCTION})
835-
no_successors = list(
836-
filter(lambda c: self._graph.out_degree(c.component_id) == 0, junctions)
837-
)
838-
if len(no_successors) > 0:
839-
raise InvalidGraphError(
840-
f"Junctions missing graph successors: {no_successors}"
841-
)
842-
843823
def _validate_leaf_components(self) -> None:
844824
"""Check that leaf components (e.g. batteries) are configured correctly.
845825

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

Lines changed: 5 additions & 15 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
@@ -247,10 +244,7 @@ async def components(self) -> Iterable[Component]:
247244
)
248245
components_only = filter(
249246
lambda c: c.category
250-
not in (
251-
microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_SENSOR,
252-
microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_LOAD,
253-
),
247+
is not microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_SENSOR,
254248
component_list.components,
255249
)
256250
result: Iterable[Component] = map(
@@ -567,7 +561,7 @@ async def ev_charger_data(
567561
EVChargerData.from_proto,
568562
).new_receiver(maxsize=maxsize)
569563

570-
async def set_power(self, component_id: int, power_w: float) -> Empty:
564+
async def set_power(self, component_id: int, power_w: float) -> None:
571565
"""Send request to the Microgrid to set power for component.
572566
573567
If power > 0, then component will be charged with this power.
@@ -579,9 +573,6 @@ async def set_power(self, component_id: int, power_w: float) -> Empty:
579573
component_id: id of the component to set power.
580574
power_w: power to set for the component.
581575
582-
Returns:
583-
Empty response.
584-
585576
Raises:
586577
AioRpcError: if connection to Microgrid API cannot be established or
587578
when the api call exceeded timeout
@@ -590,7 +581,7 @@ async def set_power(self, component_id: int, power_w: float) -> Empty:
590581
if power_w >= 0:
591582
# grpc.aio is missing types and mypy thinks this is not
592583
# async iterable, but it is
593-
result: Empty = await self.api.Charge(
584+
await self.api.Charge(
594585
microgrid_pb.PowerLevelParam(
595586
component_id=component_id, power_w=math.floor(power_w)
596587
),
@@ -600,7 +591,7 @@ async def set_power(self, component_id: int, power_w: float) -> Empty:
600591
# grpc.aio is missing types and mypy thinks this is not
601592
# async iterable, but it is
602593
power_w *= -1
603-
result = await self.api.Discharge(
594+
await self.api.Discharge(
604595
microgrid_pb.PowerLevelParam(
605596
component_id=component_id, power_w=math.floor(power_w)
606597
),
@@ -615,7 +606,6 @@ async def set_power(self, component_id: int, power_w: float) -> Empty:
615606
details=msg,
616607
debug_error_string=err.debug_error_string(),
617608
)
618-
return result
619609

620610
async def set_bounds(
621611
self,

src/frequenz/sdk/microgrid/component/_component.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,10 @@ class ComponentCategory(Enum):
5858

5959
NONE = microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_UNSPECIFIED
6060
GRID = microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_GRID
61-
JUNCTION = microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_JUNCTION
6261
METER = microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_METER
6362
INVERTER = microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_INVERTER
6463
BATTERY = microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_BATTERY
6564
EV_CHARGER = microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_EV_CHARGER
66-
LOAD = microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_LOAD
6765
CHP = microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_CHP
6866

6967
# types not yet supported by the API but which can be inferred

tests/actor/test_battery_status.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ def component_graph() -> Tuple[Set[Component], Set[Connection]]:
116116
components = {
117117
Component(1, ComponentCategory.GRID),
118118
Component(2, ComponentCategory.METER),
119-
Component(3, ComponentCategory.JUNCTION),
120119
Component(104, ComponentCategory.METER),
121120
Component(105, ComponentCategory.INVERTER),
122121
Component(106, ComponentCategory.BATTERY),
@@ -130,14 +129,13 @@ def component_graph() -> Tuple[Set[Component], Set[Connection]]:
130129

131130
connections = {
132131
Connection(1, 2),
133-
Connection(2, 3),
134-
Connection(3, 104),
132+
Connection(2, 104),
135133
Connection(104, 105),
136134
Connection(105, 106),
137-
Connection(3, 204),
135+
Connection(2, 204),
138136
Connection(204, 205),
139137
Connection(205, 206),
140-
Connection(3, 304),
138+
Connection(2, 304),
141139
Connection(304, 305),
142140
Connection(305, 306),
143141
}

tests/actor/test_data_sourcing.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ async def test_data_sourcing_actor(self) -> None:
3030
servicer.add_component(
3131
1, microgrid_pb2.ComponentCategory.COMPONENT_CATEGORY_GRID
3232
)
33-
servicer.add_component(
34-
3, microgrid_pb2.ComponentCategory.COMPONENT_CATEGORY_JUNCTION
35-
)
3633
servicer.add_component(
3734
4, microgrid_pb2.ComponentCategory.COMPONENT_CATEGORY_METER
3835
)
@@ -46,9 +43,8 @@ async def test_data_sourcing_actor(self) -> None:
4643
9, microgrid_pb2.ComponentCategory.COMPONENT_CATEGORY_BATTERY
4744
)
4845

49-
servicer.add_connection(1, 3)
50-
servicer.add_connection(3, 4)
51-
servicer.add_connection(3, 7)
46+
servicer.add_connection(1, 4)
47+
servicer.add_connection(1, 7)
5248
servicer.add_connection(7, 8)
5349
servicer.add_connection(8, 9)
5450

tests/actor/test_power_distributing.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def component_graph(self) -> tuple[set[Component], set[Connection]]:
5353
components = {
5454
Component(1, ComponentCategory.GRID),
5555
Component(2, ComponentCategory.METER),
56-
Component(3, ComponentCategory.JUNCTION),
5756
Component(104, ComponentCategory.METER),
5857
Component(105, ComponentCategory.INVERTER),
5958
Component(106, ComponentCategory.BATTERY),
@@ -67,14 +66,13 @@ def component_graph(self) -> tuple[set[Component], set[Connection]]:
6766

6867
connections = {
6968
Connection(1, 2),
70-
Connection(2, 3),
71-
Connection(3, 104),
69+
Connection(2, 104),
7270
Connection(104, 105),
7371
Connection(105, 106),
74-
Connection(3, 204),
72+
Connection(2, 204),
7573
Connection(204, 205),
7674
Connection(205, 206),
77-
Connection(3, 304),
75+
Connection(2, 304),
7876
Connection(304, 305),
7977
Connection(305, 306),
8078
}

tests/microgrid/test_client.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,10 @@ async def test_components(self) -> None:
7474
Component(0, ComponentCategory.METER),
7575
}
7676

77-
# sensors/loads are not counted as components by the API client
77+
# sensors are not counted as components by the API client
7878
servicer.add_component(
7979
1, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_SENSOR
8080
)
81-
servicer.add_component(
82-
2, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_LOAD
83-
)
8481
assert set(await microgrid.components()) == {
8582
Component(0, ComponentCategory.METER),
8683
Component(0, ComponentCategory.BATTERY),
@@ -91,7 +88,6 @@ async def test_components(self) -> None:
9188
[
9289
(9, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_METER),
9390
(99, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_INVERTER),
94-
(66, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_LOAD),
9591
(666, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_SENSOR),
9692
(999, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_BATTERY),
9793
]
@@ -104,14 +100,12 @@ async def test_components(self) -> None:
104100

105101
servicer.set_components(
106102
[
107-
(66, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_LOAD),
108103
(99, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_SENSOR),
109104
(
110105
100,
111106
microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_UNSPECIFIED,
112107
),
113108
(101, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_GRID),
114-
(103, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_JUNCTION),
115109
(104, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_METER),
116110
(105, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_INVERTER),
117111
(106, microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_BATTERY),
@@ -122,7 +116,6 @@ async def test_components(self) -> None:
122116
assert set(await microgrid.components()) == {
123117
Component(100, ComponentCategory.NONE),
124118
Component(101, ComponentCategory.GRID),
125-
Component(103, ComponentCategory.JUNCTION),
126119
Component(104, ComponentCategory.METER),
127120
Component(105, ComponentCategory.INVERTER, InverterType.NONE),
128121
Component(106, ComponentCategory.BATTERY),

tests/microgrid/test_component.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ def test_component_category_from_protobuf() -> None:
2828
== cp.ComponentCategory.GRID
2929
)
3030

31-
assert (
32-
cp._component_category_from_protobuf(
33-
microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_JUNCTION
34-
)
35-
== cp.ComponentCategory.JUNCTION
36-
)
37-
3831
assert (
3932
cp._component_category_from_protobuf(
4033
microgrid_pb.ComponentCategory.COMPONENT_CATEGORY_METER
@@ -80,9 +73,6 @@ def test_Component() -> None:
8073
c1 = cp.Component(1, cp.ComponentCategory.GRID)
8174
assert c1.is_valid()
8275

83-
c3 = cp.Component(3, cp.ComponentCategory.JUNCTION)
84-
assert c3.is_valid()
85-
8676
c4 = cp.Component(4, cp.ComponentCategory.METER)
8777
assert c4.is_valid()
8878

0 commit comments

Comments
 (0)