Skip to content

Commit 255fd11

Browse files
authored
Upgrade to microgrid client v0.7 (#1182)
Use the new microgrid client `ComponentId` and `MicrogridId`.
2 parents 1130c6a + 6a48d83 commit 255fd11

File tree

69 files changed

+1575
-1222
lines changed

Some content is hidden

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

69 files changed

+1575
-1222
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
LoggingConfig(root_logger=RootLoggerConfig(level="ERROR"))
4040
```
4141

42+
* The SDK now depends on the `frequenz-client-microgrid` v0.7.x series. The main change is now all component and microgrid IDs need to be passed using the wrapper classes `ComponentId`/`MicrogridId` instead of `int`.
43+
4244
## New Features
4345

4446
<!-- Here goes the main new features and examples or instructions on how to use them -->

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

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ plugins:
118118
# See https://mkdocstrings.github.io/python/usage/#import for details
119119
- https://docs.python.org/3/objects.inv
120120
- https://frequenz-floss.github.io/frequenz-channels-python/v1.1/objects.inv
121-
- https://frequenz-floss.github.io/frequenz-client-microgrid-python/v0.5/objects.inv
121+
- https://frequenz-floss.github.io/frequenz-client-microgrid-python/v0.7/objects.inv
122122
- https://frequenz-floss.github.io/frequenz-quantities-python/v1/objects.inv
123123
- https://lovasoa.github.io/marshmallow_dataclass/html/objects.inv
124124
- https://marshmallow.readthedocs.io/en/stable/objects.inv

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ dependencies = [
2929
# Make sure to update the mkdocs.yml file when
3030
# changing the version
3131
# (plugins.mkdocstrings.handlers.python.import)
32-
"frequenz-client-microgrid >= 0.6.0, < 0.7.0",
32+
"frequenz-client-microgrid >= 0.7.0, < 0.8.0",
3333
"frequenz-channels >= 1.6.0, < 2.0.0",
3434
"frequenz-quantities[marshmallow] >= 1.0.0, < 2.0.0",
3535
"networkx >= 2.8, < 4",

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 frequenz.sdk.microgrid._power_managing._base_classes import Algorithm, DefaultPower
2323

@@ -130,12 +130,14 @@ def __init__(
130130
self._producer: Producer | None = None
131131
self._grid: Grid | None = None
132132
self._ev_charger_pool_reference_stores: dict[
133-
frozenset[int], EVChargerPoolReferenceStore
133+
frozenset[ComponentId], EVChargerPoolReferenceStore
134134
] = {}
135135
self._battery_pool_reference_stores: dict[
136-
frozenset[int], BatteryPoolReferenceStore
136+
frozenset[ComponentId], BatteryPoolReferenceStore
137+
] = {}
138+
self._pv_pool_reference_stores: dict[
139+
frozenset[ComponentId], PVPoolReferenceStore
137140
] = {}
138-
self._pv_pool_reference_stores: dict[frozenset[int], PVPoolReferenceStore] = {}
139141
self._frequency_instance: GridFrequency | None = None
140142
self._voltage_instance: VoltageStreamer | None = None
141143

@@ -216,7 +218,7 @@ def new_ev_charger_pool(
216218
self,
217219
*,
218220
priority: int,
219-
component_ids: abc.Set[int] | None = None,
221+
component_ids: abc.Set[ComponentId] | None = None,
220222
name: str | None = None,
221223
) -> EVChargerPool:
222224
"""Return the corresponding EVChargerPool instance for the given ids.
@@ -243,7 +245,7 @@ def new_ev_charger_pool(
243245
self._ev_power_wrapper.start()
244246

245247
# We use frozenset to make a hashable key from the input set.
246-
ref_store_key: frozenset[int] = frozenset()
248+
ref_store_key: frozenset[ComponentId] = frozenset()
247249
if component_ids is not None:
248250
ref_store_key = frozenset(component_ids)
249251

@@ -292,7 +294,7 @@ def new_pv_pool(
292294
self,
293295
*,
294296
priority: int,
295-
component_ids: abc.Set[int] | None = None,
297+
component_ids: abc.Set[ComponentId] | None = None,
296298
name: str | None = None,
297299
) -> PVPool:
298300
"""Return a new `PVPool` instance for the given ids.
@@ -317,7 +319,7 @@ def new_pv_pool(
317319
self._pv_power_wrapper.start()
318320

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

@@ -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
) -> BatteryPool:
371373
"""Return a new `BatteryPool` instance for the given ids.
@@ -392,7 +394,7 @@ def new_battery_pool(
392394
self._battery_power_wrapper.start()
393395

394396
# We use frozenset to make a hashable key from the input set.
395-
ref_store_key: frozenset[int] = frozenset()
397+
ref_store_key: frozenset[ComponentId] = frozenset()
396398
if component_ids is not None:
397399
ref_store_key = frozenset(component_ids)
398400

@@ -551,7 +553,7 @@ def producer() -> Producer:
551553
def new_ev_charger_pool(
552554
*,
553555
priority: int,
554-
component_ids: abc.Set[int] | None = None,
556+
component_ids: abc.Set[ComponentId] | None = None,
555557
name: str | None = None,
556558
) -> EVChargerPool:
557559
"""Return a new `EVChargerPool` instance for the given parameters.
@@ -590,7 +592,7 @@ def new_ev_charger_pool(
590592
def new_battery_pool(
591593
*,
592594
priority: int,
593-
component_ids: abc.Set[int] | None = None,
595+
component_ids: abc.Set[ComponentId] | None = None,
594596
name: str | None = None,
595597
) -> BatteryPool:
596598
"""Return a new `BatteryPool` instance for the given parameters.
@@ -629,7 +631,7 @@ def new_battery_pool(
629631
def new_pv_pool(
630632
*,
631633
priority: int,
632-
component_ids: abc.Set[int] | None = None,
634+
component_ids: abc.Set[ComponentId] | None = None,
633635
name: str | None = None,
634636
) -> PVPool:
635637
"""Return a new `PVPool` instance for the given parameters.

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)