Skip to content

Commit 5a38fa4

Browse files
Add str function for DeliveryPeriod object
Signed-off-by: camille-bouvy-frequenz <[email protected]>
1 parent 93435c5 commit 5a38fa4

File tree

1 file changed

+26
-0
lines changed
  • src/frequenz/client/electricity_trading

1 file changed

+26
-0
lines changed

src/frequenz/client/electricity_trading/_types.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,32 @@ def __eq__(
365365

366366
return self.start == other.start and self.duration == other.duration
367367

368+
def __str__(self) -> str:
369+
"""
370+
Return string representation of the DeliveryPeriod object.
371+
372+
Returns:
373+
String representation of the DeliveryPeriod object.
374+
"""
375+
duration_map = {
376+
DeliveryDuration.MINUTES_5: "5min",
377+
DeliveryDuration.MINUTES_15: "15min",
378+
DeliveryDuration.MINUTES_30: "30min",
379+
DeliveryDuration.MINUTES_60: "60min",
380+
}
381+
duration_str = duration_map.get(self.duration, "Unknown duration")
382+
start_str = self.start.strftime("%Y-%m-%d %H:%M:%S %Z")
383+
return f"DeliveryPeriod(start={start_str}, duration={duration_str})"
384+
385+
def __repr__(self) -> str:
386+
"""
387+
Developer-friendly representation of the DeliveryPeriod object.
388+
389+
Returns:
390+
Developer-friendly representation of the DeliveryPeriod object.
391+
"""
392+
return self.__str__()
393+
368394
@classmethod
369395
def from_pb(cls, delivery_period: delivery_duration_pb2.DeliveryPeriod) -> Self:
370396
"""Convert a protobuf DeliveryPeriod to DeliveryPeriod object.

0 commit comments

Comments
 (0)