1010import grpc
1111import pytest
1212from frequenz .api .microgrid import common_pb2 as common_pb
13+ from frequenz .api .common import components_pb2 as components_pb
1314from frequenz .api .microgrid import microgrid_pb2 as microgrid_pb
1415from google .protobuf .empty_pb2 import Empty # pylint: disable=no-name-in-module
1516
@@ -51,22 +52,22 @@ async def test_components(self) -> None:
5152 assert set (await microgrid .components ()) == set ()
5253
5354 servicer .add_component (
54- 0 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_METER
55+ 0 , components_pb .ComponentCategory .COMPONENT_CATEGORY_METER
5556 )
5657 assert set (await microgrid .components ()) == {
5758 Component (0 , ComponentCategory .METER )
5859 }
5960
6061 servicer .add_component (
61- 0 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY
62+ 0 , components_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY
6263 )
6364 assert set (await microgrid .components ()) == {
6465 Component (0 , ComponentCategory .METER ),
6566 Component (0 , ComponentCategory .BATTERY ),
6667 }
6768
6869 servicer .add_component (
69- 0 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_METER
70+ 0 , components_pb .ComponentCategory .COMPONENT_CATEGORY_METER
7071 )
7172 assert set (await microgrid .components ()) == {
7273 Component (0 , ComponentCategory .METER ),
@@ -76,7 +77,7 @@ async def test_components(self) -> None:
7677
7778 # sensors are not counted as components by the API client
7879 servicer .add_component (
79- 1 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_SENSOR
80+ 1 , components_pb .ComponentCategory .COMPONENT_CATEGORY_SENSOR
8081 )
8182 assert set (await microgrid .components ()) == {
8283 Component (0 , ComponentCategory .METER ),
@@ -86,10 +87,10 @@ async def test_components(self) -> None:
8687
8788 servicer .set_components (
8889 [
89- (9 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_METER ),
90- (99 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_INVERTER ),
91- (666 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_SENSOR ),
92- (999 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY ),
90+ (9 , components_pb .ComponentCategory .COMPONENT_CATEGORY_METER ),
91+ (99 , components_pb .ComponentCategory .COMPONENT_CATEGORY_INVERTER ),
92+ (666 , components_pb .ComponentCategory .COMPONENT_CATEGORY_SENSOR ),
93+ (999 , components_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY ),
9394 ]
9495 )
9596 assert set (await microgrid .components ()) == {
@@ -100,17 +101,20 @@ async def test_components(self) -> None:
100101
101102 servicer .set_components (
102103 [
103- (99 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_SENSOR ),
104+ (99 , components_pb .ComponentCategory .COMPONENT_CATEGORY_SENSOR ),
104105 (
105106 100 ,
106- microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_UNSPECIFIED ,
107+ components_pb .ComponentCategory .COMPONENT_CATEGORY_UNSPECIFIED ,
107108 ),
108- (101 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_GRID ),
109- (104 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_METER ),
110- (105 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_INVERTER ),
111- (106 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY ),
112- (107 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_EV_CHARGER ),
113- (999 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_SENSOR ),
109+ (101 , components_pb .ComponentCategory .COMPONENT_CATEGORY_GRID ),
110+ (104 , components_pb .ComponentCategory .COMPONENT_CATEGORY_METER ),
111+ (105 , components_pb .ComponentCategory .COMPONENT_CATEGORY_INVERTER ),
112+ (106 , components_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY ),
113+ (
114+ 107 ,
115+ components_pb .ComponentCategory .COMPONENT_CATEGORY_EV_CHARGER ,
116+ ),
117+ (999 , components_pb .ComponentCategory .COMPONENT_CATEGORY_SENSOR ),
114118 ]
115119 )
116120 assert set (await microgrid .components ()) == {
@@ -141,11 +145,11 @@ async def test_connections(self) -> None:
141145 servicer .add_connection (7 , 9 )
142146 servicer .add_component (
143147 7 ,
144- component_category = microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY ,
148+ component_category = components_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY ,
145149 )
146150 servicer .add_component (
147151 9 ,
148- component_category = microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_INVERTER ,
152+ component_category = components_pb .ComponentCategory .COMPONENT_CATEGORY_INVERTER ,
149153 )
150154 assert set (await microgrid .connections ()) == {
151155 Connection (0 , 0 ),
@@ -163,7 +167,7 @@ async def test_connections(self) -> None:
163167 for component_id in [999 , 99 , 19 , 909 , 101 , 91 ]:
164168 servicer .add_component (
165169 component_id ,
166- microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY ,
170+ components_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY ,
167171 )
168172
169173 assert set (await microgrid .connections ()) == {
@@ -176,7 +180,7 @@ async def test_connections(self) -> None:
176180 for component_id in [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ]:
177181 servicer .add_component (
178182 component_id ,
179- microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY ,
183+ components_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY ,
180184 )
181185
182186 servicer .set_connections (
@@ -308,7 +312,7 @@ def ListAllComponents(
308312 for component_id in [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]:
309313 servicer .add_component (
310314 component_id ,
311- microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY ,
315+ components_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY ,
312316 )
313317 servicer .set_connections (
314318 [
@@ -359,10 +363,10 @@ async def test_meter_data(self) -> None:
359363 microgrid = self .create_client (57899 )
360364
361365 servicer .add_component (
362- 83 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_METER
366+ 83 , components_pb .ComponentCategory .COMPONENT_CATEGORY_METER
363367 )
364368 servicer .add_component (
365- 38 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY
369+ 38 , components_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY
366370 )
367371
368372 with pytest .raises (ValueError ):
@@ -391,10 +395,10 @@ async def test_battery_data(self) -> None:
391395 microgrid = self .create_client (57899 )
392396
393397 servicer .add_component (
394- 83 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY
398+ 83 , components_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY
395399 )
396400 servicer .add_component (
397- 38 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_INVERTER
401+ 38 , components_pb .ComponentCategory .COMPONENT_CATEGORY_INVERTER
398402 )
399403
400404 with pytest .raises (ValueError ):
@@ -423,10 +427,10 @@ async def test_inverter_data(self) -> None:
423427 microgrid = self .create_client (57899 )
424428
425429 servicer .add_component (
426- 83 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_INVERTER
430+ 83 , components_pb .ComponentCategory .COMPONENT_CATEGORY_INVERTER
427431 )
428432 servicer .add_component (
429- 38 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY
433+ 38 , components_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY
430434 )
431435
432436 with pytest .raises (ValueError ):
@@ -455,10 +459,10 @@ async def test_ev_charger_data(self) -> None:
455459 microgrid = self .create_client (57899 )
456460
457461 servicer .add_component (
458- 83 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_EV_CHARGER
462+ 83 , components_pb .ComponentCategory .COMPONENT_CATEGORY_EV_CHARGER
459463 )
460464 servicer .add_component (
461- 38 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY
465+ 38 , components_pb .ComponentCategory .COMPONENT_CATEGORY_BATTERY
462466 )
463467
464468 with pytest .raises (ValueError ):
@@ -489,7 +493,7 @@ async def test_charge(self) -> None:
489493 microgrid = self .create_client (57899 )
490494
491495 servicer .add_component (
492- 83 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_METER
496+ 83 , components_pb .ComponentCategory .COMPONENT_CATEGORY_METER
493497 )
494498
495499 await microgrid .set_power (component_id = 83 , power_w = 12 )
@@ -512,7 +516,7 @@ async def test_discharge(self) -> None:
512516 microgrid = self .create_client (57899 )
513517
514518 servicer .add_component (
515- 73 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_METER
519+ 73 , components_pb .ComponentCategory .COMPONENT_CATEGORY_METER
516520 )
517521
518522 await microgrid .set_power (component_id = 73 , power_w = - 15 )
@@ -532,7 +536,7 @@ async def test_set_bounds(self) -> None:
532536 microgrid = self .create_client (57899 )
533537
534538 servicer .add_component (
535- 38 , microgrid_pb .ComponentCategory .COMPONENT_CATEGORY_INVERTER
539+ 38 , components_pb .ComponentCategory .COMPONENT_CATEGORY_INVERTER
536540 )
537541
538542 num_calls = 4
0 commit comments