diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index f41c003c..dbc35478 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -12,7 +12,8 @@ * Extra validation check to ensure the quantity is strictly positive. * Extra validation check to ensure the quantity and price are within the allowed bounds. -* Add more edge cases to the integration tests +* Add more edge cases to the integration tests. +* Add idiomatic string representations for `Power` and `Price` classes. ## Bug Fixes diff --git a/src/frequenz/client/electricity_trading/_types.py b/src/frequenz/client/electricity_trading/_types.py index 968a280b..c2056931 100644 --- a/src/frequenz/client/electricity_trading/_types.py +++ b/src/frequenz/client/electricity_trading/_types.py @@ -115,6 +115,14 @@ def to_pb(self) -> price_pb2.Price: decimal_amount.value = str(self.amount) return price_pb2.Price(amount=decimal_amount, currency=self.currency.to_pb()) + def __str__(self) -> str: + """Return string representation of the Price object. + + Returns: + String representation of the Price object. + """ + return f"{self.amount} {self.currency.name}" + @dataclass(frozen=True) class Power: @@ -144,6 +152,14 @@ def to_pb(self) -> power_pb2.Power: decimal_mw.value = str(self.mw) return power_pb2.Power(mw=decimal_mw) + def __str__(self) -> str: + """Return the string representation of the Power object. + + Returns: + The string representation of the Power object. + """ + return f"{self.mw} MW" + class EnergyMarketCodeType(enum.Enum): """