Skip to content

Commit a8228b8

Browse files
committed
Use the new microgrid client ComponentId and MicrogridId
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent e686686 commit a8228b8

File tree

64 files changed

+1776
-1088
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1776
-1088
lines changed

benchmarks/power_distribution/power_distributor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from typing import Any
1313

1414
from frequenz.channels import Broadcast
15-
from frequenz.client.microgrid import Component, ComponentCategory
15+
from frequenz.client.microgrid import Component, ComponentCategory, ComponentId
1616
from frequenz.quantities import Power
1717

1818
from frequenz.sdk import microgrid
@@ -37,7 +37,7 @@
3737
# send requests, and those no longer go directly to the power distributing actor, but
3838
# instead through the power managing actor. So the below function needs to be updated
3939
# to use the PowerDistributingActor directly.
40-
async def send_requests(batteries: set[int], request_num: int) -> list[Result]:
40+
async def send_requests(batteries: set[ComponentId], request_num: int) -> list[Result]:
4141
"""Send requests to the PowerDistributingActor and wait for the response.
4242
4343
Args:
@@ -98,7 +98,7 @@ def parse_result(result: list[list[Result]]) -> dict[str, float]:
9898

9999
async def run_test( # pylint: disable=too-many-locals
100100
num_requests: int,
101-
batteries: set[int],
101+
batteries: set[ComponentId],
102102
) -> dict[str, Any]:
103103
"""Run test.
104104

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from datetime import timedelta
1818

1919
from frequenz.channels import Broadcast, Sender
20-
from frequenz.client.microgrid import ComponentCategory, InverterType
20+
from frequenz.client.microgrid import ComponentCategory, ComponentId, InverterType
2121

