Skip to content

Commit 4fdadaf

Browse files
authored
Add __str__ methods for the Price and Power classes (#78)
2 parents 5b95dd9 + 880df81 commit 4fdadaf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
* Extra validation check to ensure the quantity is strictly positive.
1414
* Extra validation check to ensure the quantity and price are within the allowed bounds.
15-
* Add more edge cases to the integration tests
15+
* Add more edge cases to the integration tests.
16+
* Add idiomatic string representations for `Power` and `Price` classes.
1617

1718
## Bug Fixes
1819

src/frequenz/client/electricity_trading/_types.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ def to_pb(self) -> price_pb2.Price:
115115
decimal_amount.value = str(self.amount)
116116
return price_pb2.Price(amount=decimal_amount, currency=self.currency.to_pb())
117117

118+
def __str__(self) -> str:
119+
"""Return string representation of the Price object.
120+
121+
Returns:
122+
String representation of the Price object.
123+
"""
124+
return f"{self.amount} {self.currency.name}"
125+
118126

119127
@dataclass(frozen=True)
120128
class Power:
@@ -144,6 +152,14 @@ def to_pb(self) -> power_pb2.Power:
144152
decimal_mw.value = str(self.mw)
145153
return power_pb2.Power(mw=decimal_mw)
146154

155+
def __str__(self) -> str:
156+
"""Return the string representation of the Power object.
157+
158+
Returns:
159+
The string representation of the Power object.
160+
"""
161+
return f"{self.mw} MW"
162+
147163

148164
class EnergyMarketCodeType(enum.Enum):
149165
"""

0 commit comments

Comments
 (0)