Skip to content

Commit 01559e6

Browse files
committed
Add __str__ methods for the Price and Power classes
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 5b95dd9 commit 01559e6

File tree

1 file changed

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

1 file changed

+16
-0
lines changed

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)