Skip to content

Commit aa79bf6

Browse files
committed
refactor: Adapt to frequenz-api-dispatch v1.0.0-rc3 and API v1alpha8
This commit adapts the client to the latest changes in the `frequenz-api-dispatch` and `frequenz-client-common` libraries. Key changes include: - Updated `frequenz-api-dispatch` dependency to `v1.0.0-rc3`. - Updated `frequenz-client-common` dependency to `v0.3.6`. - Introduced `ElectricalComponentCategory` from the new `v1alpha8` API for more specific component targeting. The old `ComponentCategory` is preserved for backward compatibility. - `InverterType.SOLAR` is now deprecated in favor of `InverterType.PV`. - Time interval filters now use `start_time` and `end_time` instead of `from_time` and `to_time`.
1 parent 58c00f1 commit aa79bf6

File tree

10 files changed

+162
-112
lines changed

10 files changed

+162
-112
lines changed

RELEASE_NOTES.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22

33
## Summary
44

5-
<!-- Here goes a general summary of what this release is about -->
5+
This release updates the `frequenz-api-dispatch` dependency to `v1.0.0-rc3` and adapts the client to the latest API changes. It introduces more specific component categories and new event names while maintaining backward compatibility.
66

77
## Upgrading
88

9-
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
9+
* `InverterType.SOLAR` is now deprecated in favor of `InverterType.PV`. The old name can still be used but will be removed in a future release.
10+
* The following dependencies were updated:
11+
* `frequenz-api-dispatch` to `v1.0.0-rc3`
12+
* `frequenz-client-common` to `v0.3.6`
13+
* `grpcio` to `v1.72.1`
1014

1115
## New Features
1216