2222
from .._internal._channels import ChannelRegistry
2323
from ..actor._actor import Actor
@@ -122,12 +122,14 @@ def __init__(
122122
self._producer: Producer | None = None
123123
self._grid: Grid | None = None
124124
self._ev_charger_pool_reference_stores: dict[
125-
frozenset[int], EVChargerPoolReferenceStore
125+
frozenset[ComponentId], EVChargerPoolReferenceStore
126126
] = {}
127127
self._battery_pool_reference_stores: dict[
128-
frozenset[int], BatteryPoolReferenceStore
128+
frozenset[ComponentId], BatteryPoolReferenceStore
129+
] = {}
130+
self._pv_pool_reference_stores: dict[
131+
frozenset[ComponentId], PVPoolReferenceStore
129132
] = {}
130-
self._pv_pool_reference_stores: dict[frozenset[int], PVPoolReferenceStore] = {}
131133
self._frequency_instance: GridFrequency | None = None
132134
self._voltage_instance: VoltageStreamer | None = None
133135

@@ -208,7 +210,7 @@ def new_ev_charger_pool(
208210
self,
209211
*,
210212
priority: int,
211-
component_ids: abc.Set[int] | None = None,
213+
component_ids: abc.Set[ComponentId] | None = None,
212214
name: str | None = None,
213215
set_operating_point: bool = False,
214216
) -> EVChargerPool:
@@ -238,7 +240,7 @@ def new_ev_charger_pool(
238240
self._ev_power_wrapper.start()
239241

240242
# We use frozenset to make a hashable key from the input set.
241-
ref_store_key: frozenset[int] = frozenset()
243+
ref_store_key: frozenset[ComponentId] = frozenset()
242244
if component_ids is not None:
243245
ref_store_key = frozenset(component_ids)
244246

@@ -288,7 +290,7 @@ def new_pv_pool(
288290
self,
289291
*,
290292
priority: int,
291-
component_ids: abc.Set[int] | None = None,
293+
component_ids: abc.Set[ComponentId] | None = None,
292294
name: str | None = None,
293295
set_operating_point: bool = False,
294296
) -> PVPool:
@@ -316,7 +318,7 @@ def new_pv_pool(
316318
self._pv_power_wrapper.start()
317319

318320
# We use frozenset to make a hashable key from the input set.
319-
ref_store_key: frozenset[int] = frozenset()
321+
ref_store_key: frozenset[ComponentId] = frozenset()
320322
if component_ids is not None:
321323
ref_store_key = frozenset(component_ids)
322324

@@ -365,7 +367,7 @@ def new_battery_pool(
365367
self,
366368
*,
367369
priority: int,
368-
component_ids: abc.Set[int] | None = None,
370+
component_ids: abc.Set[ComponentId] | None = None,
369371
name: str | None = None,
370372
set_operating_point: bool = False,
371373
) -> BatteryPool:
@@ -395,7 +397,7 @@ def new_battery_pool(
395397
self._battery_power_wrapper.start()
396398

397399
# We use frozenset to make a hashable key from the input set.
398-
ref_store_key: frozenset[int] = frozenset()
400+
ref_store_key: frozenset[ComponentId] = frozenset()
399401
if component_ids is not None:
400402
ref_store_key = frozenset(component_ids)
401403

@@ -555,7 +557,7 @@ def producer() -> Producer:
555557
def new_ev_charger_pool(
556558
*,
557559
priority: int,
558-
component_ids: abc.Set[int] | None = None,
560+
component_ids: abc.Set[ComponentId] | None = None,
559561
name: str | None = None,
560562
set_operating_point: bool = False,
561563
) -> EVChargerPool:
@@ -600,7 +602,7 @@ def new_ev_charger_pool(
600602
def new_battery_pool(
601603
*,
602604
priority: int,
603-
component_ids: abc.Set[int] | None = None,
605+
component_ids: abc.Set[ComponentId] | None = None,
604606
name: str | None = None,
605607
set_operating_point: bool = False,
606608
) -> BatteryPool:
@@ -645,7 +647,7 @@ def new_battery_pool(
645647
def new_pv_pool(
646648
*,
647649
priority: int,
648-
component_ids: abc.Set[int] | None = None,
650+
component_ids: abc.Set[ComponentId] | None = None,
649651
name: str | None = None,
650652
set_operating_point: bool = False,
651653
) -> PVPool:

src/frequenz/sdk/microgrid/_data_sourcing/_component_metric_request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dataclasses import dataclass
77
from datetime import datetime
88

9-
from frequenz.client.microgrid import ComponentMetricId
9+
from frequenz.client.microgrid import ComponentId, ComponentMetricId
1010

1111
__all__ = ["ComponentMetricRequest", "ComponentMetricId"]
1212

@@ -36,7 +36,7 @@ class ComponentMetricRequest:
3636
namespace: str
3737
"""A client-defined identifier influencing the channel name."""
3838

39-
component_id: int
39+
component_id: ComponentId
4040
"""The ID of the requested component."""
4141

4242
metric_id: ComponentMetricId

src/frequenz/sdk/microgrid/_data_sourcing/microgrid_api_source.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from frequenz.client.microgrid import (
1313
BatteryData,
1414
ComponentCategory,
15+
ComponentId,
1516
ComponentMetricId,
1617
EVChargerData,
1718
InverterData,
@@ -148,20 +149,22 @@ def __init__(
148149
registry: A channel registry. To be replaced by a singleton
149150
instance.
150151
"""
151-
self._comp_categories_cache: dict[int, ComponentCategory] = {}
152+
self._comp_categories_cache: dict[ComponentId, ComponentCategory] = {}
152153

153-
self.comp_data_receivers: dict[int, Receiver[Any]] = {}
154+
self.comp_data_receivers: dict[ComponentId, Receiver[Any]] = {}
154155
"""The dictionary of component IDs to data receivers."""
155156

156-
self.comp_data_tasks: dict[int, asyncio.Task[None]] = {}
157+
self.comp_data_tasks: dict[ComponentId, asyncio.Task[None]] = {}
157158
"""The dictionary of component IDs to asyncio tasks."""
158159

159160
self._registry = registry
160161
self._req_streaming_metrics: dict[
161-
int, dict[ComponentMetricId, list[ComponentMetricRequest]]
162+
ComponentId, dict[ComponentMetricId, list[ComponentMetricRequest]]
162163
] = {}
163164

164-
async def _get_component_category(self, comp_id: int) -> ComponentCategory | None:
165+
async def _get_component_category(
166+
self, comp_id: ComponentId
167+
) -> ComponentCategory | None:
165168
"""Get the component category of the given component.
166169
167170
Args:
@@ -185,7 +188,7 @@ async def _get_component_category(self, comp_id: int) -> ComponentCategory | Non
185188

186189
async def _check_battery_request(
187190
self,
188-
comp_id: int,
191+
comp_id: ComponentId,
189192
requests: dict[ComponentMetricId, list[ComponentMetricRequest]],
190193
) -> None:
191194
"""Check if the requests are valid Battery metrics.
@@ -210,7 +213,7 @@ async def _check_battery_request(
210213

211214
async def _check_ev_charger_request(
212215
self,
213-
comp_id: int,
216+
comp_id: ComponentId,
214217
requests: dict[ComponentMetricId, list[ComponentMetricRequest]],
215218
) -> None:
216219
"""Check if the requests are valid EV Charger metrics.
@@ -235,7 +238,7 @@ async def _check_ev_charger_request(
235238

236239
async def _check_inverter_request(
237240
self,
238-
comp_id: int,
241+
comp_id: ComponentId,
239242
requests: dict[ComponentMetricId, list[ComponentMetricRequest]],
240243
) -> None:
241244
"""Check if the requests are valid Inverter metrics.
@@ -260,7 +263,7 @@ async def _check_inverter_request(
260263

261264
async def _check_meter_request(
262265
self,
263-
comp_id: int,
266+
comp_id: ComponentId,
264267
requests: dict[ComponentMetricId, list[ComponentMetricRequest]],
265268
) -> None:
266269
"""Check if the requests are valid Meter metrics.
@@ -285,7 +288,7 @@ async def _check_meter_request(
285288

286289
async def _check_requested_component_and_metrics(
287290
self,
288-
comp_id: int,
291+
comp_id: ComponentId,
289292
category: ComponentCategory,
290293
requests: dict[ComponentMetricId, list[ComponentMetricRequest]],
291294
) -> None:
@@ -376,7 +379,7 @@ def _get_metric_senders(
376379

377380
async def _handle_data_stream(
378381
self,
379-
comp_id: int,
382+
comp_id: ComponentId,
380383
category: ComponentCategory,
381384
) -> None:
382385
"""Stream component data and send the requested metrics out.
@@ -448,7 +451,7 @@ async def clean_tasks(
448451

449452
async def _update_streams(
450453
self,
451-
comp_id: int,
454+
comp_id: ComponentId,
452455
category: ComponentCategory,
453456
) -> None:
454457
"""Update the requested metric streams for the given component.

0 commit comments

Comments
 (0)