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
5 changes: 4 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Frequenz Dispatch Client Library Release Notes

## Features

* `Dispatch.end_time` has been added to the `Dispatch` class, which is the time when the dispatch ended as calculated by the server. `dispatch-cli` will also print this time.

## Bug Fixes

* Fix that duration=0 was sent & received as None.
* Fix that `dispatch-cli stream` would try to print an event as dispatch, causing an exception.
1 change: 1 addition & 0 deletions src/frequenz/client/dispatch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def format_line(key: str, value: str, color: str = "cyan") -> str:
lines.append(format_line("Recurrence", "None"))
lines.append(format_line("Create Time", format_datetime(dispatch.create_time)))
lines.append(format_line("Update Time", format_datetime(dispatch.update_time)))
lines.append(format_line("End Time", format_datetime(dispatch.end_time)))

# Combine all lines
dispatch_info: str = "\n".join(lines)
Expand Down
8 changes: 8 additions & 0 deletions src/frequenz/client/dispatch/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ class Dispatch: # pylint: disable=too-many-instance-attributes
update_time: datetime
"""The last update time of the dispatch in UTC. Set when a dispatch is modified."""

end_time: datetime | None = None
"""The end time of the dispatch in UTC.

Calculated and sent by the backend service.
"""

@property
def started(self) -> bool:
"""Check if the dispatch has started.
Expand Down Expand Up @@ -290,6 +296,7 @@ def from_protobuf(cls, pb_object: PBDispatch) -> "Dispatch":
type=pb_object.data.type,
create_time=to_datetime(pb_object.metadata.create_time),
update_time=to_datetime(pb_object.metadata.modification_time),
end_time=to_datetime(pb_object.metadata.end_time),
start_time=to_datetime(pb_object.data.start_time),
duration=(
timedelta(seconds=pb_object.data.duration)
Expand Down Expand Up @@ -317,6 +324,7 @@ def to_protobuf(self) -> PBDispatch:
dispatch_id=self.id,
create_time=to_timestamp(self.create_time),
modification_time=to_timestamp(self.update_time),
end_time=to_timestamp(self.end_time),
),
data=DispatchData(
type=self.type,
Expand Down
13 changes: 12 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import random
from dataclasses import replace
from datetime import timedelta
from functools import partial

import grpc
from pytest import raises
Expand Down Expand Up @@ -38,6 +39,7 @@ def _update_metadata(dispatch: Dispatch, created: Dispatch) -> Dispatch:
id=created.id,
create_time=created.create_time,
update_time=created.update_time,
end_time=created.end_time,
)


Expand Down Expand Up @@ -97,7 +99,16 @@ async def test_list_dispatches(
dispatches = client.list(microgrid_id=1)
async for page in dispatches:
for dispatch in page:
assert dispatch in client.dispatches(microgrid_id=1)
# First find matching id in client.dispatches, then compare
service_side_dispatch = next(
filter(
partial(lambda d, md: d.id == md.id, md=dispatch),
client.dispatches(microgrid_id=1),
),
None,
)

assert dispatch == service_side_dispatch


async def test_list_dispatches_no_duration(
Expand Down
2 changes: 2 additions & 0 deletions tests/test_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_dispatch() -> None:
create_time=datetime(2023, 1, 1, tzinfo=timezone.utc),
update_time=datetime(2023, 1, 1, tzinfo=timezone.utc),
start_time=datetime(2024, 10, 10, tzinfo=timezone.utc),
end_time=datetime(2024, 10, 20, tzinfo=timezone.utc),
duration=timedelta(days=10),
target=[1, 2, 3],
active=True,
Expand All @@ -117,6 +118,7 @@ def test_dispatch() -> None:
create_time=datetime(2024, 3, 10, tzinfo=timezone.utc),
update_time=datetime(2024, 3, 11, tzinfo=timezone.utc),
start_time=datetime(2024, 11, 10, tzinfo=timezone.utc),
end_time=datetime(2024, 11, 20, tzinfo=timezone.utc),
duration=timedelta(seconds=20),
target=[ComponentCategory.BATTERY],
active=False,
Expand Down