17+
* **`ElectricalComponentCategory`**: The client now uses the more specific `frequenz.client.common.microgrid.electrical_components.ElectricalComponentCategory` for targeting components.
18+
* The new property `TargetCategory.category2` will return an `ElectricalComponentCategory`.
19+
* The existing `TargetCategory.category` property is preserved for backward compatibility and returns the corresponding `ComponentCategory`.
1320
* Support secrets for signing and verifying messages.
1421
* Use the new env variable `DISPATCH_API_SIGN_SECRET` to set the secret key.
1522
* Use the new `sign_secret` parameter in the `DispatchClient` constructor to set the secret key.

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ classifiers = [
3737
requires-python = ">= 3.11, < 4"
3838
dependencies = [
3939
"typing-extensions >= 4.13.0, < 5",
40-
"frequenz-api-dispatch == 1.0.0-rc2",
40+
"frequenz-api-dispatch >= 1.0.0-rc3, < 2",
4141
"frequenz-client-base >= 0.11.0, < 0.12.0",
42-
"frequenz-client-common >= 0.3.2, < 0.4.0",
42+
"frequenz-client-common >= 0.3.6, < 0.4.0",
4343
"frequenz-core >= 1.0.2, < 2.0.0",
44-
"grpcio >= 1.70.0, < 2",
44+
"grpcio >= 1.72.1, < 2",
4545
"python-dateutil >= 2.8.2, < 3.0",
4646
]
4747
dynamic = ["version"]
@@ -64,7 +64,7 @@ cli = [
6464
dev-flake8 = [
6565
"flake8 == 7.3.0",
6666
"flake8-docstrings == 1.7.0",
67-
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
67+
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
6868
"pydoclint == 0.6.6",
6969
"pydocstyle == 6.3.0",
7070
]
@@ -75,7 +75,7 @@ dev-mkdocs = [
7575
"mike == 2.1.3",
7676
"mkdocs-gen-files == 0.5.0",
7777
"mkdocs-literate-nav == 0.6.2",
78-
"frequenz-api-dispatch == 1.0.0-rc2",
78+
"frequenz-api-dispatch == 1.0.0-rc3",
7979
"mkdocs-macros-plugin == 1.3.7",
8080
"mkdocs-material == 9.6.16",
8181
"mkdocstrings[python] == 0.30.0",
@@ -95,7 +95,7 @@ dev-pylint = [
9595
"pylint == 3.3.7",
9696
# For checking the noxfile, docs/ script, and tests
9797
"frequenz-client-dispatch[cli,dev-mkdocs,dev-noxfile,dev-pytest]",
98-
"frequenz-api-dispatch == 1.0.0-rc2",
98+
"frequenz-api-dispatch == 1.0.0-rc3",
9999
]
100100
dev-pytest = [
101101
"pytest == 8.4.1",

src/frequenz/client/dispatch/_cli_types.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from tzlocal import get_localzone
1414

1515
from frequenz.client.common.microgrid.components import ComponentCategory
16+
from frequenz.client.common.microgrid.electrical_components import (
17+
ElectricalComponentCategory,
18+
)
1619
from frequenz.client.dispatch.types import (
1720
BatteryType,
1821
EvChargerType,
@@ -177,9 +180,17 @@ def convert(
177180

178181
def enum_from_str(
179182
name: str,
180-
) -> InverterType | BatteryType | EvChargerType | ComponentCategory:
183+
) -> (
184+
InverterType
185+
| BatteryType
186+
| EvChargerType
187+
| ElectricalComponentCategory
188+
| ComponentCategory
189+
):
181190
"""Convert a string to an enum member."""
182191
name = name.strip().upper()
192+
if name in ElectricalComponentCategory.__members__:
193+
return ElectricalComponentCategory[name]
183194
if name in ComponentCategory.__members__:
184195
return ComponentCategory[name]
185196
if name in InverterType.__members__:
@@ -208,7 +219,7 @@ def enum_from_str(
208219
"- METER,INVERTER # A list of component categories\n"
209220
"- NA_ION,SOLAR # A list of component category types (category is derived)\n"
210221
"Valid categories:\n"
211-
f"{', '.join([cat.name for cat in ComponentCategory])}\n"
222+
f"{', '.join([cat.name for cat in ElectricalComponentCategory])}\n"
212223
"Valid types:\n"
213224
f"{types_str}\n",
214225
param,

src/frequenz/client/dispatch/_client.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
from datetime import datetime, timedelta
88
from typing import Any, AsyncIterator, Awaitable, Iterator, Literal, cast
99

10-
# pylint: disable=no-name-in-module
11-
from frequenz.api.common.v1.pagination.pagination_params_pb2 import PaginationParams
10+
# pylint: disable-next=no-name-in-module
11+
from frequenz.api.common.v1alpha8.pagination.pagination_params_pb2 import (
12+
PaginationParams,
13+
)
14+
from frequenz.api.common.v1alpha8.types.interval_pb2 import Interval as PBInterval
1215
from frequenz.api.dispatch.v1 import dispatch_pb2_grpc
1316
from frequenz.api.dispatch.v1.dispatch_pb2 import (
1417
CreateMicrogridDispatchResponse,
@@ -20,11 +23,6 @@
2023
ListMicrogridDispatchesResponse,
2124
StreamMicrogridDispatchesRequest,
2225
StreamMicrogridDispatchesResponse,
23-
)
24-
from frequenz.api.dispatch.v1.dispatch_pb2 import (
25-
TimeIntervalFilter as PBTimeIntervalFilter,
26-
)
27-
from frequenz.api.dispatch.v1.dispatch_pb2 import (
2826
UpdateMicrogridDispatchRequest,
2927
UpdateMicrogridDispatchResponse,
3028
)
@@ -170,11 +168,9 @@ async def list(
170168

171169
def to_interval(
172170
from_: datetime | None, to: datetime | None
173-
) -> PBTimeIntervalFilter | None:
171+
) -> PBInterval | None:
174172
return (
175-
PBTimeIntervalFilter(
176-
from_time=to_timestamp(from_), to_time=to_timestamp(to)
177-
)
173+
PBInterval(start_time=to_timestamp(from_), end_time=to_timestamp(to))
178174
if from_ or to
179175
else None
180176
)

src/frequenz/client/dispatch/test/_service.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import grpc.aio
1515

1616
# pylint: disable=no-name-in-module
17-
from frequenz.api.common.v1.pagination.pagination_info_pb2 import PaginationInfo
17+
from frequenz.api.common.v1alpha8.pagination.pagination_info_pb2 import PaginationInfo
1818
from frequenz.api.dispatch.v1.dispatch_pb2 import (
1919
CreateMicrogridDispatchRequest as PBDispatchCreateRequest,
2020
)
@@ -36,9 +36,10 @@
3636
# pylint: enable=no-name-in-module
3737
from frequenz.client.base.conversion import to_datetime as _to_dt
3838
from frequenz.client.common.microgrid import MicrogridId
39+
from frequenz.client.common.streaming import Event
3940

4041
from .._internal_types import DispatchCreateRequest
41-
from ..types import Dispatch, DispatchEvent, DispatchId, Event
42+
from ..types import Dispatch, DispatchEvent, DispatchId
4243

4344
_logger = logging.getLogger(__name__)
4445

@@ -148,20 +149,20 @@ def _filter_dispatch(
148149
if target != dispatch.target:
149150
return False
150151
if _filter.HasField("start_time_interval"):
151-
if start_from := _filter.start_time_interval.from_time:
152+
if start_from := _filter.start_time_interval.start_time:
152153
if dispatch.start_time < _to_dt(start_from):
153154
return False
154-
if start_to := _filter.start_time_interval.to_time:
155+
if start_to := _filter.start_time_interval.end_time:
155156
if dispatch.start_time >= _to_dt(start_to):
156157
return False
157158
if _filter.HasField("end_time_interval"):
158-
if end_from := _filter.end_time_interval.from_time:
159+
if end_from := _filter.end_time_interval.start_time:
159160
if (
160161
dispatch.duration
161162
and dispatch.start_time + dispatch.duration < _to_dt(end_from)
162163
):
163164
return False
164-
if end_to := _filter.end_time_interval.to_time:
165+
if end_to := _filter.end_time_interval.end_time:
165166
if (
166167
dispatch.duration
167168
and dispatch.start_time + dispatch.duration >= _to_dt(end_to)

src/frequenz/client/dispatch/test/generator.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import random
77
from datetime import datetime, timedelta, timezone
88

9-
from frequenz.client.common.microgrid.components import ComponentCategory
9+
from frequenz.client.common.microgrid.electrical_components import (
10+
ElectricalComponentCategory,
11+
)
1012

1113
from .._internal_types import rounded_start_time
1214
from ..recurrence import EndCriteria, Frequency, RecurrenceRule, Weekday
@@ -82,15 +84,15 @@ def generate_target_category_and_type(self) -> TargetCategory:
8284
Returns:
8385
a random category and type
8486
"""
85-
category = self._rng.choice(list(ComponentCategory)[1:])
87+
category = self._rng.choice(list(ElectricalComponentCategory)[1:])
8688
category_type: BatteryType | InverterType | EvChargerType | None = None
8789

8890
match category:
89-
case ComponentCategory.BATTERY:
91+
case ElectricalComponentCategory.BATTERY:
9092
category_type = self._rng.choice(list(BatteryType)[1:])
91-
case ComponentCategory.INVERTER:
93+
case ElectricalComponentCategory.INVERTER:
9294
category_type = self._rng.choice(list(InverterType)[1:])
93-
case ComponentCategory.EV_CHARGER:
95+
case ElectricalComponentCategory.EV_CHARGER:
9496
category_type = self._rng.choice(list(EvChargerType)[1:])
9597
case _:
9698
category_type = None
@@ -116,7 +118,7 @@ def generate_dispatch(self) -> Dispatch:
116118
*[
117119
# Not yet used
118120
# self.generate_target_category_and_type()
119-
self._rng.choice(list(ComponentCategory)[1:])
121+
self._rng.choice(list(ElectricalComponentCategory)[1:])
120122
for _ in range(self._rng.randint(1, 10))
121123
]
122124
),

0 commit comments

Comments
 (0)