Skip to content

Commit 10a710a

Browse files
authored
Update to new client (#39)
- **Remove implicit dependencies** - **Update to latest client-dispatch**
2 parents e565c00 + b34f096 commit 10a710a

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

pyproject.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ dependencies = [
4141
# plugins.mkdocstrings.handlers.python.import)
4242
"frequenz-sdk == 1.0.0rc601",
4343
"frequenz-channels >= 1.0.1, < 2.0.0",
44-
"frequenz-api-dispatch >= 0.13.0, < 0.14",
45-
"frequenz-client-dispatch >= 0.4.0, < 0.5.0",
46-
"frequenz-client-base >= 0.3.0, < 0.5.0",
47-
"frequenz-client-common >= 0.1.0, < 0.3.0",
44+
# "frequenz-client-dispatch >= 0.4.0, < 0.5.0",
45+
"frequenz-client-dispatch @ git+https://github.com/frequenz-floss/frequenz-client-dispatch-python.git@6632298",
4846
]
4947
dynamic = ["version"]
5048

src/frequenz/dispatch/_dispatcher.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ async def run():
182182
# Create a new dispatch
183183
new_dispatch = await dispatcher.client.create(
184184
microgrid_id=microgrid_id,
185-
_type="ECHO_FREQUENCY", # replace with your own type
185+
type="ECHO_FREQUENCY", # replace with your own type
186186
start_time=datetime.now(tz=timezone.utc) + timedelta(minutes=10),
187187
duration=timedelta(minutes=5),
188188
selector=ComponentCategory.INVERTER,
@@ -191,11 +191,15 @@ async def run():
191191
192192
# Modify the dispatch
193193
await dispatcher.client.update(
194-
dispatch_id=new_dispatch.id, new_fields={"duration": timedelta(minutes=10)}
194+
microgrid_id=microgrid_id,
195+
dispatch_id=new_dispatch.id,
196+
new_fields={"duration": timedelta(minutes=10)}
195197
)
196198
197199
# Validate the modification
198-
modified_dispatch = await dispatcher.client.get(new_dispatch.id)
200+
modified_dispatch = await dispatcher.client.get(
201+
microgrid_id=microgrid_id, dispatch_id=new_dispatch.id
202+
)
199203
assert modified_dispatch.duration == timedelta(minutes=10)
200204
```
201205
"""

tests/test_frequenz_dispatch.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async def test_new_dispatch_created(
9898
generator: DispatchGenerator,
9999
) -> None:
100100
"""Test that a new dispatch is created."""
101-
sample = generator.generate_dispatch(actor_env.microgrid_id)
101+
sample = generator.generate_dispatch()
102102

103103
await _test_new_dispatch_created(actor_env, sample)
104104

@@ -134,7 +134,7 @@ async def _test_new_dispatch_created(
134134
Returns:
135135
The sample dispatch that was created
136136
"""
137-
await actor_env.client.create(**to_create_params(sample))
137+
await actor_env.client.create(**to_create_params(actor_env.microgrid_id, sample))
138138

139139
dispatch_event = await actor_env.updated_dispatches.receive()
140140

@@ -154,7 +154,7 @@ async def test_existing_dispatch_updated(
154154
fake_time: time_machine.Coordinates,
155155
) -> None:
156156
"""Test that an existing dispatch is updated."""
157-
sample = generator.generate_dispatch(actor_env.microgrid_id)
157+
sample = generator.generate_dispatch()
158158
sample = replace(
159159
sample,
160160
active=False,
@@ -167,6 +167,7 @@ async def test_existing_dispatch_updated(
167167
fake_time.shift(timedelta(seconds=1))
168168

169169
await actor_env.client.update(
170+
microgrid_id=actor_env.microgrid_id,
170171
dispatch_id=sample.id,
171172
new_fields={
172173
"active": True,
@@ -199,11 +200,13 @@ async def test_existing_dispatch_deleted(
199200
fake_time: time_machine.Coordinates,
200201
) -> None:
201202
"""Test that an existing dispatch is deleted."""
202-
sample = generator.generate_dispatch(actor_env.microgrid_id)
203+
sample = generator.generate_dispatch()
203204

204205
sample = await _test_new_dispatch_created(actor_env, sample)
205206

206-
await actor_env.client.delete(sample.id)
207+
await actor_env.client.delete(
208+
microgrid_id=actor_env.microgrid_id, dispatch_id=sample.id
209+
)
207210
fake_time.shift(timedelta(seconds=10))
208211
await asyncio.sleep(10)
209212

@@ -223,9 +226,9 @@ async def test_dispatch_schedule(
223226
fake_time: time_machine.Coordinates,
224227
) -> None:
225228
"""Test that a random dispatch is scheduled correctly."""
226-
sample = generator.generate_dispatch(actor_env.microgrid_id)
227-
await actor_env.client.create(**to_create_params(sample))
228-
dispatch = Dispatch(actor_env.client.dispatches[0])
229+
sample = generator.generate_dispatch()
230+
await actor_env.client.create(**to_create_params(actor_env.microgrid_id, sample))
231+
dispatch = Dispatch(actor_env.client.dispatches(actor_env.microgrid_id)[0])
229232

230233
next_run = dispatch.next_run_after(_now())
231234
assert next_run is not None

0 commit comments

Comments
 (0)