Skip to content

Commit 91a86f3

Browse files
committed
Update API dependency
* selector was renamed to target * start_immediately was added in the proto rpc create Signed-off-by: Mathias L. Baumann <[email protected]> # Conflicts: # src/frequenz/client/dispatch/_client.py # src/frequenz/client/dispatch/_internal_types.py # src/frequenz/client/dispatch/types.py # tests/test_proto.py
1 parent a6a2b1d commit 91a86f3

File tree

12 files changed

+102
-106
lines changed

12 files changed

+102
-106
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ classifiers = [
3737
requires-python = ">= 3.11, < 4"
3838
dependencies = [
3939
"typing-extensions >= 4.6.1, < 5",
40-
"frequenz-api-dispatch >= 0.15.1, < 0.16",
40+
"frequenz-api-dispatch == 1.0.0-rc1",
4141
"frequenz-client-base >= 0.7.0, < 0.8.0",
4242
"frequenz-client-common >= 0.1.0, < 0.3.0",
4343
"grpcio >= 1.66.1, < 2",
@@ -87,7 +87,7 @@ dev-pylint = [
8787
"pylint == 3.3.1",
8888
# For checking the noxfile, docs/ script, and tests
8989
"frequenz-client-dispatch[cli,dev-mkdocs,dev-noxfile,dev-pytest]",
90-
"frequenz-api-dispatch >= 0.15.1, < 0.16",
90+
"frequenz-api-dispatch == 1.0.0-rc1",
9191
]
9292
dev-pytest = [
9393
"pytest == 8.3.3",

src/frequenz/client/dispatch/__main__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
FuzzyIntRange,
2929
FuzzyTimeDelta,
3030
JsonDictParamType,
31-
SelectorParamType,
31+
TargetComponentParamType,
3232
)
3333
from ._client import Client
3434

@@ -79,7 +79,7 @@ async def cli(ctx: click.Context, url: str, key: str) -> None:
7979
@cli.command("list")
8080
@click.pass_context
8181
@click.argument("microgrid-id", required=True, type=int)
82-
@click.option("--selector", "-s", type=SelectorParamType(), multiple=True)
82+
@click.option("--target", "-t", type=TargetComponentParamType(), multiple=True)
8383
@click.option("--start-from", type=FuzzyDateTime())
8484
@click.option("--start-to", type=FuzzyDateTime())
8585
@click.option("--end-from", type=FuzzyDateTime())
@@ -92,11 +92,12 @@ async def list_(ctx: click.Context, /, **filters: Any) -> None:
9292
9393
Lists all dispatches for MICROGRID_ID that match the given filters.
9494
95-
The selector option can be given multiple times.
95+
The target option can be given multiple times.
9696
"""
97-
if "selector" in filters:
98-
selector = filters.pop("selector")
99-
filters["component_selectors"] = selector
97+
if "target" in filters:
98+
target = filters.pop("target")
99+
# Name of the parameter in client.list()
100+
filters["target_components"] = target
100101

101102
num_dispatches = 0
102103
async for page in ctx.obj["client"].list(**filters):
@@ -241,7 +242,7 @@ def validate_reccurance(ctx: click.Context, param: click.Parameter, value: Any)
241242
required=True,
242243
type=str,
243244
)
244-
@click.argument("selector", required=True, type=SelectorParamType())
245+
@click.argument("target", required=True, type=TargetComponentParamType())
245246
@click.argument("start-time", required=True, type=FuzzyDateTime())
246247
@click.argument("duration", required=False, type=FuzzyTimeDelta())
247248
@click.option("--active", "-a", type=bool, default=True)
@@ -260,7 +261,7 @@ async def create(
260261
Creates a new dispatch for MICROGRID_ID of type TYPE running for DURATION seconds
261262
starting at START_TIME.
262263
263-
SELECTOR is a comma-separated list of either component categories or component IDs.
264+
TARGET is a comma-separated list of either component categories or component IDs.
264265
Possible component categories: "BATTERY, GRID, METER, INVERTER, EV_CHARGER, CHP".
265266
"""
266267
# Remove keys with `None` value
@@ -286,7 +287,7 @@ async def create(
286287
@click.option("--start-time", type=FuzzyDateTime())
287288
@click.option("--duration", type=FuzzyTimeDelta())
288289
@click.option("--no-duration", is_flag=True)
289-
@click.option("--selector", type=SelectorParamType())
290+
@click.option("--target", type=TargetComponentParamType())
290291
@click.option("--active", type=bool)
291292
@click.option(
292293
"--payload", "-p", type=JsonDictParamType(), help="JSON payload for the dispatch"

src/frequenz/client/dispatch/_cli_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ def convert(
130130
self.fail(f"Invalid integer range: {value}", param, ctx)
131131

132132

133-
class SelectorParamType(click.ParamType):
134-
"""Click parameter type for selectors."""
133+
class TargetComponentParamType(click.ParamType):
134+
"""Click parameter type for targets."""
135135

136-
name = "selector"
136+
name = "target"
137137

138138
def convert(
139139
self, value: Any, param: click.Parameter | None, ctx: click.Context | None
@@ -154,7 +154,7 @@ def convert(
154154
values = value.split(",")
155155

156156
if len(values) == 0:
157-
self.fail("Empty selector list", param, ctx)
157+
self.fail("Empty target list", param, ctx)
158158

159159
error: Exception | None = None
160160
# Attempt to parse component ids

src/frequenz/client/dispatch/_client.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
from ._internal_types import DispatchCreateRequest
4343
from .recurrence import RecurrenceRule
4444
from .types import (
45-
ComponentSelector,
4645
Dispatch,
4746
DispatchEvent,
48-
_component_selector_to_protobuf,
47+
TargetComponents,
48+
_target_components_to_protobuf,
4949
)
5050

5151
# pylint: enable=no-name-in-module
@@ -110,7 +110,7 @@ async def list(
110110
self,
111111
microgrid_id: int,
112112
*,
113-
component_selectors: Iterator[ComponentSelector] = iter(()),
113+
target_components: Iterator[TargetComponents] = iter(()),
114114
start_from: datetime | None = None,
115115
start_to: datetime | None = None,
116116
end_from: datetime | None = None,
@@ -136,7 +136,7 @@ async def list(
136136
137137
Args:
138138
microgrid_id: The microgrid_id to list dispatches for.
139-
component_selectors: optional, list of component ids or categories to filter by.
139+
target_components: optional, list of component ids or categories to filter by.
140140
start_from: optional, filter by start_time >= start_from.
141141
start_to: optional, filter by start_time < start_to.
142142
end_from: optional, filter by end_time >= end_from.
@@ -166,9 +166,9 @@ def to_interval(
166166
# Setup parameters
167167
start_time_interval = to_interval(start_from, start_to)
168168
end_time_interval = to_interval(end_from, end_to)
169-
selectors = list(map(_component_selector_to_protobuf, component_selectors))
169+
targets = list(map(_target_components_to_protobuf, target_components))
170170
filters = DispatchFilter(
171-
selectors=selectors,
171+
targets=targets,
172172
start_time_interval=start_time_interval,
173173
end_time_interval=end_time_interval,
174174
is_active=active,
@@ -256,7 +256,7 @@ async def create( # pylint: disable=too-many-positional-arguments
256256
type: str, # pylint: disable=redefined-builtin
257257
start_time: datetime,
258258
duration: timedelta | None,
259-
selector: ComponentSelector,
259+
target: TargetComponents,
260260
*,
261261
active: bool = True,
262262
dry_run: bool = False,
@@ -271,7 +271,7 @@ async def create( # pylint: disable=too-many-positional-arguments
271271
start_time: The start time of the dispatch.
272272
duration: The duration of the dispatch. Can be `None` for infinite
273273
or no-duration dispatches (e.g. switching a component on).
274-
selector: The component selector for the dispatch.
274+
target: The component target for the dispatch.
275275
active: The active status of the dispatch.
276276
dry_run: The dry_run status of the dispatch.
277277
payload: The payload of the dispatch.
@@ -295,7 +295,7 @@ async def create( # pylint: disable=too-many-positional-arguments
295295
type=type,
296296
start_time=start_time,
297297
duration=duration,
298-
selector=selector,
298+
target=target,
299299
active=active,
300300
dry_run=dry_run,
301301
payload=payload or {},
@@ -353,8 +353,8 @@ async def update(
353353
msg.update.ClearField("duration")
354354
else:
355355
msg.update.duration = round(val.total_seconds())
356-
case "selector":
357-
msg.update.selector.CopyFrom(_component_selector_to_protobuf(val))
356+
case "target":
357+
msg.update.target.CopyFrom(_target_components_to_protobuf(val))
358358
case "is_active":
359359
msg.update.is_active = val
360360
case "payload":

src/frequenz/client/dispatch/_internal_types.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
from .recurrence import RecurrenceRule
2222
from .types import (
23-
ComponentSelector,
24-
_component_selector_from_protobuf,
25-
_component_selector_to_protobuf,
23+
TargetComponents,
24+
_target_components_from_protobuf,
25+
_target_components_to_protobuf,
2626
)
2727

2828
# pylint: enable=no-name-in-module
@@ -51,8 +51,8 @@ class DispatchCreateRequest:
5151
like a command to turn on a component.
5252
"""
5353

54-
selector: ComponentSelector
55-
"""The component selector specifying which components the dispatch targets."""
54+
target: TargetComponents
55+
"""The target components of the dispatch."""
5656

5757
active: bool
5858
"""Indicates whether the dispatch is active and eligible for processing."""
@@ -69,7 +69,6 @@ class DispatchCreateRequest:
6969

7070
recurrence: RecurrenceRule | None
7171
"""The recurrence rule for the dispatch.
72-
7372
Defining any repeating patterns or schedules."""
7473

7574
@classmethod
@@ -97,9 +96,7 @@ def from_protobuf(
9796
to_datetime(pb_object.dispatch_data.start_time)
9897
),
9998
duration=duration,
100-
selector=_component_selector_from_protobuf(
101-
pb_object.dispatch_data.selector
102-
),
99+
target=_target_components_from_protobuf(pb_object.dispatch_data.target),
103100
active=pb_object.dispatch_data.is_active,
104101
dry_run=pb_object.dispatch_data.is_dry_run,
105102
payload=MessageToDict(pb_object.dispatch_data.payload),
@@ -123,7 +120,7 @@ def to_protobuf(self) -> PBDispatchCreateRequest:
123120
duration=(
124121
round(self.duration.total_seconds()) if self.duration else None
125122
),
126-
selector=_component_selector_to_protobuf(self.selector),
123+
target=_target_components_to_protobuf(self.target),
127124
is_active=self.active,
128125
is_dry_run=self.dry_run,
129126
payload=payload,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ def _filter_dispatch(
176176
"""Filter a dispatch based on the request."""
177177
if request.HasField("filter"):
178178
_filter = request.filter
179-
for selector in _filter.selectors:
180-
if selector != dispatch.selector:
179+
for target in _filter.targets:
180+
if target != dispatch.target:
181181
return False
182182
if _filter.HasField("start_time_interval"):
183183
if start_from := _filter.start_time_interval.__dict__["from"]:
@@ -272,7 +272,7 @@ async def UpdateMicrogridDispatch(
272272
getattr(request.update, split_path[0]),
273273
)
274274
# Fields that need to be copied
275-
case "start_time" | "selector" | "payload":
275+
case "start_time" | "target" | "payload":
276276
getattr(pb_dispatch.data, split_path[0]).CopyFrom(
277277
getattr(request.update, split_path[0])
278278
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def to_create_params(microgrid_id: int, dispatch: Dispatch) -> dict[str, Any]:
8282
"type": dispatch.type,
8383
"start_time": dispatch.start_time,
8484
"duration": dispatch.duration,
85-
"selector": dispatch.selector,
85+
"target": dispatch.target,
8686
"active": dispatch.active,
8787
"dry_run": dispatch.dry_run,
8888
"payload": dispatch.payload,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def generate_dispatch(self) -> Dispatch:
9292
timedelta(seconds=self._rng.randint(0, 1000000)),
9393
]
9494
),
95-
selector=self._rng.choice( # type: ignore
95+
target=self._rng.choice( # type: ignore
9696
[
9797
[
9898
self._rng.choice(list(ComponentCategory)[1:])

0 commit comments

Comments
 (0)