Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
LoggingConfig(root_logger=RootLoggerConfig(level="ERROR"))
```

* 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`.

## New Features

<!-- Here goes the main new features and examples or instructions on how to use them -->
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/power_distribution/power_distributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from typing import Any

from frequenz.channels import Broadcast
from frequenz.client.microgrid import Component, ComponentCategory
from frequenz.client.microgrid import Component, ComponentCategory, ComponentId
from frequenz.quantities import Power

from frequenz.sdk import microgrid
Expand All @@ -37,7 +37,7 @@
# send requests, and those no longer go directly to the power distributing actor, but
# instead through the power managing actor. So the below function needs to be updated
# to use the PowerDistributingActor directly.
async def send_requests(batteries: set[int], request_num: int) -> list[Result]:
async def send_requests(batteries: set[ComponentId], request_num: int) -> list[Result]:
"""Send requests to the PowerDistributingActor and wait for the response.

Args:
Expand Down Expand Up @@ -98,7 +98,7 @@ def parse_result(result: list[list[Result]]) -> dict[str, float]:

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

Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ plugins:
# See https://mkdocstrings.github.io/python/usage/#import for details
- https://docs.python.org/3/objects.inv
- https://frequenz-floss.github.io/frequenz-channels-python/v1.1/objects.inv
- https://frequenz-floss.github.io/frequenz-client-microgrid-python/v0.5/objects.inv
- https://frequenz-floss.github.io/frequenz-client-microgrid-python/v0.7/objects.inv
- https://frequenz-floss.github.io/frequenz-quantities-python/v1/objects.inv
- https://lovasoa.github.io/marshmallow_dataclass/html/objects.inv
- https://marshmallow.readthedocs.io/en/stable/objects.inv
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
# Make sure to update the mkdocs.yml file when
# changing the version
# (plugins.mkdocstrings.handlers.python.import)
"frequenz-client-microgrid >= 0.6.0, < 0.7.0",
"frequenz-client-microgrid >= 0.7.0, < 0.8.0",
"frequenz-channels >= 1.6.0, < 2.0.0",
"frequenz-quantities[marshmallow] >= 1.0.0, < 2.0.0",
"networkx >= 2.8, < 4",
Expand Down
28 changes: 15 additions & 13 deletions src/frequenz/sdk/microgrid/_data_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from datetime import timedelta

from frequenz.channels import Broadcast, Sender
from frequenz.client.microgrid import ComponentCategory, InverterType
from frequenz.client.microgrid import ComponentCategory, ComponentId, InverterType

from frequenz.sdk.microgrid._power_managing._base_classes import Algorithm, DefaultPower

Expand Down Expand Up @@ -130,12 +130,14 @@ def __init__(
self._producer: Producer | None = None
self._grid: Grid | None = None
self._ev_charger_pool_reference_stores: dict[
frozenset[int], EVChargerPoolReferenceStore
frozenset[ComponentId], EVChargerPoolReferenceStore
] = {}
self._battery_pool_reference_stores: dict[
frozenset[int], BatteryPoolReferenceStore
frozenset[ComponentId], BatteryPoolReferenceStore
] = {}
self._pv_pool_reference_stores: dict[
frozenset[ComponentId], PVPoolReferenceStore
] = {}
self._pv_pool_reference_stores: dict[frozenset[int], PVPoolReferenceStore] = {}
self._frequency_instance: GridFrequency | None = None
self._voltage_instance: VoltageStreamer | None = None

Expand Down Expand Up @@ -216,7 +218,7 @@ def new_ev_charger_pool(
self,
*,
priority: int,
component_ids: abc.Set[int] | None = None,
component_ids: abc.Set[ComponentId] | None = None,
name: str | None = None,
) -> EVChargerPool:
"""Return the corresponding EVChargerPool instance for the given ids.
Expand All @@ -243,7 +245,7 @@ def new_ev_charger_pool(
self._ev_power_wrapper.start()

# We use frozenset to make a hashable key from the input set.
ref_store_key: frozenset[int] = frozenset()
ref_store_key: frozenset[ComponentId] = frozenset()
if component_ids is not None:
ref_store_key = frozenset(component_ids)

Expand Down Expand Up @@ -292,7 +294,7 @@ def new_pv_pool(
self,
*,
priority: int,
component_ids: abc.Set[int] | None = None,
component_ids: abc.Set[ComponentId] | None = None,
name: str | None = None,
) -> PVPool:
"""Return a new `PVPool` instance for the given ids.
Expand All @@ -317,7 +319,7 @@ def new_pv_pool(
self._pv_power_wrapper.start()

# We use frozenset to make a hashable key from the input set.
ref_store_key: frozenset[int] = frozenset()
ref_store_key: frozenset[ComponentId] = frozenset()
if component_ids is not None:
ref_store_key = frozenset(component_ids)

Expand Down Expand Up @@ -365,7 +367,7 @@ def new_battery_pool(
self,
*,
priority: int,
component_ids: abc.Set[int] | None = None,
component_ids: abc.Set[ComponentId] | None = None,
name: str | None = None,
) -> BatteryPool:
"""Return a new `BatteryPool` instance for the given ids.
Expand All @@ -392,7 +394,7 @@ def new_battery_pool(
self._battery_power_wrapper.start()

# We use frozenset to make a hashable key from the input set.
ref_store_key: frozenset[int] = frozenset()
ref_store_key: frozenset[ComponentId] = frozenset()
if component_ids is not None:
ref_store_key = frozenset(component_ids)

Expand Down Expand Up @@ -551,7 +553,7 @@ def producer() -> Producer:
def new_ev_charger_pool(
*,
priority: int,
component_ids: abc.Set[int] | None = None,
component_ids: abc.Set[ComponentId] | None = None,
name: str | None = None,
) -> EVChargerPool:
"""Return a new `EVChargerPool` instance for the given parameters.
Expand Down Expand Up @@ -590,7 +592,7 @@ def new_ev_charger_pool(
def new_battery_pool(
*,
priority: int,
component_ids: abc.Set[int] | None = None,
component_ids: abc.Set[ComponentId] | None = None,
name: str | None = None,
) -> BatteryPool:
"""Return a new `BatteryPool` instance for the given parameters.
Expand Down Expand Up @@ -629,7 +631,7 @@ def new_battery_pool(
def new_pv_pool(
*,
priority: int,
component_ids: abc.Set[int] | None = None,
component_ids: abc.Set[ComponentId] | None = None,
name: str | None = None,
) -> PVPool:
"""Return a new `PVPool` instance for the given parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass
from datetime import datetime

from frequenz.client.microgrid import ComponentMetricId
from frequenz.client.microgrid import ComponentId, ComponentMetricId

__all__ = ["ComponentMetricRequest", "ComponentMetricId"]

Expand Down Expand Up @@ -36,7 +36,7 @@ class ComponentMetricRequest:
namespace: str
"""A client-defined identifier influencing the channel name."""

component_id: int
component_id: ComponentId
"""The ID of the requested component."""

metric_id: ComponentMetricId
Expand Down
27 changes: 15 additions & 12 deletions src/frequenz/sdk/microgrid/_data_sourcing/microgrid_api_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from frequenz.client.microgrid import (
BatteryData,
ComponentCategory,
ComponentId,
ComponentMetricId,
EVChargerData,
InverterData,
Expand Down Expand Up @@ -148,20 +149,22 @@ def __init__(
registry: A channel registry. To be replaced by a singleton
instance.
"""
self._comp_categories_cache: dict[int, ComponentCategory] = {}
self._comp_categories_cache: dict[ComponentId, ComponentCategory] = {}

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

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

self._registry = registry
self._req_streaming_metrics: dict[
int, dict[ComponentMetricId, list[ComponentMetricRequest]]
ComponentId, dict[ComponentMetricId, list[ComponentMetricRequest]]
] = {}

async def _get_component_category(self, comp_id: int) -> ComponentCategory | None:
async def _get_component_category(
self, comp_id: ComponentId
) -> ComponentCategory | None:
"""Get the component category of the given component.

Args:
Expand All @@ -185,7 +188,7 @@ async def _get_component_category(self, comp_id: int) -> ComponentCategory | Non

async def _check_battery_request(
self,
comp_id: int,
comp_id: ComponentId,
requests: dict[ComponentMetricId, list[ComponentMetricRequest]],
) -> None:
"""Check if the requests are valid Battery metrics.
Expand All @@ -210,7 +213,7 @@ async def _check_battery_request(

async def _check_ev_charger_request(
self,
comp_id: int,
comp_id: ComponentId,
requests: dict[ComponentMetricId, list[ComponentMetricRequest]],
) -> None:
"""Check if the requests are valid EV Charger metrics.
Expand All @@ -235,7 +238,7 @@ async def _check_ev_charger_request(

async def _check_inverter_request(
self,
comp_id: int,
comp_id: ComponentId,
requests: dict[ComponentMetricId, list[ComponentMetricRequest]],
) -> None:
"""Check if the requests are valid Inverter metrics.
Expand All @@ -260,7 +263,7 @@ async def _check_inverter_request(

async def _check_meter_request(
self,
comp_id: int,
comp_id: ComponentId,
requests: dict[ComponentMetricId, list[ComponentMetricRequest]],
) -> None:
"""Check if the requests are valid Meter metrics.
Expand All @@ -285,7 +288,7 @@ async def _check_meter_request(

async def _check_requested_component_and_metrics(
self,
comp_id: int,
comp_id: ComponentId,
category: ComponentCategory,
requests: dict[ComponentMetricId, list[ComponentMetricRequest]],
) -> None:
Expand Down Expand Up @@ -376,7 +379,7 @@ def _get_metric_senders(

async def _handle_data_stream(
self,
comp_id: int,
comp_id: ComponentId,
category: ComponentCategory,
) -> None:
"""Stream component data and send the requested metrics out.
Expand Down Expand Up @@ -448,7 +451,7 @@ async def clean_tasks(

async def _update_streams(
self,
comp_id: int,
comp_id: ComponentId,
category: ComponentCategory,
) -> None:
"""Update the requested metric streams for the given component.
Expand Down
Loading
Loading